Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • aotgonbold/register
  • osdu/platform/system/register
2 results
Show changes
Commits on Source (12)
  • Rucha Deshpande's avatar
    Register Service AWS impl · 252849b1
    Rucha Deshpande authored
    commit d387c6ad 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 28 2020 10:44:39 GMT-0500 (Central Daylight Time) 
    
        Adding copyright/license stmt
    
    
    commit 7e1b58a2 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Sep 25 2020 14:39:50 GMT-0500 (Central Daylight Time) 
    
        acept http
    
    
    commit cf0a2e2b 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Sep 25 2020 11:37:18 GMT-0500 (Central Daylight Time) 
    
        Add actuator for health check
    
    
    commit d78aabad 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Sep 24 2020 15:20:30 GMT-0500 (Central Daylight Time) 
    
        bug fixes
    
    
    commit 42b48d42 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Sep 24 2020 14:59:36 GMT-0500 (Central Daylight Time) 
    
        SubscriptionUnitTests2
    
    
    commit 3f331424 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 23 2020 16:51:02 GMT-0500 (Central Daylight Time) 
    
        SubscriptionUnitTests1
    
    
    commit 279e0cd8 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 23 2020 11:37:17 GMT-0500 (Central Daylight Time) 
    
        DDms unit test2
    
    
    commit 214d7f82 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 22 2020 15:22:18 GMT-0500 (Central Daylight Time) 
    
        Adding unittest2
    
    
    commit 28c35b16 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 22 2020 11:18:55 GMT-0500 (Central Daylight Time) 
    
        Adding unittest1
    
    
    commit 69c98e7f 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 21 2020 16:14:08 GMT-0500 (Central Daylight Time) 
    
        bug fixes
    
    
    commit 6c5e4dda 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 21 2020 14:27:25 GMT-0500 (Central Daylight Time) 
    
        Add subscription API impl
    
    
    commit 15b895d8 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Sep 17 2020 16:33:29 GMT-0500 (Central Daylight Time) 
    
        Subscription impl1
    
    
    commit c2ca7c6d 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 16 2020 13:42:34 GMT-0500 (Central Daylight Time) 
    
        ddms impl1
    
    
    commit ba1cd0f0 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 15 2020 14:01:10 GMT-0500 (Central Daylight Time) 
    
        Action impl2
    
    
    commit 31a67ee0 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 15 2020 11:53:40 GMT-0500 (Central Daylight Time) 
    
        Action impl
    
    
    commit f5054b94 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 14 2020 16:13:16 GMT-0500 (Central Daylight Time) 
    
        aws impl5
    
    
    commit dfed512b 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 14 2020 15:23:18 GMT-0500 (Central Daylight Time) 
    
        aws impl4
    
    
    commit dd7d3f9d 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Sep 14 2020 13:11:22 GMT-0500 (Central Daylight Time) 
    
        Acion Api impl1
    
    
    commit 03b69f06 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Sep 10 2020 13:04:27 GMT-0500 (Central Daylight Time) 
    
        aws impl2
    
    
    commit 87035f6f 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 09 2020 16:09:57 GMT-0500 (Central Daylight Time) 
    
        aws impl1
    
    
    commit 8d81100d 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 09 2020 11:26:18 GMT-0500 (Central Daylight Time) 
    
        Add copyright stmt/license
    
    
    commit 6f77c37b 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 09 2020 11:20:49 GMT-0500 (Central Daylight Time) 
    
        Update CodeBuild json
    
    
    commit 8742b4c8 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 09 2020 10:06:49 GMT-0500 (Central Daylight Time) 
    
        Add provider/aws to reactor
    
    
    commit 0198515f 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Sep 09 2020 10:02:05 GMT-0500 (Central Daylight Time) 
    
        Adding empty AWS impl classes
    
    
    commit ff71961f 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 08 2020 16:57:18 GMT-0500 (Central Daylight Time) 
    
        pom
    
    
    commit f9ab1f78 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 08 2020 16:55:12 GMT-0500 (Central Daylight Time) 
    
        Adding provider pom and src
    
    
    commit 03f3258c 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 08 2020 16:54:31 GMT-0500 (Central Daylight Time) 
    
        adding provider pom and src
    
    
    commit b4854fb8 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Sep 08 2020 16:23:11 GMT-0500 (Central Daylight Time) 
    
        setup build
    252849b1
  • Rucha Deshpande's avatar
    Add Register Integration tests · e718ddf7
    Rucha Deshpande authored
    commit 7277a94e 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 10:20:05 GMT-0500 (Central Daylight Time) 
    
        Addng ENVIRONMENT variable
    
    
    commit 7e854a11 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 09:57:38 GMT-0500 (Central Daylight Time) 
    
        used logger
    
    
    commit 5dea70b1 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 09:31:27 GMT-0500 (Central Daylight Time) 
    
        Bug Fix: flushing httpReponse buffer
    
    
    commit ccb26905 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 08:06:39 GMT-0500 (Central Daylight Time) 
    
        Removing commented code
    
    
    commit 97b7e028 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 07:55:55 GMT-0500 (Central Daylight Time) 
    
        Removed commented code
    
    
    commit 9f8a300b 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 07:44:46 GMT-0500 (Central Daylight Time) 
    
        Remove debug prints
    
    
    commit 8e02aa46 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Sun Oct 11 2020 09:21:00 GMT-0500 (Central Daylight Time) 
    
        add prefix to debug stmt
    
    
    commit 264298d2 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Sun Oct 11 2020 09:18:06 GMT-0500 (Central Daylight Time) 
    
        Adding debug prints
    
    
    commit 0415c8ec 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Sat Oct 10 2020 15:35:15 GMT-0500 (Central Daylight Time) 
    
        Adding some prints
    
    
    commit d855fa6a 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Oct 09 2020 12:09:11 GMT-0500 (Central Daylight Time) 
    
        enable int tests in pipeline
    
    
    commit a029c439 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Oct 09 2020 11:14:23 GMT-0500 (Central Daylight Time) 
    
        Update env var name and remove print statements
    
    
    commit fc72f144 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Oct 09 2020 09:32:08 GMT-0500 (Central Daylight Time) 
    
        Bug Fix: int tests
    
    
    commit 02f774a1 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 08 2020 13:40:52 GMT-0500 (Central Daylight Time) 
    
        Fix for int tests
    
    
    commit 242e6a80 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 08 2020 10:48:35 GMT-0500 (Central Daylight Time) 
    
        Bug fix
    
    
    commit 436ffaee 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 08 2020 09:53:43 GMT-0500 (Central Daylight Time) 
    
        using coore-lib 0.3.10
    
    
    commit 63dcc6f8 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 08 2020 09:36:07 GMT-0500 (Central Daylight Time) 
    
        skipping Mongo health check
    
    
    commit 28d3b094 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 16:51:53 GMT-0500 (Central Daylight Time) 
    
        Using latest os-core-lib-aws artifact
    
    
    commit b942ad1a 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 15:52:42 GMT-0500 (Central Daylight Time) 
    
        Bug fixes for int tests
    
    
    commit c9be3d47 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 13:13:09 GMT-0500 (Central Daylight Time) 
    
        Bug fix
    
    
    commit 4b04690a 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 11:01:52 GMT-0500 (Central Daylight Time) 
    
        Bug fix
    
    
    commit 2d9a2197 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 10:59:07 GMT-0500 (Central Daylight Time) 
    
        Add AWS test listener and add env vars for push path
    
    
    commit eb5b75f0 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 09:54:27 GMT-0500 (Central Daylight Time) 
    
        Bug fix
    
    
    commit 7d9920e1 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 09:44:58 GMT-0500 (Central Daylight Time) 
    
        Bug fix
    
    
    commit ba4dff33 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Wed Oct 07 2020 07:05:19 GMT-0500 (Central Daylight Time) 
    
        Save encrypted secret as ByteBuffer instead of String
    
    
    commit 73a0557f 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Oct 06 2020 14:40:50 GMT-0500 (Central Daylight Time) 
    
        BugFux: test-core - Create subscription id dynamically for int test
    
    
    commit a244b3fb 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Tue Oct 06 2020 11:34:47 GMT-0500 (Central Daylight Time) 
    
        int tests bug fixes
    
    
    commit 3bd87fcf 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 05 2020 17:02:28 GMT-0500 (Central Daylight Time) 
    
        Int tests update
    
    
    commit d6ca3715 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 01 2020 12:36:28 GMT-0500 (Central Daylight Time) 
    
        Add int tests1
    
    
    commit 01a32c8b 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Thu Oct 01 2020 10:39:54 GMT-0500 (Central Daylight Time) 
    
        save epoch as string in DynamoDB
    e718ddf7
  • Rucha Deshpande's avatar
    Reverting httpResponse.flushbuffer() in RegisterFilter · 25c5001f
    Rucha Deshpande authored
    commit b5c7d018 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Mon Oct 12 2020 14:17:34 GMT-0500 (Central Daylight Time) 
    
        Reverting httpResponse.flushbuffer() in RegisterFilter
    25c5001f
  • Rucha Deshpande's avatar
    Add error handling for SSM · 98da4bf8
    Rucha Deshpande authored
    commit 39dae666 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Oct 16 2020 11:45:16 GMT-0500 (Central Daylight Time) 
    
        Add error handling for SSM
    
    
    commit a31c7b07 
    Author: Rucha Deshpande <deshruch@amazon.com> 
    Date: Fri Oct 16 2020 11:07:16 GMT-0500 (Central Daylight Time) 
    
        Add error handling for SSM
    98da4bf8
  • Rucha Deshpande's avatar
    Update SSM param name · 0406abff
    Rucha Deshpande authored
    0406abff
  • Rucha Deshpande's avatar
  • Rucha Deshpande's avatar
    Generate SubscriptionId for int test · ca9c3c77
    Rucha Deshpande authored
    ca9c3c77
  • Rucha Deshpande's avatar
    Update .gitlab-ci.yml · ccddf1c2
    Rucha Deshpande authored
    ccddf1c2
  • Rucha Deshpande's avatar
    Update .gitlab-ci.yml · 2ac431c6
    Rucha Deshpande authored
    2ac431c6
  • Rucha Deshpande's avatar
    Update RegisterFilter.java · 00a857e2
    Rucha Deshpande authored
    00a857e2
  • Rucha Deshpande's avatar
  • Rucha Deshpande's avatar
    Merge branch 'feat/aws-impl3' into 'master' · b66f0139
    Rucha Deshpande authored
    Feat/aws impl3
    
    See merge request !27
    b66f0139
Showing
with 1886 additions and 11 deletions
variables:
AWS_BUILD_SUBDIR: provider/register-aws/build-aws
AWS_TEST_SUBDIR: testing/register-test-aws
AWS_SERVICE: register
AWS_ENVIRONMENT: dev
include:
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'standard-setup.yml'
- project: "osdu/platform/ci-cd-pipelines"
file: "standard-setup.yml"
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'build/maven.yml'
- project: "osdu/platform/ci-cd-pipelines"
file: "build/maven.yml"
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'scanners/fossa.yml'
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/fossa.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/gcp.yml"
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'scanners/gitlab-ultimate.yml'
file: 'cloud-providers/aws.yml'
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/gitlab-ultimate.yml"
# disable the eslint scanner
# I think this is being generated from the presence of an HTML file, but there
# is no javascript to scan, so the job isn't helpful and just gets in the way
eslint-sast:
rules:
- when: never
......@@ -92,6 +92,7 @@
<module>provider/register-gcp</module>
<module>provider/register-ibm</module>
<module>provider/register-azure</module>
<module>provider/register-aws</module>
</modules>
<distributionManagement>
......
# Copyright © 2020 Amazon Web Services
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html
FROM amazoncorretto:8
ARG JAR_FILE=provider/register-aws/target/*spring-boot.jar
# Harcoding this value since Register-core requires this variable. AWS does not use it. Might change in future
ENV ENVIRONMENT=DEV
WORKDIR /
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT java $JAVA_OPTS -jar /app.jar
# Copyright © 2020 Amazon Web Services
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import boto3
import json
import os
import argparse
# Create the build-info.json
parser = argparse.ArgumentParser(description="")
# env - CODEBUILD_SOURCE_VERSION
parser.add_argument("--branch", type=str, help="")
# env - CODEBUILD_RESOLVED_SOURCE_VERSION
parser.add_argument("--commit", type=str, help="")
# env - CODEBUILD_BUILD_ID
parser.add_argument("--buildid", type=str, help="")
# env - CODEBUILD_BUILD_NUMBER
parser.add_argument("--buildnumber", type=str, help="")
# Get from directory name
parser.add_argument("--reponame", type=str, help="")
# env OUTPUT_DIR
parser.add_argument("--outdir", type=str, help="")
# full ecr image and tag, and any other artifacts
parser.add_argument("--artifact", type=str, action="append", help="")
args = parser.parse_args()
branch = args.branch
commitId = args.commit
buildId = args.buildid
buildNumber = args.buildnumber
repoName = args.reponame
outputDir = args.outdir
artifacts = args.artifact
buildInfoFilePath = os.path.join(".", outputDir, "build-info.json")
print(buildInfoFilePath)
commitArgs = {
"repositoryName": repoName,
"commitId": commitId
}
commitDetail = {
"commit": ""
}
# get the commit detail
try:
codecommit = boto3.client("codecommit")
commitDetail = codecommit.get_commit(**commitArgs)
except Exception as e:
print("Getting commit information from codecommit failed")
buildInfo = {
"branch": branch,
"build-id": buildId,
"build-number": buildNumber,
"repo": repoName,
"artifacts": artifacts,
"commit": commitDetail["commit"]
}
print(json.dumps(buildInfo, sort_keys=True, indent=4))
# write the build.json file to dist
f = open(buildInfoFilePath, "w")
f.write(json.dumps(buildInfo, sort_keys=True, indent=4))
f.close()
# Copyright © 2020 Amazon Web Services
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
version: 0.2
phases:
install:
runtime-versions:
java: corretto8
commands:
- if [ $(echo $CODEBUILD_SOURCE_VERSION | grep -c ^refs/heads.*) -eq 1 ]; then echo "Branch name found"; else echo "This build only supports branch builds" && exit 1; fi
- apt-get update -y
- apt-get install -y maven
- java -version
- mvn -version
- mkdir -p /root/.m2
- cp ./provider/register-aws/maven/settings.xml /root/.m2/settings.xml # copy the AWS-specific settings.xml to the CodeBuild instance's .m2 folder
- export AWS_ACCOUNT_ID=`aws sts get-caller-identity | grep Account | cut -d':' -f 2 | cut -d'"' -f 2`
- export AWS_OSDU_DEV_MAVEN_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain $AWS_OSDU_DEV_MAVEN_DOMAIN --domain-owner $AWS_ACCOUNT_ID --query authorizationToken --output text`
pre_build:
commands:
- echo "Logging in to Amazon ECR..."
- $(aws ecr get-login --no-include-email --region $AWS_REGION) # authenticate with ECR via the AWS CLI
build:
commands:
- export REPO_NAME=${PWD##*/}
- export OUTPUT_DIR="dist"
- export BRANCH_NAME=`echo ${CODEBUILD_SOURCE_VERSION} | awk '{gsub("refs/heads/","");gsub("\\.","-");gsub("[[:space:]]","-")}1' | sed 's/\//-/g' | awk '{print tolower($0)}'`
- export ECR_TAG=`echo build.${BRANCH_NAME}.${CODEBUILD_BUILD_NUMBER}.${CODEBUILD_RESOLVED_SOURCE_VERSION} | cut -c 1-120`
- export ECR_IMAGE=${ECR_REGISTRY}:${ECR_TAG}
- export ECR_IMAGE_BRANCH_LATEST=${ECR_REGISTRY}:${BRANCH_NAME}
- export INTEGRATION_TEST_OUTPUT=${OUTPUT_DIR}/testing/integration
- export INTEGRATION_TEST_OUTPUT_BIN=${INTEGRATION_TEST_OUTPUT}/bin
- mkdir -p ${OUTPUT_DIR}/bin
- mkdir -p ${OUTPUT_DIR}/testing && mkdir -p ${INTEGRATION_TEST_OUTPUT} && mkdir -p ${INTEGRATION_TEST_OUTPUT}/bin
- echo "Placeholder" >> ${OUTPUT_DIR}/build-info.json # touched so that the output directory has some content incase the build fails so that testing reports are uploaded
- printenv
- echo "Building primary service assemblies..."
- mvn -B test install -pl register-core,provider/register-aws -Ddeployment.environment=prod
- echo "Building integration testing assemblies and gathering artifacts..."
- ./testing/register-test-aws/build-aws/prepare-dist.sh
- echo "Building docker image..."
- docker build -f provider/register-aws/build-aws/Dockerfile -t ${ECR_IMAGE} .
- docker tag ${ECR_IMAGE} ${ECR_IMAGE_BRANCH_LATEST}
- echo "Pushing docker image..."
- docker push ${ECR_IMAGE}
- docker push ${ECR_IMAGE_BRANCH_LATEST}
- echo "Generate build-info.json"
- |
python provider/register-aws/build-aws/build-info.py --branch ${CODEBUILD_SOURCE_VERSION} --commit ${CODEBUILD_RESOLVED_SOURCE_VERSION} \
--buildid ${CODEBUILD_BUILD_ID} --buildnumber ${CODEBUILD_BUILD_NUMBER} --reponame ${REPO_NAME} --outdir ${OUTPUT_DIR} \
--artifact ${ECR_IMAGE}
reports:
SurefireReports: # CodeBuild will create a report group called "SurefireReports".
files: #Store all of the files
- "register-core/target/surefire-reports/**/*"
- "provider/register-aws/target/surefire-reports/**/*"
base-directory: "." # Location of the reports
artifacts:
files:
- "**/*"
base-directory: "dist"
name: ${REPO_NAME}_${BRANCH_NAME}_$(date +%F)_${CODEBUILD_BUILD_NUMBER}.zip
cache:
paths:
- "/root/.m2/**/*"
\ No newline at end of file
{
"name": "os-register",
"description": "Build of the os-register repository",
"source": {
"type": "CODECOMMIT",
"location": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/os-register",
"gitCloneDepth": 1,
"gitSubmodulesConfig": {
"fetchSubmodules": false
},
"buildspec": "./provider/register-aws/build-aws/buildspec.yaml",
"insecureSsl": false
},
"secondarySources": [],
"sourceVersion": "refs/heads/dev",
"secondarySourceVersions": [],
"artifacts": {
"type": "S3",
"location": "888733619319-devops-build-artifacts",
"path": "os-register",
"namespaceType": "NONE",
"name": "os-register",
"packaging": "ZIP",
"overrideArtifactName": true,
"encryptionDisabled": false
},
"secondaryArtifacts": [],
"cache": {
"type": "LOCAL",
"modes": [
"LOCAL_CUSTOM_CACHE"
]
},
"environment": {
"type": "LINUX_CONTAINER",
"image": "aws/codebuild/standard:4.0",
"computeType": "BUILD_GENERAL1_SMALL",
"environmentVariables": [
{
"name": "ECR_REGISTRY",
"value": "888733619319.dkr.ecr.us-east-1.amazonaws.com/os-register_dev",
"type": "PLAINTEXT"
},
{
"name": "AWS_OSDU_DEV_MAVEN_URL",
"value": "https://osdu-dev-888733619319.d.codeartifact.us-east-1.amazonaws.com/maven/osdu-maven/",
"type": "PLAINTEXT"
},
{
"name": "AWS_OSDU_DEV_MAVEN_DOMAIN",
"value": "osdu-dev",
"type": "PLAINTEXT"
}
],
"privilegedMode": true,
"imagePullCredentialsType": "CODEBUILD"
},
"serviceRole": "arn:aws:iam::888733619319:role/service-role/dev-CodeBuildRole",
"timeoutInMinutes": 60,
"queuedTimeoutInMinutes": 480,
"encryptionKey": "arn:aws:kms:us-east-1:888733619319:alias/aws/s3",
"tags": [],
"vpcConfig": {
"vpcId": "vpc-0f273733df61bc541",
"subnets": [
"subnet-03963a50e77043e12",
"subnet-04a975f0e6e0c9279"
],
"securityGroupIds": [
"sg-0dee4e811c2062e26"
]
},
"badgeEnabled": true,
"logsConfig": {
"cloudWatchLogs": {
"status": "ENABLED"
},
"s3Logs": {
"status": "DISABLED",
"encryptionDisabled": false
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2020 Amazon Web Services
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>aws-osdu-dev-maven</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>aws-osdu-dev-maven</id>
<url>${env.AWS_OSDU_DEV_MAVEN_URL}</url>
</repository>
<repository>
<id>gitlab-os-core-common-maven</id>
<url>https://community.opengroup.org/api/v4/projects/67/packages/maven</url>
</repository>
</repositories>
</profile>
<profile>
<id>credentialsConfiguration</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<deployment.environment>dev</deployment.environment>
<aws.accessKeyId>no-default</aws.accessKeyId>
<aws.secretKey>no-default</aws.secretKey>
<azure.devops.username>Another-Access-Token-2021</azure.devops.username>
<azure.devops.token>no-default</azure.devops.token>
</properties>
</profile>
</profiles>
<servers>
<server>
<id>aws-osdu-dev-maven</id>
<username>aws</username>
<password>${env.AWS_OSDU_DEV_MAVEN_AUTH_TOKEN}</password>
</server>
</servers>
<!-- CodeArtifact doesn't support external repos yet that aren't Maven Central. ETA Q4 2020. -->
<!-- <mirrors> -->
<!-- <mirror> -->
<!-- <id>aws-osdu-dev-maven</id> -->
<!-- <name>aws-osdu-dev-maven</name> -->
<!-- <url>https://osdu-dev-888733619319.d.codeartifact.us-east-1.amazonaws.com/maven/osdu-maven/</url> -->
<!-- <mirrorOf>*,!gitlab-os-core-common-maven</mirrorOf> -->
<!-- </mirror> -->
<!-- </mirrors> -->
<activeProfiles>
<activeProfile>credentialsConfiguration</activeProfile>
</activeProfiles>
</settings>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2020 Amazon Web Services
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>register-aws</artifactId>
<version>1.0.0</version>
<description>Register service on AWS</description>
<packaging>jar</packaging>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-register</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<properties>
<aws.version>1.11.637</aws.version>
</properties>
<dependencies>
<!-- AWS managed packages -->
<!--<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws.version}</version>
</dependency>-->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cognitoidentity</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kms</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.3.11</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>register-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Third party Apache 2.0 license packages -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<version>1.11.651</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/157/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/157/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>org.opengroup.osdu.register.provider.aws.RegisterApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(value = {
"org.opengroup.osdu.register",
"org.opengroup.osdu.core",
"org.opengroup.osdu.aws"
})
@SpringBootApplication
public class RegisterApplication {
public static void main(String[] args) {
SpringApplication.run(RegisterApplication.class, args);
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.action;
import com.amazonaws.services.dynamodbv2.datamodeling.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.action.model.Filter;
import java.sql.Timestamp;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@DynamoDBTable(tableName = "Register.Action")
public class ActionDoc {
@DynamoDBHashKey(attributeName = "id")
private String id;
@DynamoDBAttribute(attributeName = "name")
private String name;
@DynamoDBAttribute(attributeName = "description")
private String description;
@DynamoDBAttribute(attributeName = "img")
private String img;
@DynamoDBAttribute(attributeName = "url")
private String url;
@DynamoDBAttribute(attributeName = "contactEmail")
private String contactEmail;
@DynamoDBAttribute(attributeName = "createdOnEpoch")
private String createdOnEpoch;
@DynamoDBAttribute(attributeName = "dataPartitionId")
private String dataPartitionId;
@DynamoDBTypeConverted(converter = ActionDoc.ActionConverter.class)
@DynamoDBAttribute(attributeName = "filter")
private Filter filter;
public static class ActionConverter implements DynamoDBTypeConverter<String, Filter> {
@SneakyThrows
@Override
public String convert(Filter object) {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(object);
}
@SneakyThrows
@Override
public Filter unconvert(String object) {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(object, new TypeReference<Filter>() {
});
}
}
public static ActionDoc mapFrom(Action action, String dataPartitionId) {
ActionDocBuilder actionDocBuilder = new ActionDoc().builder()
.id(action.getId())
.name(action.getName())
.description(action.getDescription())
.img(action.getImg())
.url(action.getUrl())
.contactEmail(action.getContactEmail())
.filter(action.getFilter())
.createdOnEpoch((new Timestamp(System.currentTimeMillis())).toString())
.dataPartitionId(dataPartitionId);
return actionDocBuilder.build();
}
public static Action mapto(ActionDoc actionDoc) {
Action action = new Action();
action.setId(actionDoc.getId());
action.setName(actionDoc.getName());
action.setDescription(actionDoc.getDescription());
action.setImg(actionDoc.getImg());
action.setUrl(actionDoc.getUrl());
action.setContactEmail(actionDoc.getContactEmail());
Timestamp sqlTimestamp = Timestamp.valueOf(actionDoc.getCreatedOnEpoch());
com.google.cloud.Timestamp t = com.google.cloud.Timestamp.of(sqlTimestamp);
action.setCreatedOnEpoch(t);
action.setFilter(actionDoc.getFilter());
return action;
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.action;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.opengroup.osdu.register.provider.aws.util.DocUtil;
import org.opengroup.osdu.register.provider.interfaces.action.IActionRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Repository
public class AwsActionRepo implements IActionRepo {
@Autowired
private DpsHeaders dpsHeaders;
@Autowired
private JaxRsDpsLog logger;
@Inject
private AwsServiceConfig serviceConfig;
private DynamoDBQueryHelper queryHelper;
@Autowired
DocUtil docUtil;
@PostConstruct
public void init() {
queryHelper = new DynamoDBQueryHelper(serviceConfig.getDynamoDbEndpoint(),
serviceConfig.getAmazonRegion(),
serviceConfig.getDynamoDbTablePrefix());
}
@Override
public List<Action> getAllActions() {
List<String> filters = new ArrayList<>();
Map<String, AttributeValue> valueMap = new HashMap<>();
filters.add("dataPartitionId = :dataPartitionId");
valueMap.put(":dataPartitionId", new AttributeValue().withS(dpsHeaders.getPartitionId()));
String filterExpression = String.join(" and ", filters);
logger.info(String.format("Action query filter expression: %s", filterExpression));
List<ActionDoc> results = queryHelper.scanTable(ActionDoc.class, filterExpression, valueMap);
List<Action> actionsList = results.stream().map(ActionDoc::mapto).collect(Collectors.toList());
//Alternative implementation
/* List<Action> actionsList = new ArrayList<Action>();
for (ActionDoc actionDoc : results){
actionsList.add(ActionDoc.mapto(actionDoc));
}*/
return actionsList;
}
@Override
public Action createAction(Action action) {
if(action.getId() == null){
logger.error("Action id cannot be null");
throw new AppException(400, "Bad Request", "Action id cannot be null");
}
ActionDoc doc = ActionDoc.mapFrom(action, dpsHeaders.getPartitionId());
try {
queryHelper.saveWithHashCondition(doc,docUtil.getHashKey());
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("An action already exists with the id: %s", action.getId()));
throw new AppException(409, "Conflict", String.format("An action already exists with the id: %s", action.getId()));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return action;
}
@Override
public boolean delete(String id) {
try{
ActionDoc objectTodelete = new ActionDoc();
objectTodelete.setId(id);
DynamoDBDeleteExpression deleteExpression = new DynamoDBDeleteExpression()
.withConditionExpression("attribute_exists(id)");
queryHelper.deleteByObjectWithCondition(objectTodelete,deleteExpression);
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("Failed to delete: %s Object does not exist",id));
throw new AppException(404, "ObjectNotFound", String.format("The Action you are trying to delete: %s does not exist", id));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return true;
}
@Override
public Action get(String id){
ActionDoc doc = queryHelper.loadByPrimaryKey(ActionDoc.class, id);
if (doc == null) {
logger.error(String.format("Action with id %s does not exist.", id));
throw new AppException(404, "Not found", String.format("Action with id %s does not exist.", id));
} else {
return ActionDoc.mapto(doc);
}
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.config;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersResult;
import com.amazonaws.services.simplesystemsmanagement.model.ParameterNotFoundException;
import com.amazonaws.services.simplesystemsmanagement.model.InternalServerErrorException;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import com.amazonaws.services.sns.AmazonSNS;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.aws.iam.IAMConfig;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.register.provider.aws.subscriber.KmsConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import org.opengroup.osdu.core.common.model.http.AppException;
@Component
public class AwsServiceConfig {
@Value("${aws.region}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String amazonRegion;
@Value("${aws.dynamodb.table.prefix}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String dynamoDbTablePrefix;
@Value("${aws.dynamodb.endpoint}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String dynamoDbEndpoint;
@Value("${aws.ssm}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public Boolean ssmEnabled;
@Value("${aws.kms.endpoint}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String kmsEndpoint;
@Value("${aws.environment}")
@Getter()
@Setter(AccessLevel.PROTECTED)
public String environment;
@Getter()
public String kmsKeyId;
@Getter()
public String snsTopicArn;
@Getter()
public AWSKMS kmsClient;
@Getter()
public AmazonSNS snsClient;
private AWSCredentialsProvider amazonAWSCredentials;
private AWSSimpleSystemsManagement ssmManager;
@PostConstruct
public void init() {
if (ssmEnabled) {
AmazonSNSConfig snsConfig = new AmazonSNSConfig(amazonRegion);
snsClient = snsConfig.AmazonSNS();
KmsConfig kmsConfig = new KmsConfig(kmsEndpoint, amazonRegion);
kmsClient = kmsConfig.awsKMS();
try {
String keyssmparameter = "/osdu/" + environment + "/register/kpath";
String snstopicArnParameter = "/osdu/" + environment + "/register/register-sns-topic-arn";
amazonAWSCredentials = IAMConfig.amazonAWSCredentials();
ssmManager = AWSSimpleSystemsManagementClientBuilder.standard()
.withCredentials(amazonAWSCredentials)
.withRegion(amazonRegion)
.build();
List<String> paramsList = new ArrayList<String>();
paramsList.add(keyssmparameter);
paramsList.add(snstopicArnParameter);
GetParametersRequest paramRequest = new GetParametersRequest()
.withNames(paramsList)
.withWithDecryption(true);
GetParametersResult paramResult = new GetParametersResult();
paramResult = ssmManager.getParameters(paramRequest);
System.out.println("SSM Parameters retrieved");
List<Parameter> paramsResultList = new ArrayList<>();
paramsResultList = paramResult.getParameters();
for (Parameter s : paramsResultList) {
if(s.getName().equalsIgnoreCase(keyssmparameter)) {
kmsKeyId = s.getValue();
}
if(s.getName().equalsIgnoreCase(snstopicArnParameter)) {
snsTopicArn = s.getValue();
}
}
} catch (ParameterNotFoundException e) {
throw new AppException(HttpStatus.SC_NOT_FOUND, "SSM ParameterNotFoundException",e.getErrorMessage());
} catch (InternalServerErrorException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "SSM InternalServerErrorException",e.getErrorMessage());
}
}
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.ddms;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.ddms.model.Ddms;
import org.opengroup.osdu.register.provider.aws.action.ActionDoc;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.opengroup.osdu.register.provider.aws.util.DocUtil;
import org.opengroup.osdu.register.provider.interfaces.ddms.IDdmsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@Repository
public class AwsDdmsRepo implements IDdmsRepository {
@Autowired
private DpsHeaders dpsHeaders;
@Autowired
private JaxRsDpsLog logger;
@Inject
private AwsServiceConfig serviceConfig;
private DynamoDBQueryHelper queryHelper;
@Autowired
DocUtil docUtil;
@PostConstruct
public void init() {
queryHelper = new DynamoDBQueryHelper(serviceConfig.getDynamoDbEndpoint(),
serviceConfig.getAmazonRegion(),
serviceConfig.getDynamoDbTablePrefix());
}
@Override
public Ddms create(Ddms ddms) {
DdmsDoc doc = DdmsDoc.mapFrom(ddms, dpsHeaders.getPartitionId());
try {
queryHelper.saveWithHashCondition(doc,docUtil.getHashKey());
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("An DDMS already exists with the id: %s", ddms.getId()));
throw new AppException(409, "Conflict", String.format("An DDMS already exists with the id: %s", ddms.getId()));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return ddms;
}
@Override
public Ddms get(String id) {
DdmsDoc doc = queryHelper.loadByPrimaryKey(DdmsDoc.class, id);
if (doc == null) {
logger.error(String.format("Ddms with id %s does not exist.", id));
throw new AppException(404, "Not found", String.format("Ddms with id %s does not exist.", id));
} else {
return DdmsDoc.mapto(doc);
}
}
@Override
public List<Ddms> query(String entityType) {
String dataPartitionId = dpsHeaders.getPartitionId();
DdmsDoc gsiQuery = new DdmsDoc();
String key = String.format("%s:%s",dataPartitionId,entityType);
gsiQuery.setPartitionIdEntityType(key);
List<Ddms> ddmsList = docUtil.getDdmsList(queryHelper,gsiQuery);
return ddmsList;
}
@Override
public boolean delete(String id) {
try{
DdmsDoc objectTodelete = new DdmsDoc();
objectTodelete.setId(id);
DynamoDBDeleteExpression deleteExpression = new DynamoDBDeleteExpression()
.withConditionExpression("attribute_exists(id)");
queryHelper.deleteByObjectWithCondition(objectTodelete,deleteExpression);
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("Failed to delete: %s Object does not exist",id));
throw new AppException(404, "ObjectNotFound", String.format("The Ddms you are trying to delete: %s does not exist", id));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return true;
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.ddms;
import com.amazonaws.services.dynamodbv2.datamodeling.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.opengroup.osdu.register.ddms.model.Ddms;
import org.opengroup.osdu.register.ddms.model.RegisteredInterface;
import java.sql.Timestamp;
import java.util.Set;
import java.util.stream.Collectors;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@DynamoDBTable(tableName = "Register.Ddms")
public class DdmsDoc {
@DynamoDBHashKey(attributeName = "id")
private String id;
@DynamoDBAttribute(attributeName = "name")
private String name;
@DynamoDBAttribute(attributeName = "description")
private String description;
@DynamoDBAttribute(attributeName = "contactEmail")
private String contactEmail;
@DynamoDBAttribute(attributeName = "createdDateTimeEpoch")
private String createdDateTimeEpoch;
@DynamoDBAttribute(attributeName = "dataPartitionId")
private String dataPartitionId;
@DynamoDBIndexHashKey(attributeName = "partitionIdEntityType", globalSecondaryIndexName = "entityType-index") //Added this for query api
private String partitionIdEntityType;
@DynamoDBTypeConverted(converter = DdmsDoc.DdmsConverter.class)
@DynamoDBAttribute(attributeName = "interfaces")
// private Set<RegInterfaceDoc> interfaces;
private Set<RegisteredInterface> interfaces;
public static class DdmsConverter implements DynamoDBTypeConverter<String, Set<RegisteredInterface>> {
@SneakyThrows
@Override
public String convert(Set<RegisteredInterface> object) {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(object);
}
@SneakyThrows
@Override
public Set<RegisteredInterface> unconvert(String object) {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(object, new TypeReference<Set<RegisteredInterface>>() {
});
}
}
public static DdmsDoc mapFrom(Ddms ddms, String dataPartitionId) {
DdmsDocBuilder ddmsDocBuilder = new DdmsDoc().builder()
.id(ddms.getId())
.name(ddms.getName())
.description(ddms.getDescription())
.contactEmail(ddms.getContactEmail())
.createdDateTimeEpoch((new Timestamp(System.currentTimeMillis())).toString())
.interfaces(ddms.getInterfaces())
.dataPartitionId(dataPartitionId)
.partitionIdEntityType(String.format("%s:%s",dataPartitionId,getEntityType(ddms)));
return ddmsDocBuilder.build();
}
public static Ddms mapto(DdmsDoc ddmsDoc) {
Ddms ddms = new Ddms();
ddms.setId(ddmsDoc.getId());
ddms.setName(ddmsDoc.getName());
ddms.setDescription(ddmsDoc.getDescription());
ddms.setContactEmail(ddmsDoc.getContactEmail());
Timestamp sqlTimestamp = Timestamp.valueOf(ddmsDoc.getCreatedDateTimeEpoch());
com.google.cloud.Timestamp t = com.google.cloud.Timestamp.of(sqlTimestamp);
ddms.setCreatedDateTimeEpoch(t);
ddms.setInterfaces(ddmsDoc.getInterfaces());
return ddms;
}
private static RegInterfaceDoc getRegisteredInterfaceDoc(RegisteredInterface reginterface){
return new RegInterfaceDoc(reginterface.getEntityType(), reginterface.getSchema());
}
private static RegisteredInterface getRegisteredInterface(RegInterfaceDoc doc){
RegisteredInterface registeredInterface = new RegisteredInterface();
registeredInterface.setEntityType(doc.getEntityType());
registeredInterface.setSchema(doc.getSchema());
return registeredInterface;
}
private static String getEntityType(Ddms ddms){
String entityType="";
//get the first element from the set
RegisteredInterface ri = ddms.getInterfaces().iterator().next();
if(ri!=null) {
RegInterfaceDoc regIntDoc = DdmsDoc.getRegisteredInterfaceDoc(ri);
entityType = regIntDoc.getEntityType();
}
return entityType;
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.ddms;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.Map;
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class RegInterfaceDoc {
private String entityType;
private Map<String, Object> schema;
}
\ No newline at end of file
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.pushApi;
import com.amazonaws.services.sns.message.*;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.common.base.Strings;
import com.google.common.hash.Hashing;
import org.opengroup.osdu.core.common.cryptographic.ISignatureService;
import org.opengroup.osdu.core.common.cryptographic.SignatureServiceException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.utils.AppServiceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
//used by integration test to validate challenge response logic and confirm subscription
@RestController
@RequestMapping("/awstest")
@RequestScope
@Validated
public class AwsSubscriberTestListenerApi {
@Autowired
private AppServiceConfig serviceConfig;
@Autowired
private ISignatureService signatureService;
@Autowired
private JaxRsDpsLog logger;
@Inject
private javax.inject.Provider<DpsHeaders> headersProvider;
private final SnsMessageManager messageParser = new SnsMessageManager();
@GetMapping("/aws/challenge/{count}")
public ResponseEntity<?> testCrc(@RequestParam("crc") @NotBlank String crc, @RequestParam("hmac") @NotBlank String hmac) {
try {
signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret());
} catch (SignatureServiceException e) {
return new ResponseEntity<>("Authorization signature validation Failed", HttpStatus.BAD_REQUEST);
}
logger.info("Signature verified and sending response");
// Use the secret you send to the subscriber registration create request
return getResponse(crc, this.serviceConfig.getSubscriberSecret());
}
@PostMapping("/aws/challenge/{count}")
public void process(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
messageParser.handleMessage(httpRequest.getInputStream(), new DefaultSnsMessageHandler() {
@Override
public void handle(SnsNotification snsNotification) {
// If the subject is "unsubscribe" then unsubscribe from this topic
if (snsNotification.getSubject().equalsIgnoreCase("unsubscribe")) {
snsNotification.unsubscribeFromTopic();
} else {
// Otherwise process the message
System.out.printf("Received message %n"
+ "Subject=%s %n"
+ "Message = %s %n",
snsNotification.getSubject(), snsNotification.getMessage());
}
}
@Override
public void handle(SnsUnsubscribeConfirmation message) {
logger.info("Received unsubscribe confirmation.");
}
@Override
public void handle(SnsSubscriptionConfirmation message) {
super.handle(message);
logger.info("Received subscription confirmation.");
}
});
}
@PostMapping("challenge/{count}")
public ResponseEntity testPushHmac(@RequestBody Object o, @RequestParam("hmac") String hmac) {
try {
signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret());
} catch (SignatureServiceException e) {
return new ResponseEntity<>("Authorization signature validation Failed", HttpStatus.BAD_REQUEST);
}
logger.info("Sending acknowledgement from hmac endpoint");
return new ResponseEntity<>(HttpStatus.OK);
}
class ChallengeResponse {
public String responseHash = "";
}
private boolean verifyToken() {
DpsHeaders headers = headersProvider.get();
if (Strings.isNullOrEmpty(headers.getAuthorization()))
return true;
try {
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance())
.setAudience(Collections.singletonList(this.serviceConfig.getIntegrationTestJwtAudiences()))
.build();
GoogleIdToken idToken = verifier.verify(headers.getAuthorization());
return idToken != null;
} catch (Exception ex) {
return false;
}
}
private ResponseEntity<ChallengeResponse> getResponse(String crc, String secretString) {
String response = secretString + crc;
response = Hashing.sha256()
.hashString(response, StandardCharsets.UTF_8)
.toString();
response = Base64.getEncoder().encodeToString(response.getBytes());
ChallengeResponse cr = new ChallengeResponse();
cr.responseHash = response;
return new ResponseEntity<>(cr, HttpStatus.OK);
}
}
// Copyright © 2020 Amazon Web Services
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.security;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class AwsSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable()
.csrf().disable(); //disable default authN. AuthN handled by endpoints proxy
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.subscriber;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import com.amazonaws.services.sns.AmazonSNS;
import com.google.cloud.Timestamp;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.core.aws.ssm.ParameterStorePropertySource;
import org.opengroup.osdu.core.aws.ssm.SSMConfig;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.aws.action.ActionDoc;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.opengroup.osdu.register.provider.aws.util.DocUtil;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
import org.opengroup.osdu.register.subscriber.model.*;
import org.opengroup.osdu.register.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.nio.ByteBuffer;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Repository
public class AwsSubscriptionRepo implements ISubscriptionRepository {
@Autowired
private DpsHeaders dpsHeaders;
@Autowired
private JaxRsDpsLog logger;
private DynamoDBQueryHelper queryHelper;
@Inject
private AwsServiceConfig serviceConfig;
private String amazonSNSTopicArn_records_changed;
private SSMConfig ssmConfig;
private ParameterStorePropertySource ssm;
@Autowired
private SubscriptionHelper snsHelper;
@Autowired
private KmsHelper kmsHelper;
@Autowired
DocUtil docUtil;
@PostConstruct
public void init() {
// TODO: serviceConfig.environment isn't correct and needs to be table prefix. Maybe the "-" will fix it
queryHelper = new DynamoDBQueryHelper(serviceConfig.getDynamoDbEndpoint(),
serviceConfig.getAmazonRegion(),
serviceConfig.getDynamoDbTablePrefix());
amazonSNSTopicArn_records_changed=serviceConfig.getSnsTopicArn();
}
@Override
public Subscription create(Subscription s) throws Exception {
String pushEndPoint = s.getPushEndpoint();
String subscriptionArn = snsHelper.createPushSubscription(amazonSNSTopicArn_records_changed,pushEndPoint);
ByteBuffer encryptedSecretValue = kmsHelper.encrypt(s.getSecret().toString());
SubscriptionDoc doc = SubscriptionDoc.mapFrom(s, dpsHeaders.getPartitionId(),subscriptionArn,encryptedSecretValue);
try {
queryHelper.saveWithHashCondition(doc,docUtil.getHashKey());
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("A subscription already exists with the id: %s", s.getId()));
throw new AppException(409, "Conflict", String.format("A subscription already exists with the id: %s", s.getId()));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return s;
}
@Override
public Subscription get(String id) {
SubscriptionDoc doc = queryHelper.loadByPrimaryKey(SubscriptionDoc.class, id);
if (doc == null) {
logger.error(String.format("Subscription with id %s does not exist.", id));
throw new AppException(404, "Not found", String.format("Subscription with id %s does not exist.", id));
} else {
String secretValue = kmsHelper.decrypt(doc.getSecretValue());
Secret secret = docUtil.createSecret(doc.getSecretType(),secretValue);
Subscription s = SubscriptionDoc.mapTo(doc,secret);
return s;
}
}
@Override
public List<Subscription> query(String notificationId) {
String key=String.format("%s:%s",dpsHeaders.getPartitionId(),notificationId);
SubscriptionDoc gsiQuery = new SubscriptionDoc();
gsiQuery.setPartitionIdNotificationId(key);
List<Subscription> subsList = docUtil.getSubscriptionList(queryHelper,gsiQuery);
return subsList;
}
@Override
public boolean delete(String id) {
SubscriptionDoc doc=null;
String snsSubscriptionArn="";
try {
//Need this to retrieve the subscription Arn
doc = queryHelper.loadByPrimaryKey(SubscriptionDoc.class, id);
if (doc == null) {
logger.error(String.format("Subscription with id %s does not exist.", id));
throw new AppException(404, "Not found", String.format("Subscription with id %s does not exist.", id));
}
else {
snsSubscriptionArn = doc.getSnssubscriptionArn();
// queryHelper.deleteByPrimaryKey(SubscriptionDoc.class, id);
SubscriptionDoc objectTodelete = new SubscriptionDoc();
objectTodelete.setId(id);
DynamoDBDeleteExpression deleteExpression = new DynamoDBDeleteExpression()
.withConditionExpression("attribute_exists(id)");
queryHelper.deleteByObjectWithCondition(objectTodelete,deleteExpression);
}
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("Failed to delete: %s Object does not exist",id));
throw new AppException(404, "ObjectNotFound", String.format("The Subscription you are trying to delete: %s does not exist", id));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
//delete the SNS subscription
//this will throw 404 if SNS Subscription not found
snsHelper.deletePushSubscription(snsSubscriptionArn);
return true;
}
@Override
public boolean patch(Subscription subscription, Secret secret) {
SubscriptionDoc doc=null;
String id = subscription.getId();
try {
doc = queryHelper.loadByPrimaryKey(SubscriptionDoc.class, id);
}catch(AppException e)
{
if(e.getError().getCode() == 404) {
logger.error("Could not find subscription with Id %s ", id);
throw e;
}
else {
logger.error(e.getMessage());
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
}
//update the secret
doc.setSecretType(secret.getSecretType());
doc.setSecretValue(kmsHelper.encrypt(secret.toString()));
try{
queryHelper.save(doc);
} catch (AppException e) {
String msg="Error while saving the updated secret";
throw new AppException(e.getError().getCode(), e.getError().getReason(), msg);
}
return true;
}
@Override
public List<Subscription> getAll() throws Exception {
List<String> filters = new ArrayList<>();
Map<String, AttributeValue> valueMap = new HashMap<>();
List<SubscriptionDoc> results=null;
filters.add("dataPartitionId = :dataPartitionId");
valueMap.put(":dataPartitionId", new AttributeValue().withS(dpsHeaders.getPartitionId()));
String filterExpression = String.join(" and ", filters);
logger.info(String.format("Subscription query filter expression: %s", filterExpression));
try {
results = queryHelper.scanTable(SubscriptionDoc.class, filterExpression, valueMap);
}
catch(AppException e)
{
String msg="Error while getting ALL subscriptions";
throw new AppException(e.getError().getCode(), e.getError().getReason(), msg);
}
List<Subscription> subsList = new ArrayList<Subscription>();
for (SubscriptionDoc subsDoc : results){
String secretValue = kmsHelper.decrypt(subsDoc.getSecretValue());
Secret secret = docUtil.createSecret(subsDoc.getSecretType(),secretValue);
subsList.add(SubscriptionDoc.mapTo(subsDoc,secret));
}
return subsList;
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.subscriber;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClientBuilder;
import org.opengroup.osdu.core.aws.iam.IAMConfig;
//This class should be moved to os-core-lib-aws. Keeping it here temporarily till testing is complete
public class KmsConfig {
private String amazonKmsEndpoint;
private String amazonKmsRegion;
private AWSCredentialsProvider amazonAWSCredentials;
public KmsConfig(String amazonKmsEndpoint, String amazonKmsRegion){
amazonAWSCredentials = IAMConfig.amazonAWSCredentials();
this.amazonKmsEndpoint = amazonKmsEndpoint;
this.amazonKmsRegion = amazonKmsRegion;
}
public AWSKMS awsKMS() {
// Generate the KMS client
return AWSKMSClientBuilder.standard()
.withCredentials(amazonAWSCredentials)
.withEndpointConfiguration(amazonKmsEndpointConfiguration())
.build();
}
public AwsClientBuilder.EndpointConfiguration amazonKmsEndpointConfiguration() {
// Create an endpoint configuration for KMS with region and service endpoint from application.properties
return new AwsClientBuilder.EndpointConfiguration(
amazonKmsEndpoint, amazonKmsRegion
);
}
}
// Copyright © 2020 Amazon Web Services
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.subscriber;
import com.amazonaws.services.kms.model.DecryptRequest;
import com.amazonaws.services.kms.model.DecryptResult;
import com.amazonaws.services.kms.model.EncryptRequest;
import com.amazonaws.services.kms.model.EncryptResult;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.aws.ssm.ParameterStorePropertySource;
import org.opengroup.osdu.core.aws.ssm.SSMConfig;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import com.amazonaws.services.kms.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.util.Base64Utils;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
@Component
public class KmsHelper {
@Autowired
private DpsHeaders dpsHeaders;
@Autowired
private JaxRsDpsLog logger;
@Inject
private AwsServiceConfig serviceConfig;
private AWSKMS kmsClient;
private String kmsKeyId;
@PostConstruct
public void init() {
kmsClient = serviceConfig.getKmsClient();
kmsKeyId=serviceConfig.getKmsKeyId();
}
public ByteBuffer encrypt(String plainTextString) {
EncryptRequest encReq = new EncryptRequest();
encReq.setKeyId(kmsKeyId);
encReq.setPlaintext(ByteBuffer.wrap(plainTextString.getBytes()));
encReq.setEncryptionContext(Collections.singletonMap("dataPartitionId", dpsHeaders.getPartitionId()));
ByteBuffer ciphertext = kmsClient.encrypt(encReq).getCiphertextBlob();
return ciphertext;
}
public String decrypt(ByteBuffer ciphertext) {
DecryptRequest decReq = new DecryptRequest();
decReq.setCiphertextBlob(ciphertext);
decReq.setEncryptionContext(Collections.singletonMap("dataPartitionId", dpsHeaders.getPartitionId()));
ByteBuffer decrypted = kmsClient.decrypt(decReq).getPlaintext();
String decryptedStr = new String(decrypted.array());
return decryptedStr;
}
}