diff --git a/.fossa.yml b/.fossa.yml index ad198294f8c5fb49dd2d00f408493f3993af057c..c530ca18f16acf9fb7f442885d83823722930904 100644 --- a/.fossa.yml +++ b/.fossa.yml @@ -32,3 +32,7 @@ analyze: type: mvn target: provider/legal-aws/pom.xml path: . + - name: legal-ibm + type: mvn + target: provider/legal-ibm/pom.xml + path: . diff --git a/.gitignore b/.gitignore index b7efba2c016b12bc92d6fe6c2e2a9c9d0da6ff4d..5bc7bc15b40092714e3cdcb59ec02317c0286983 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ build/ # Environment configuration *.env +.envrc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9d280ff22abe139564537ffe29f29cd7aca21a72..bec86ffedd94b7897a55186d807a710ef70090e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,39 +6,53 @@ variables: GCP_BUILD_SUBDIR: provider/legal-gcp GCP_INT_TEST_SUBDIR: testing/legal-test-gcp - GCP_APPLICATION_NAME: os-legal GCP_ENVIRONMENT: testing GCP_PROJECT: opendes-evt GCP_TENANT_NAME: opendes-evt + OSDU_GCP_BUILD_SUBDIR: provider/legal-gcp + OSDU_GCP_INT_TEST_SUBDIR: testing/legal-test-gcp + OSDU_GCP_APPLICATION_NAME: os-legal + + IBM_BUILD_SUBDIR: provider/legal-ibm + IBM_INT_TEST_SUBDIR: testing/legal-test-ibm + AZURE_SERVICE: legal AZURE_BUILD_SUBDIR: provider/legal-azure AZURE_TEST_SUBDIR: testing/legal-test-azure - IBM_BUILD_SUBDIR: provider/legal-ibm - IBM_INT_TEST_SUBDIR: testing/legal-test-ibm include: - project: "osdu/platform/ci-cd-pipelines" file: "standard-setup.yml" + - project: "osdu/platform/ci-cd-pipelines" file: "build/maven.yml" - - project: 'osdu/platform/ci-cd-pipelines' - ref: "master" - file: "cloud-providers/azure.yml" - - project: 'osdu/platform/ci-cd-pipelines' - ref: "master" - file: 'cloud-providers/gcp.yml' - - project: 'osdu/platform/ci-cd-pipelines' - file: 'cloud-providers/aws.yml' - - project: 'osdu/platform/ci-cd-pipelines' - file: 'cloud-providers/ibm.yml' + - project: "osdu/platform/ci-cd-pipelines" file: "scanners/fossa.yml" + - project: "osdu/platform/ci-cd-pipelines" file: "scanners/gitlab-ultimate.yml" + - project: "osdu/platform/ci-cd-pipelines" + file: "cloud-providers/aws.yml" + + - project: "osdu/platform/ci-cd-pipelines" + file: "cloud-providers/ibm.yml" + + - project: "osdu/platform/ci-cd-pipelines" + file: "cloud-providers/azure.yml" + + - project: 'osdu/platform/ci-cd-pipelines' + ref: "master" + file: 'cloud-providers/osdu-gcp.yml' + + - project: 'osdu/platform/ci-cd-pipelines' + ref: "master" + file: 'cloud-providers/gcp.yml' + compile-and-unit-test: variables: GOOGLE_CLOUD_PROJECT: opendes-evt diff --git a/NOTICE b/NOTICE index ac0c9a28fd76c6b8c9dd234d458d7ae5218da465..166e725082f67083b4444d6c55bc7027a908e3de 100644 --- a/NOTICE +++ b/NOTICE @@ -25,6 +25,8 @@ Apache-2.0 ======================================================================== The following software have components provided under the terms of this license: +- AMQP 1.0 JMS Spring Boot AutoConfiguration (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-autoconfigure) +- AMQP 1.0 JMS Spring Boot Starter (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-starter) - ASM Analysis (from ) - ASM Commons (from ) - ASM Core (from ) @@ -235,8 +237,13 @@ The following software have components provided under the terms of this license: - Apache Commons Text (from http://commons.apache.org/proper/commons-text/) - Apache Commons Validator (from http://commons.apache.org/proper/commons-validator/) - Apache Commons Validator (from http://commons.apache.org/proper/commons-validator/) +- Apache Geronimo JMS Spec 2.0 (from http://geronimo.apache.org/maven/${siteId}/${version}) +- Apache Groovy (from http://groovy-lang.org) +- Apache Groovy (from http://groovy-lang.org) +- Apache Groovy (from http://groovy-lang.org) - Apache HttpAsyncClient (from http://hc.apache.org/httpcomponents-asyncclient) - Apache HttpClient (from http://hc.apache.org/httpcomponents-client) +- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client) - Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga) - Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga) - Apache Log4j API (from ) @@ -267,6 +274,7 @@ The following software have components provided under the terms of this license: - Commons Digester (from http://commons.apache.org/digester/) - Commons Digester (from http://commons.apache.org/digester/) - Commons IO (from http://commons.apache.org/io/) +- Commons IO (from http://commons.apache.org/io/) - Commons Lang (from http://commons.apache.org/lang/) - Converter: Jackson (from ) - Doxia :: APT Module (from ) @@ -299,6 +307,10 @@ The following software have components provided under the terms of this license: - Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) - HPPC Collections (from http://labs.carrotsearch.com) - Hibernate Validator Engine (from ) +- IBM COS Java SDK for Amazon S3 (from https://github.com/ibm/ibm-cos-sdk-java) +- IBM COS Java SDK for COS KMS (from https://github.com/ibm/ibm-cos-sdk-java) +- IBM COS SDK For Java (from https://github.com/ibm/ibm-cos-sdk-java) +- IBM COS SDK for Java - Core (from https://github.com/ibm/ibm-cos-sdk-java) - Identity and Access Management (IAM) API v1-rev247-1.23.0 (from ) - J2ObjC Annotations (from https://github.com/google/j2objc/) - J2ObjC Annotations (from https://github.com/google/j2objc/) @@ -330,6 +342,7 @@ The following software have components provided under the terms of this license: - Java Servlet API (from http://servlet-spec.java.net) - Java UUID Generator (from http://wiki.fasterxml.com/JugHome) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) - Jetty Server (from ) - Jetty Utilities (from ) - Joda-Time (from http://www.joda.org/joda-time/) @@ -370,6 +383,7 @@ The following software have components provided under the terms of this license: - Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java) +- Microsoft Azure Netty HTTP Client Library (from https://github.com/Azure/azure-sdk-for-java) - Mockito (from http://www.mockito.org) - Mockito (from http://mockito.org) - Mockito (from http://mockito.org) @@ -395,8 +409,10 @@ The following software have components provided under the terms of this license: - OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions) - Objenesis (from http://objenesis.org) - OkHttp (from ) +- OkHttp (from ) - OkHttp Logging Interceptor (from ) - OkHttp URLConnection (from ) +- OkHttp URLConnection (from ) - Okio (from ) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) @@ -408,6 +424,7 @@ The following software have components provided under the terms of this license: - Plexus Velocity Component (from ) - PowerMock (from http://www.powermock.org) - Protocol Buffer extensions to the Google HTTP Client Library for Java. (from ) +- QpidJMS Client (from ) - Reactive Object Pool (from https://github.com/reactor/reactor-pool) - Reactive Streams Netty driver (from https://github.com/reactor/reactor-netty) - Retrofit (from ) @@ -437,9 +454,12 @@ The following software have components provided under the terms of this license: - Spring Context (from https://github.com/spring-projects/spring-framework) - Spring Core (from https://github.com/spring-projects/spring-framework) - Spring Expression Language (SpEL) (from https://github.com/spring-projects/spring-framework) +- Spring JMS (from https://github.com/spring-projects/spring-framework) +- Spring Messaging (from https://github.com/spring-projects/spring-framework) - Spring Plugin - Core (from ) - Spring Plugin - Metadata Extension (from ) - Spring TestContext Framework (from https://github.com/spring-projects/spring-framework) +- Spring Transaction (from https://github.com/spring-projects/spring-framework) - Spring Web (from https://github.com/spring-projects/spring-framework) - Spring Web MVC (from https://github.com/spring-projects/spring-framework) - T-Digest (from https://github.com/tdunning/t-digest) @@ -472,8 +492,11 @@ The following software have components provided under the terms of this license: - io.grpc:grpc-protobuf-lite (from https://github.com/grpc/grpc-java) - io.grpc:grpc-stub (from https://github.com/grpc/grpc-java) - ion-java (from https://github.com/amznlabs/ion-java/) +- ion-java (from https://github.com/amznlabs/ion-java/) - jackson-databind (from http://github.com/FasterXML/jackson) - jackson-databind (from http://github.com/FasterXML/jackson) +- java-cloudant (from https://cloudant.com) +- java-cloudant (from https://cloudant.com) - javax.inject (from http://code.google.com/p/atinject/) - javax.ws.rs-api (from http://jax-rs-spec.java.net) - jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet) @@ -502,6 +525,7 @@ The following software have components provided under the terms of this license: - powermock-reflect (from ) - proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging) - proton-j (from ) +- proton-j (from ) - rank-eval (from https://github.com/elastic/elasticsearch) - resilience4j (from https://github.com/resilience4j/resilience4j) - resilience4j (from https://github.com/resilience4j/resilience4j) @@ -516,6 +540,7 @@ The following software have components provided under the terms of this license: - spring-security-oauth2-client (from http://spring.io/spring-security) - spring-security-oauth2-core (from http://spring.io/spring-security) - spring-security-oauth2-jose (from http://spring.io/spring-security) +- spring-security-oauth2-resource-server (from http://spring.io/spring-security) - spring-security-test (from http://spring.io/spring-security) - spring-security-web (from http://spring.io/spring-security) - springfox-core (from https://github.com/springfox/springfox) @@ -569,6 +594,7 @@ The following software have components provided under the terms of this license: - ASM library repackaged as OSGi bundle (from ) - Apache Commons Codec (from http://commons.apache.org/proper/commons-codec/) - Apache Commons Codec (from http://commons.apache.org/proper/commons-codec/) +- Apache Groovy (from http://groovy-lang.org) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) @@ -808,6 +834,7 @@ The following software have components provided under the terms of this license: - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) - Logback Classic Module (from ) - Logback Core Module (from ) - Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java) @@ -823,6 +850,7 @@ The following software have components provided under the terms of this license: - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) +- Javassist (from http://www.javassist.org/) - SnakeYAML (from http://www.snakeyaml.org) ======================================================================== @@ -869,9 +897,9 @@ The following software have components provided under the terms of this license: - Microsoft Azure client library for Identity (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure client library for KeyVault Secrets (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure common module for Storage (from https://github.com/Azure/azure-sdk-for-java) -- Mockito (from http://www.mockito.org) - Mockito (from http://mockito.org) - Mockito (from http://mockito.org) +- Mockito (from http://www.mockito.org) - Netty/Codec/HTTP (from ) - Netty/Common (from ) - Plexus :: Default Container (from ) @@ -889,12 +917,14 @@ The following software have components provided under the terms of this license: - Cobertura code coverage (from http://cobertura.sourceforge.net) - Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) ======================================================================== MPL-2.0 ======================================================================== The following software have components provided under the terms of this license: +- Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) ======================================================================== @@ -949,6 +979,8 @@ public-domain The following software have components provided under the terms of this license: - AWS SDK for Java - Models (from https://aws.amazon.com/sdkforjava) +- Apache Groovy (from http://groovy-lang.org) +- Apache Groovy (from http://groovy-lang.org) - Asynchronous Http Client (from ) - Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) - Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) diff --git a/README.md b/README.md index 32f87cd8263769150e1ef5404d77e0c230d52ddf..4faa9e0d0def11927898a4277cd957902d3969ee 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,14 @@ The steps for running `os-legal-azure` can be found in the [Azure Implementation <!-- This should be replaced with a link to AWS specific docs --> -## os-legal-gcp +# os-legal-gcp -<!-- This should be replaced with a link to GCP specific docs --> +## Running integration tests +Integration tests are located in a separate project for each cloud in the ```testing``` directory under the project root directory. + +### GCP + +Instructions for running the GCP integration tests can be found [here](./provider/legal-gcp/README.md). ## License Copyright 2017-2019, Schlumberger diff --git a/devops/azure/chart/helm-config.yaml b/devops/azure/chart/helm-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d64f75442b0646538049408e281cef7aababb7d7 --- /dev/null +++ b/devops/azure/chart/helm-config.yaml @@ -0,0 +1,14 @@ +# This file contains the essential configs for the osdu on azure helm chart +global: + + # Service(s) Replica Count + replicaCount: 2 + +################################################################################ +# Specify the Gitlab branch being used for image creation +# ie: community.opengroup.org:5555/osdu/platform/security-and-compliance/legal/{{ .Values.global.branch }}/legal:latest +# +image: + repository: #{container-registry}#.azurecr.io + branch: #{ENVIRONMENT_NAME}# + tag: #{Build.SourceVersion}# diff --git a/devops/azure/chart/templates/deployment.yaml b/devops/azure/chart/templates/deployment.yaml index e91ce1e02c67acc72b1183660b5bd52c9bc3aae5..089df6936f1176a0619ca04991d212e5e0e26751 100644 --- a/devops/azure/chart/templates/deployment.yaml +++ b/devops/azure/chart/templates/deployment.yaml @@ -66,42 +66,28 @@ spec: - name: AZURE_CLIENT_ID valueFrom: secretKeyRef: - name: clientid - key: clientid + name: active-directory + key: principal-clientid - name: AZURE_CLIENT_SECRET valueFrom: secretKeyRef: - name: clientpassword - key: clientpassword + name: active-directory + key: principal-clientpassword - name: AZURE_TENANT_ID valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_TENANT_ID + secretKeyRef: + name: active-directory + key: tenantid - name: aad_client_id valueFrom: secretKeyRef: - name: appid - key: appid + name: active-directory + key: application-appid - name: appinsights_key valueFrom: secretKeyRef: - name: appinsights + name: central-logging key: appinsights - - name: servicebus_namespace_name - valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_SERVICEBUS_NAMESPACE - - name: storage_account - valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_STORAGE_ACCOUNT - - name: azure_activedirectory_session_stateless - value: "true" - - name: azure_activedirectory_AppIdUri - value: "api://$(aad_client_id)" - name: cosmosdb_database value: osdu-db - name: LOG_PREFIX @@ -118,3 +104,9 @@ spec: value: http://entitlements-azure/entitlements/v1 - name: entitlements_service_api_key value: "OBSOLETE" + - name: partition_service_endpoint + value: http://partition/api/partition/v1 + - name: azure_istioauth_enabled + value: "true" + - name: azure_activedirectory_AppIdUri + value: "api://$(aad_client_id)" diff --git a/devops/azure/development-pipeline.yml b/devops/azure/development-pipeline.yml new file mode 100644 index 0000000000000000000000000000000000000000..873fc98e8b9d3d17a702206d640b42377edef7d9 --- /dev/null +++ b/devops/azure/development-pipeline.yml @@ -0,0 +1,82 @@ +# Copyright © Microsoft Corporation +# +# 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. + +trigger: + batch: true + branches: + include: + - master + paths: + exclude: + - /**/*.md + - .gitignore + - /docs + - /provider/legal-aws + - /provider/legal-byoc + - /provider/legal-gcp + - /provider/legal-ibm + +resources: + repositories: + - repository: FluxRepo + type: git + name: k8-gitops-manifests + - repository: TemplateRepo + type: git + name: infra-azure-provisioning + +variables: + - group: 'Azure - OSDU' + - group: 'Azure - OSDU Secrets' + + - name: serviceName + value: "legal" + - name: chartPath + value: "devops/azure/chart" + - name: valuesFile + value: "devops/azure/chart/helm-config.yaml" + - name: 'MANIFEST_REPO' + value: $[ resources.repositories['FluxRepo'].name ] + - name: SKIP_TESTS + value: 'false' + +stages: + - template: /devops/build-stage.yml@TemplateRepo + parameters: + mavenGoal: 'package' + mavenPublishJUnitResults: true + serviceCoreMavenOptions: '-P legal-core' + mavenOptions: '-P legal-azure' + copyFileContents: | + pom.xml + provider/legal-azure/maven/settings.xml + provider/legal-azure/pom.xml + provider/legal-azure/target/*-spring-boot.jar + copyFileContentsToFlatten: '' + mavenSettingsFile: './maven/settings.xml' + serviceBase: ${{ variables.serviceName }} + testingRootFolder: 'testing' + chartPath: ${{ variables.chartPath }} + - template: /devops/deploy-stages.yml@TemplateRepo + parameters: + serviceName: ${{ variables.serviceName }} + chartPath: ${{ variables.chartPath }} + valuesFile: ${{ variables.valuesFile }} + testCoreMavenPomFile: 'testing/legal-test-core/pom.xml' + testCoreMavenOptions: '--settings $(System.DefaultWorkingDirectory)/drop/deploy/testing/maven/settings.xml' + skipDeploy: ${{ variables.SKIP_DEPLOY }} + skipTest: ${{ variables.SKIP_TESTS }} + providers: + - name: Azure + environments: ['dev'] diff --git a/devops/azure/pipeline.yml b/devops/azure/pipeline.yml new file mode 100644 index 0000000000000000000000000000000000000000..f38616fd18d8acf14e6489dd1b3aff42099defcb --- /dev/null +++ b/devops/azure/pipeline.yml @@ -0,0 +1,82 @@ +# Copyright © Microsoft Corporation +# +# 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. + +trigger: + batch: true + branches: + include: + - master + paths: + exclude: + - /**/*.md + - .gitignore + - /docs + - /provider/legal-aws + - /provider/legal-byoc + - /provider/legal-gcp + - /provider/legal-ibm + +resources: + repositories: + - repository: FluxRepo + type: git + name: k8-gitops-manifests + - repository: TemplateRepo + type: git + name: infra-azure-provisioning + +variables: + - group: 'Azure - OSDU' + - group: 'Azure - OSDU Secrets' + + - name: serviceName + value: "legal" + - name: chartPath + value: "devops/azure/chart" + - name: valuesFile + value: "devops/azure/chart/helm-config.yaml" + - name: 'MANIFEST_REPO' + value: $[ resources.repositories['FluxRepo'].name ] + - name: SKIP_TESTS + value: 'false' + +stages: + - template: /devops/build-stage.yml@TemplateRepo + parameters: + mavenGoal: 'package' + mavenPublishJUnitResults: true + serviceCoreMavenOptions: '-P legal-core' + mavenOptions: '-P legal-azure' + copyFileContents: | + pom.xml + provider/legal-azure/maven/settings.xml + provider/legal-azure/pom.xml + provider/legal-azure/target/*-spring-boot.jar + copyFileContentsToFlatten: '' + mavenSettingsFile: './maven/settings.xml' + serviceBase: ${{ variables.serviceName }} + testingRootFolder: 'testing' + chartPath: ${{ variables.chartPath }} + - template: /devops/deploy-stages.yml@TemplateRepo + parameters: + serviceName: ${{ variables.serviceName }} + chartPath: ${{ variables.chartPath }} + valuesFile: ${{ variables.valuesFile }} + testCoreMavenPomFile: 'testing/legal-test-core/pom.xml' + testCoreMavenOptions: '--settings $(System.DefaultWorkingDirectory)/drop/deploy/testing/maven/settings.xml' + skipDeploy: ${{ variables.SKIP_DEPLOY }} + skipTest: ${{ variables.SKIP_TESTS }} + providers: + - name: Azure + environments: ['demo'] diff --git a/devops/azure/release.yaml b/devops/azure/release.yaml index 072fc703aa3a5aeafa81a32d8b77f22e8240220b..9fdf00b7209e09f87c86f86155168735598f80fb 100644 --- a/devops/azure/release.yaml +++ b/devops/azure/release.yaml @@ -17,7 +17,7 @@ apiVersion: v1 kind: Service metadata: - name: osdu-gitlab-legal + name: legal namespace: osdu spec: type: ClusterIP @@ -26,7 +26,7 @@ spec: port: 80 targetPort: 80 selector: - app: osdu-gitlab-legal + app: legal --- # Source: legal/templates/deployment.yaml # Copyright © Microsoft Corporation @@ -49,14 +49,14 @@ metadata: name: osdu-gitlab-legal namespace: osdu spec: - replicas: 1 + replicas: 2 selector: matchLabels: - app: osdu-gitlab-legal + app: legal template: metadata: labels: - app: osdu-gitlab-legal + app: legal aadpodidbinding: osdu-identity spec: volumes: @@ -67,14 +67,14 @@ spec: volumeAttributes: secretProviderClass: azure-keyvault containers: - - name: osdu-gitlab-legal - image: community.opengroup.org:5555/osdu/platform/security-and-compliance/legal/legal-master:latest + - name: legal + image: community.opengroup.org:5555/osdu/platform/security-and-compliance/legal/legal-trusted-partition-svc imagePullPolicy: Always ports: - containerPort: 80 readinessProbe: httpGet: - path: /entitlements/v1/swagger-ui.html + path: /api/legal/v1/swagger-ui.html port: 80 volumeMounts: - name: azure-keyvault @@ -97,42 +97,28 @@ spec: - name: AZURE_CLIENT_ID valueFrom: secretKeyRef: - name: clientid - key: clientid + name: active-directory + key: principal-clientid - name: AZURE_CLIENT_SECRET valueFrom: secretKeyRef: - name: clientpassword - key: clientpassword + name: active-directory + key: principal-clientpassword - name: AZURE_TENANT_ID valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_TENANT_ID + secretKeyRef: + name: active-directory + key: tenantid - name: aad_client_id valueFrom: secretKeyRef: - name: appid - key: appid + name: active-directory + key: application-appid - name: appinsights_key valueFrom: secretKeyRef: - name: appinsights + name: central-logging key: appinsights - - name: servicebus_namespace_name - valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_SERVICEBUS_NAMESPACE - - name: storage_account - valueFrom: - configMapKeyRef: - name: osdu-svc-properties - key: ENV_STORAGE_ACCOUNT - - name: azure_activedirectory_session_stateless - value: "true" - - name: azure_activedirectory_AppIdUri - value: "api://$(aad_client_id)" - name: cosmosdb_database value: osdu-db - name: LOG_PREFIX @@ -149,3 +135,12 @@ spec: value: http://entitlements-azure/entitlements/v1 - name: entitlements_service_api_key value: "OBSOLETE" + - name: partition_service_endpoint + value: http://partition/api/partition/v1 + # If Istio is enabled L#126 is true and L# 127-130 removed + - name: azure_istioauth_enabled + value: "false" + - name: azure_activedirectory_session_stateless + value: "true" + - name: azure_activedirectory_AppIdUri + value: "api://$(aad_client_id)" diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/api/LegalTagApi.java b/legal-core/src/main/java/org/opengroup/osdu/legal/api/LegalTagApi.java index f78078a8db8184d95b28dc947367ac1cd46608fb..293aa55ee9fe0f20b0570e145be9a8708bc1a1e6 100644 --- a/legal-core/src/main/java/org/opengroup/osdu/legal/api/LegalTagApi.java +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/api/LegalTagApi.java @@ -1,6 +1,7 @@ package org.opengroup.osdu.legal.api; import com.google.gson.Gson; +import java.util.Collections; import org.opengroup.osdu.legal.countries.LegalTagCountriesService; import org.opengroup.osdu.legal.logging.AuditLogger; import org.opengroup.osdu.legal.tags.LegalTagService; @@ -137,7 +138,7 @@ public class LegalTagApi { output.setPersonalDataTypes(allowedLegaltagPropertyValues.getPersonalDataType()); output.setSecurityClassifications(allowedLegaltagPropertyValues.getSecurityClassifications()); output.setDataTypes(allowedLegaltagPropertyValues.getDataTypes()); - auditLogger.readLegalPropertiesSuccess(); + auditLogger.readLegalPropertiesSuccess(Collections.singletonList(output.toString())); return new ResponseEntity<ReadablePropertyValues>(output, HttpStatus.OK); } diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditEvents.java b/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditEvents.java index fc00f8beedb34fed1351e3919696272c8033b09a..7331668c656e11ee91ea323933a5172e129c42f4 100644 --- a/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditEvents.java +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditEvents.java @@ -82,25 +82,25 @@ public class AuditEvents { .build(); } - public AuditPayload getReadLegalPropertiesEventSuccess() { + public AuditPayload getReadLegalPropertiesEventSuccess(List<String> resources) { return AuditPayload.builder() .action(AuditAction.READ) .status(AuditStatus.SUCCESS) .user(this.user) .actionId(READ_ACTION_ID) .message(READ_MESSAGE_SUCCESS) - .resources(singletonList(PROPERTY_VALUE)) + .resources(resources) .build(); } - public AuditPayload getReadLegalPropertiesEventFail() { + public AuditPayload getReadLegalPropertiesEventFail(List<String> resources) { return AuditPayload.builder() .action(AuditAction.READ) .status(AuditStatus.FAILURE) .user(this.user) .actionId(READ_ACTION_ID) .message(READ_MESSAGE_FAILURE) - .resources(singletonList(PROPERTY_VALUE)) + .resources(resources) .build(); } diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditLogger.java b/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditLogger.java index 8df60fb121d2ebd8211bc62d91eb717c3f6bdb2b..939b2cdd614a354ba70003a200c38c39d0ade8b9 100644 --- a/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditLogger.java +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/logging/AuditLogger.java @@ -63,12 +63,12 @@ public class AuditLogger { this.writeLog(this.getEvents().getLegalTagStatusJobEventFail(resources)); } - public void readLegalPropertiesSuccess() { - this.writeLog(this.getEvents().getReadLegalPropertiesEventSuccess()); + public void readLegalPropertiesSuccess(List<String> resources) { + this.writeLog(this.getEvents().getReadLegalPropertiesEventSuccess(resources)); } - public void readLegalPropertiesFail() { - this.writeLog(this.getEvents().getReadLegalPropertiesEventFail()); + public void readLegalPropertiesFail(List<String> resources) { + this.writeLog(this.getEvents().getReadLegalPropertiesEventFail(resources)); } public void validateLegalTagSuccess() { diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalExceptionMapper.java b/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalExceptionMapper.java index eef26642158be23a7b095a98ce824ede5b3b8307..2730e644394f91d2bcb1557fb815d18596103fbf 100644 --- a/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalExceptionMapper.java +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalExceptionMapper.java @@ -14,20 +14,21 @@ package org.opengroup.osdu.legal.middleware; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; - +import javassist.NotFoundException; +import javax.inject.Inject; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; import javax.validation.ValidationException; -import javax.inject.Inject; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; - -import com.google.gson.Gson; -import javassist.NotFoundException; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.http.HttpHeaders; @@ -36,21 +37,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.lang.NonNull; import org.springframework.security.access.AccessDeniedException; import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import org.opengroup.osdu.core.common.model.http.AppException; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; - @Order(Ordered.HIGHEST_PRECEDENCE) -@ControllerAdvice -@RestController +@RestControllerAdvice public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { private static final Gson gson = new Gson(); @@ -74,7 +68,7 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { return this.getErrorResponse( new AppException(HttpStatus.BAD_REQUEST.value(), "Bad JSON format", e.getMessage())); } - + @ExceptionHandler(UnrecognizedPropertyException.class) protected ResponseEntity<Object> handleValidationException(UnrecognizedPropertyException e) { return this.getErrorResponse( @@ -124,13 +118,24 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(@NonNull HttpRequestMethodNotSupportedException e, @NonNull HttpHeaders headers, @NonNull HttpStatus status, - @NonNull WebRequest request) { - return this.getErrorResponse( + @NonNull WebRequest request) { + return this.getErrorResponse( new AppException(HttpStatus.METHOD_NOT_ALLOWED.value(), "Method not found.", "Method not found.", e)); } - private ResponseEntity<Object> getErrorResponse(AppException e) { + @Override + @NonNull + protected ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull MethodArgumentNotValidException e, + @NonNull HttpHeaders headers, + @NonNull HttpStatus status, + @NonNull WebRequest request) { + return this.getErrorResponse( + new AppException(HttpStatus.BAD_REQUEST.value(), "Validation failed.", + "Validation failed.", e)); + } + + public ResponseEntity<Object> getErrorResponse(AppException e) { String exceptionMsg = e.getError().getMessage(); @@ -140,6 +145,6 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { this.logger.warning(exceptionMsg, e); } - return new ResponseEntity<Object>(gson.toJson(exceptionMsg), HttpStatus.resolve(e.getError().getCode())); + return new ResponseEntity<Object>(gson.toJson(exceptionMsg),HttpStatus.resolve(e.getError().getCode())); } } \ No newline at end of file diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalOtherExceptionMapper.java b/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalOtherExceptionMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..ae763156fbbc750e7547daadecaf8fae7a45f5d9 --- /dev/null +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/middleware/GlobalOtherExceptionMapper.java @@ -0,0 +1,39 @@ +// Copyright 2017-2020, Schlumberger +// +// 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.legal.middleware; + +import org.opengroup.osdu.core.common.model.http.AppException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalOtherExceptionMapper { + + private GlobalExceptionMapper mapper; + + public GlobalOtherExceptionMapper(GlobalExceptionMapper mapper) { + this.mapper = mapper; + } + + @ExceptionHandler(Exception.class) + protected ResponseEntity<Object> handleGeneralException(Exception e) { + return mapper.getErrorResponse( + new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error.", + "An unknown error has occurred.", e)); + } + +} diff --git a/legal-core/src/test/java/org/opengroup/osdu/legal/api/LegalTagApiTests.java b/legal-core/src/test/java/org/opengroup/osdu/legal/api/LegalTagApiTests.java index a62d12e014ef4f0433afb7f35e7cfc3bf048cc3b..1d48b35939cbe10205d3ccedb952a77c1fab80ea 100644 --- a/legal-core/src/test/java/org/opengroup/osdu/legal/api/LegalTagApiTests.java +++ b/legal-core/src/test/java/org/opengroup/osdu/legal/api/LegalTagApiTests.java @@ -268,6 +268,6 @@ public class LegalTagApiTests { public void shouldCreateAuditLogs_when_getLegalTagProperties() { sut.getLegalTagProperties(); - verify(auditLogger).readLegalPropertiesSuccess(); + verify(auditLogger).readLegalPropertiesSuccess(any()); } } diff --git a/legal-core/src/test/java/org/opengroup/osdu/legal/logging/AuditLoggerTests.java b/legal-core/src/test/java/org/opengroup/osdu/legal/logging/AuditLoggerTests.java index aba5c74aa429660f0638161c58ba2dc8a69ea7d3..5d5220ea63cd65f4f5fb707d8ea5b30a886f70bd 100644 --- a/legal-core/src/test/java/org/opengroup/osdu/legal/logging/AuditLoggerTests.java +++ b/legal-core/src/test/java/org/opengroup/osdu/legal/logging/AuditLoggerTests.java @@ -67,13 +67,13 @@ public class AuditLoggerTests { @Test public void should_writeLegalTagReadPropertiesSuccessEvent(){ - sut.readLegalPropertiesSuccess(); + sut.readLegalPropertiesSuccess(any()); verify(log).audit(any()); } @Test public void should_writeLegalTagReadPropertiesFailEvent(){ - sut.readLegalPropertiesFail(); + sut.readLegalPropertiesFail(any()); verify(log).audit(any()); } diff --git a/provider/legal-azure/README.md b/provider/legal-azure/README.md index 9154f0013c4d45c8821c75ef7c3673b6668fdb35..7275ad11bb0833f491add5cb302457e6b91d7953 100644 --- a/provider/legal-azure/README.md +++ b/provider/legal-azure/README.md @@ -44,22 +44,23 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA | `legal_service_region` | `us` | Legal service region | no | - | | `entitlements_service_endpoint` | ex `https://foo-entitlements.azurewebsites.net` | Entitlements API endpoint | no | output of infrastructure deployment | | `entitlements_service_api_key` | `********` | The API key clients will need to use when calling the service | yes | -- | +| `partition_service_endpoint` | ex `https://foo-partition.azurewebsites.net` | Partition Service API endpoint | no | output of infrastructure deployment | +| `azure.activedirectory.app-resource-id` | `********` | AAD client application ID | yes | output of infrastructure deployment | | `LEGAL_HOSTNAME` | `notused` | Possibly unused | no | - | | `CRON_JOB_IP` | `10.0.0.1` | Possibly unused | no | - | | `azure.activedirectory.session-stateless` | `true` | Flag run in stateless mode (needed by AAD dependency) | no | -- | | `aad_client_id` | `********` | AAD client application ID | yes | output of infrastructure deployment | | `azure.activedirectory.AppIdUri` | `api://${azure.activedirectory.client-id}` | URI for AAD Application | no | -- | | `cosmosdb_database` | ex `dev-osdu-r2-db` | Cosmos database for legal documents | no | output of infrastructure deployment | -| `storage_account` | ex `devintosdur2storage` | Storage account for legal documents | no | output of infrastructure deployment | | `azure.storage.container-name` | ex `legal-service-azure-configuration` | Storage container for legal documents | no | output of infrastructure deployment | | `azure.storage.enable-https` | `true` | Spring configuration for Azure Storage | no | - | | `servicebus_topic_name` | `legaltags` | Topic for async messaging | no | output of infrastructure deployment | -| `servicebus_namespace_name` | ex `foo-sb-namespace` | Namespace for async messaging | no | output of infrastructure deployment | | `KEYVAULT_URI` | ex `https://foo-keyvault.vault.azure.net/` | URI of KeyVault that holds application secrets | no | output of infrastructure deployment | | `AZURE_CLIENT_ID` | `********` | Identity to run the service locally. This enables access to Azure resources. You only need this if running locally | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-username` | | `AZURE_TENANT_ID` | `********` | AD tenant to authenticate users from | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-tenant-id` | | `AZURE_CLIENT_SECRET` | `********` | Secret for `$AZURE_CLIENT_ID` | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-password` | | `appinsights_key` | `********` | API Key for App Insights | yes | output of infrastructure deployment | +| `azure_istioauth_enabled` | `true` | Flag to Disable AAD auth | no | -- | **Required to run integration tests** @@ -89,27 +90,6 @@ Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b0 ... ``` -You may need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`: -```bash -$ cat ~/.m2/settings.xml -<?xml version="1.0" encoding="UTF-8"?> -<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"> - <servers> - <server> - <id>os-core</id> - <username>mvn-pat</username> - <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. --> - <!-- The generated token expires on or before 11/14/2019 --> - <password>$PERSONAL_ACCESS_TOKEN_GOES_HERE</password> - </server> - </servers> -</settings> -``` - -_A settings file is also conveniently located in ./.mvn/community-maven.settings.xml which is also used for CI/CD processes._ - ### Build and run the application After configuring your environment as specified above, you can follow these steps to build and run the application. These steps should be invoked from the *repository root.* diff --git a/provider/legal-azure/pom.xml b/provider/legal-azure/pom.xml index 462ae48f8d755dcb76f612c69670a6ca571b0759..b87a229855593f18dc3c8f12082289d0617d802c 100644 --- a/provider/legal-azure/pom.xml +++ b/provider/legal-azure/pom.xml @@ -40,6 +40,21 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-common</artifactId> + <version>0.3.12</version> + <exclusions> + <exclusion> + <groupId>org.elasticsearch</groupId> + <artifactId>elasticsearch</artifactId> + </exclusion> + <exclusion> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-client</artifactId> + </exclusion> + <exclusion> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.opengroup.osdu.legal</groupId> @@ -88,7 +103,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>core-lib-azure</artifactId> - <version>0.0.11</version> + <version>0.0.33</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> @@ -193,6 +208,25 @@ </deployment> </configuration> </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.3</version> + <executions> + <execution> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>report</id> + <phase>prepare-package</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> </project> diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/countries/StorageReaderFactoryImpl.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/countries/StorageReaderFactoryImpl.java index b46462dc1291cdf11a6790ef2f6bb0e723eee283..64ecb945c5c135a6a43de55fda48558a6349891b 100644 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/countries/StorageReaderFactoryImpl.java +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/countries/StorageReaderFactoryImpl.java @@ -15,8 +15,10 @@ package org.opengroup.osdu.legal.azure.countries; import javax.inject.Inject; +import javax.inject.Named; -import com.azure.storage.blob.BlobContainerClient; +import org.opengroup.osdu.azure.blobstorage.IBlobContainerClientFactory; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; @@ -27,13 +29,20 @@ import org.springframework.stereotype.Component; public class StorageReaderFactoryImpl implements IStorageReaderFactory { @Inject - private BlobContainerClient blobContainerClient; + private IBlobContainerClientFactory blobContainerClientFactory; + + @Inject + private DpsHeaders headers; + + @Inject + @Named("STORAGE_CONTAINER_NAME") + private String containerName; @Inject private JaxRsDpsLog logger; @Override public IStorageReader getReader(TenantInfo tenant, String projectRegion) { - return new StorageReaderImpl(tenant, projectRegion, blobContainerClient, logger); + return new StorageReaderImpl(tenant, projectRegion, blobContainerClientFactory.getClient(headers.getPartitionId(), containerName), logger); } } diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/AzureBootstrapConfig.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/AzureBootstrapConfig.java index d5471859361d177826e304c3b0e55d038e018eb0..c87b4be82ce11d81bf3f496987387157e081a37a 100644 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/AzureBootstrapConfig.java +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/AzureBootstrapConfig.java @@ -14,8 +14,6 @@ package org.opengroup.osdu.legal.azure.di; -import com.azure.security.keyvault.secrets.SecretClient; -import org.opengroup.osdu.azure.KeyVaultFacade; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @@ -25,21 +23,12 @@ import javax.inject.Named; @Component public class AzureBootstrapConfig { - @Value("${azure.storage.account-name}") - private String storageAccount; - @Value("${azure.storage.container-name}") private String storageContainer; @Value("${azure.servicebus.topic-name}") private String serviceBusTopic; - @Value("${azure.servicebus.namespace-name}") - private String serviceBusNamespace; - - @Value("${azure.cosmosdb.tenant.collection}") - private String tenantCollectionName; - @Value("${azure.cosmosdb.legal.collection}") private String legalCollectionName; @@ -49,24 +38,12 @@ public class AzureBootstrapConfig { @Value("${azure.cosmosdb.database}") private String cosmosDBName; - @Bean - @Named("STORAGE_ACCOUNT_NAME") - public String storageAccount() { - return storageAccount; - } - @Bean @Named("STORAGE_CONTAINER_NAME") public String containerName() { return storageContainer; } - @Bean - @Named("SERVICE_BUS_NAMESPACE") - public String serviceBusNamespace() { - return serviceBusNamespace; - } - @Bean @Named("SERVICE_BUS_TOPIC") public String serviceBusTopic() { @@ -79,30 +56,13 @@ public class AzureBootstrapConfig { return keyVaultURL; } - @Bean - @Named("COSMOS_ENDPOINT") - public String cosmosEndpoint(SecretClient kv) { - return KeyVaultFacade.getSecretWithValidation(kv, "cosmos-endpoint"); - } - - @Bean - @Named("COSMOS_KEY") - public String cosmosKey(SecretClient kv) { - return KeyVaultFacade.getSecretWithValidation(kv, "cosmos-primary-key"); - } - @Bean public String cosmosDBName() { return cosmosDBName; } @Bean - public String legalTagsContainer(){ + public String legalTagsContainer() { return legalCollectionName; } - - @Bean - public String tenantInfoContainer(){ - return tenantCollectionName; - } } \ No newline at end of file diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantFactoryImpl.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantFactoryImpl.java deleted file mode 100644 index 34a88b0e0ff467c49a0475c69d21e8910b67a2d6..0000000000000000000000000000000000000000 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantFactoryImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © Microsoft Corporation -// -// 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.legal.azure.di; - -import org.opengroup.osdu.azure.CosmosStore; -import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -@Component -public class TenantFactoryImpl implements ITenantFactory { - - @Autowired - private CosmosStore cosmosStore; - - @Autowired - private String tenantInfoContainer; - - @Autowired - private String cosmosDBName; - - @Autowired - private DpsHeaders headers; - - private Map<String, TenantInfo> tenants; - - public boolean exists(String tenantName) - { - if (this.tenants == null) - initTenants(); - return this.tenants.containsKey(tenantName); - } - - public TenantInfo getTenantInfo(String tenantName) { - if (this.tenants == null) - initTenants(); - return this.tenants.get(tenantName); - } - - public Collection<TenantInfo> listTenantInfo() { - if (this.tenants == null) - initTenants(); - return this.tenants.values(); - } - - public <V> ICache<String, V> createCache(String tenantName, String host, int port, int expireTimeSeconds, Class<V> classOfV) - { - return null; - } - - public void flushCache() {} - - private void initTenants() { - this.tenants = new HashMap<>(); - cosmosStore.findAllItems(headers.getPartitionId(), cosmosDBName, tenantInfoContainer, TenantInfoDoc.class).forEach(doc -> { - TenantInfo ti = new TenantInfo(); - String tenantName = doc.getId(); - ti.setName(tenantName); - String complianceRuleSet = doc.getComplianceRuleSet(); - ti.setComplianceRuleSet(complianceRuleSet); - this.tenants.put(tenantName, ti) ; - }); - } - -} diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantInfoDoc.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantInfoDoc.java deleted file mode 100644 index 30145e260f1dc63c1381f43717c43db09740ebb8..0000000000000000000000000000000000000000 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/di/TenantInfoDoc.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright © Microsoft Corporation -// -// 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.legal.azure.di; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class TenantInfoDoc { - private String id; - private String complianceRuleSet; -} diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImpl.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImpl.java index 7f6efd53ee5ab3876e509a9502a6b34223874e05..013410b5aa680ae254ea9aa268f9f179fce98e2e 100644 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImpl.java +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImpl.java @@ -17,15 +17,16 @@ package org.opengroup.osdu.legal.azure.jobs; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.microsoft.azure.servicebus.Message; -import com.microsoft.azure.servicebus.TopicClient; import lombok.NoArgsConstructor; +import org.opengroup.osdu.azure.servicebus.ITopicClientFactory; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.legal.StatusChangedTags; import org.opengroup.osdu.legal.provider.interfaces.ILegalTagPublisher; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.inject.Inject; +import javax.inject.Named; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -33,12 +34,17 @@ import java.util.Map; @NoArgsConstructor @Component public class LegalTagPublisherImpl implements ILegalTagPublisher { - @Autowired - private TopicClient topicClient; - @Autowired + @Inject + private ITopicClientFactory topicClientFactory; + + @Inject private JaxRsDpsLog logger; + @Inject + @Named("SERVICE_BUS_TOPIC") + private String serviceBusTopic; + @Override public void publish(String projectId, DpsHeaders headers, StatusChangedTags tags) throws Exception { Gson gson = new Gson(); @@ -69,10 +75,8 @@ public class LegalTagPublisherImpl implements ILegalTagPublisher { try { logger.info("Storage publishes message " + headers.getCorrelationId()); - topicClient.send(message); - } - catch (Exception e) - { + topicClientFactory.getClient(headers.getPartitionId(), serviceBusTopic).send(message); + } catch (Exception e) { logger.error(e.getMessage(), e); } } diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AADSecurityConfig.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AADSecurityConfig.java index 1c96f3deff490025c1e2ddc8c8e8575d9ebb2882..cd284dfe01d92b24c5d040c1d90b8297d06975f7 100644 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AADSecurityConfig.java +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AADSecurityConfig.java @@ -15,18 +15,22 @@ package org.opengroup.osdu.legal.azure.security; import com.microsoft.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 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; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.parameters.P; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import javax.inject.Inject; @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) +@ConditionalOnProperty(value = "azure.istio.auth.enabled", havingValue = "false", matchIfMissing = false) public class AADSecurityConfig extends WebSecurityConfigurerAdapter { + @Inject private AADAppRoleStatelessAuthenticationFilter appRoleAuthFilter; diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AzureIstioSecurityConfig.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AzureIstioSecurityConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..2de6575c262f49d71fa75ae25a1466e762275b66 --- /dev/null +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/AzureIstioSecurityConfig.java @@ -0,0 +1,35 @@ +// Copyright © Microsoft Corporation +// +// 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.legal.azure.security; + + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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) +@ConditionalOnProperty(value = "azure.istio.auth.enabled", havingValue = "true", matchIfMissing = true) +public class AzureIstioSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.httpBasic().disable() + .csrf().disable(); //AuthN is disabled. AuthN is handled by sidecar proxy + } +} diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/tags/dataaccess/LegalTagRepositoryImpl.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/tags/dataaccess/LegalTagRepositoryImpl.java index 5391457c1a8443d586e75801b754f1b23890b088..f27dc1bcca0ef9060316f8a69fe9e254d2bc5f42 100644 --- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/tags/dataaccess/LegalTagRepositoryImpl.java +++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/tags/dataaccess/LegalTagRepositoryImpl.java @@ -18,7 +18,7 @@ import com.azure.cosmos.FeedOptions; import com.azure.cosmos.SqlParameter; import com.azure.cosmos.SqlParameterList; import com.azure.cosmos.SqlQuerySpec; -import org.opengroup.osdu.azure.CosmosStore; +import org.opengroup.osdu.azure.cosmosdb.CosmosStore; import org.opengroup.osdu.common.Validators; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.legal.ListLegalTagArgs; diff --git a/provider/legal-azure/src/main/resources/application.properties b/provider/legal-azure/src/main/resources/application.properties index 6744890ff4e6ad7db6ab7973f9ae3d0519cfaf4a..f5ab69d34e0b4ff727b08862b8185c1e18e3e1e6 100644 --- a/provider/legal-azure/src/main/resources/application.properties +++ b/provider/legal-azure/src/main/resources/application.properties @@ -18,27 +18,33 @@ server.servlet.contextPath=/api/legal/v1/ REGION=${legal_service_region} AUTHORIZE_API=${entitlements_service_endpoint} AUTHORIZE_API_KEY=${entitlements_service_api_key} + +# Partition Service configuration +PARTITION_API=${partition_service_endpoint} +azure.activedirectory.app-resource-id=${aad_client_id} + LEGAL_HOSTNAME=notused CRON_JOB_IP=10.0.0.1 -# Azure AD configuration for OpenIDConnect -azure.activedirectory.session-stateless=true -azure.activedirectory.client-id=${aad_client_id} -azure.activedirectory.AppIdUri=api://${azure.activedirectory.client-id} +# Azure AD configuration for OpenIDConnect, commented below settings to disable AAD AuthN , +# Uncomment it In the Istio AUTHN disabled Scenario +#azure.activedirectory.client-id=${aad_client_id} +#azure.activedirectory.AppIdUri=api://${azure.activedirectory.client-id} +#azure.activedirectory.session-stateless=true + +# Istio Auth Enabled +azure.istio.auth.enabled=${azure_istioauth_enabled} # Azure CosmosDB configuration azure.cosmosdb.database=${cosmosdb_database} -azure.cosmosdb.tenant.collection=TenantInfo azure.cosmosdb.legal.collection=LegalTag # Azure Blob Storage configuration -azure.storage.account-name=${storage_account} azure.storage.container-name=legal-service-azure-configuration azure.storage.enable-https=true # Azure Service Bus configuration azure.servicebus.topic-name=${servicebus_topic_name} -azure.servicebus.namespace-name=${servicebus_namespace_name} # Azure KeyVault configuration azure.keyvault.url=${KEYVAULT_URI} @@ -49,4 +55,10 @@ spring.application.name=legal-azure #logging configuration logging.transaction.enabled=true -logging.slf4jlogger.enabled=true \ No newline at end of file +logging.slf4jlogger.enabled=true +logging.mdccontext.enabled=true + +#TenantFactory Configuration +tenantFactoryImpl.required=true +tenantInfo.container.name=TenantInfo + diff --git a/provider/legal-gcp/README.md b/provider/legal-gcp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7e9519743c3def3c63645539c6b7ed7001a7e3af --- /dev/null +++ b/provider/legal-gcp/README.md @@ -0,0 +1,174 @@ +# legal-gcp + +os-legal-gcp is a Spring Boot service that hosts CRUD APIs that enable management of legal tags within the OSDU R2 ecosystem. + +## Getting Started + +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. + +### Prerequisites + +- [Maven 3.6.0+](https://maven.apache.org/download.cgi) +- [AdoptOpenJDK8](https://adoptopenjdk.net/) +- [Lombok 1.16 or later](https://projectlombok.org/setup/maven) +- [GCloud SDK with java (latest version)](https://cloud.google.com/sdk/docs/install) + +### Installation + +- Setup Apache Maven +- Setup AdoptOpenJDK +- Setup GCloud SDK +- Install Eclipse (or other IDE) to run applications +- Set up environment variables for Apache Maven and AdoptOpenJDK. For example M2_HOME, JAVA_HOME, etc. +- Add a configuration for build project in Eclipse(or other IDE) + +### Run Locally + +Check that maven is installed: + +```bash +$ mvn --version +Apache Maven 3.6.0 +Maven home: /usr/share/maven +Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b04/jre +... +``` + +You may need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.mvn/community-maven.settings.xml`: + +```bash +$ cat ~/.m2/settings.xml +<?xml version="1.0" encoding="UTF-8"?> +<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"> + <servers> + <server> + <id>community-maven-via-private-token</id> + <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. --> + <!-- The generated token expires on or before 11/14/2019 --> + <configuration> + <httpHeaders> + <property> + <name>Private-Token</name> + <value>${env.COMMUNITY_MAVEN_TOKEN}</value> + </property> + </httpHeaders> + </configuration> + </server> + </servers> +</settings> +``` + +* Update the Google cloud SDK to the latest version: + +```bash +gcloud components update +``` +* Set Google Project Id: + +```bash +gcloud config set project <YOUR-PROJECT-ID> +``` + +* Perform a basic authentication in the selected project: + +```bash +gcloud auth application-default login +``` + +* Navigate to search service's root folder and run: + +```bash +mvn jetty:run +## Testing +* Navigate to legal service's root folder and run: + +```bash +mvn clean install +``` + +* If you wish to see the coverage report then go to testing/target/site/jacoco-aggregate and open index.html + +* If you wish to build the project without running tests + +```bash +mvn clean install -DskipTests +``` + +After configuring your environment as specified above, you can follow these steps to build and run the application. These steps should be invoked from the *repository root.* + +```bash +cd provider/legal-gcp/ && mvn spring-boot:run +``` + +## Testing + +Navigate to legal service's root folder and run all the tests: + +```bash +# build + install integration test core +$ (cd testing/legal-test-core/ && mvn clean install) +``` + +### Running E2E Tests + +This section describes how to run cloud OSDU E2E tests (testing/legal-test-gcp). + +You will need to have the following environment variables defined. + +| name | value | description | sensitive? | source | +| --- | --- | --- | --- | --- | +| `GCLOUD_PROJECT` | `nice-etching-277309` | google cloud project ID | yes | - | +| `MY_TENANT_PROJECT` | `osdu` | my tenant project name | yes | - | +| `INTEGRATION_TEST_AUDIENCE` | `********` | client application ID | yes | https://console.cloud.google.com/apis/credentials | +| `INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must have entitlements configured already | yes | https://console.cloud.google.com/iam-admin/serviceaccounts | +| `HOST_URL` | `http://localhsot:8080/api/legal/v1/` | - | yes | - | +| `MY_TENANT` | `osdu` | OSDU tenant used for testing | yes | - | +| `SKIP_HTTP_TESTS` | ex `true` | jetty server returns 403 when running locally when deployed jettyserver is not used and the app returns a 302 so just run against deployed version only when checking http -> https redirects. Use 'true' for Google Cloud Run | yes | - | + +**Entitlements configuration for integration accounts** + +| INTEGRATION_TESTER | +| --- | +| users<br/>service.entitlements.user<br/>service.legal.admin<br/>service.legal.editor<br/>service.legal.user<br/>data.test1<br/>data.integration.test | + +Execute following command to build code and run all the integration tests: + +```bash +# Note: this assumes that the environment variables for integration tests as outlined +# above are already exported in your environment. +$ (cd testing/legal-test-gcp/ && mvn clean test) +``` + +## Deployment + +* Data-Lake Legal Google Cloud Endpoints on App Engine Flex environment + * Deploy + ```sh + mvn appengine:deploy -pl org.opengroup.osdu.legal:legal -amd + ``` + + * If you wish to deploy the search service without running tests + ```sh + mvn appengine:deploy -pl org.opengroup.osdu.legal:legal -amd -DskipTests + ``` + +or +* Google Documentation: https://cloud.google.com/cloud-build/docs/deploying-builds/deploy-appengine + +## Licence +Copyright © Google LLC +Copyright © EPAM Systems + +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](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. \ No newline at end of file diff --git a/provider/legal-gcp/pom.xml b/provider/legal-gcp/pom.xml index 05a0b9e363ec560eb442ff8d8813c2e280dec924..e48735275c9c5070c445889e0037a49bf205ed64 100644 --- a/provider/legal-gcp/pom.xml +++ b/provider/legal-gcp/pom.xml @@ -233,7 +233,26 @@ <configuration> <version>1</version> </configuration> - </plugin> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.7.201606060606</version> + <executions> + <execution> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>report</id> + <phase>prepare-package</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> </project> diff --git a/provider/legal-gcp/src/main/appengine/app.yaml b/provider/legal-gcp/src/main/appengine/app.yaml index 22df4b203c8223c9df742668103c62e06b91e923..6be9a6e8ed966b9dfda935b84ab69318fc502fa9 100644 --- a/provider/legal-gcp/src/main/appengine/app.yaml +++ b/provider/legal-gcp/src/main/appengine/app.yaml @@ -34,4 +34,5 @@ handlers: env_variables: SPRING_PROFILES_ACTIVE: "ENVIRONMENT" + ENABLE_FULL_BUCKET_NAME: 'ENABLE_FULL_BUCKET_NAME_VAR' \ No newline at end of file diff --git a/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderFactoryImpl.java b/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderFactoryImpl.java index 150829919df3a31c3fa753dba0a9ef776a42276c..040d92900ddea325b279f1353f41307c432936b7 100644 --- a/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderFactoryImpl.java +++ b/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderFactoryImpl.java @@ -4,13 +4,17 @@ import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class StorageReaderFactoryImpl implements IStorageReaderFactory { + @Value("#{new Boolean('${enable.full.bucket.name:false}')}") + private Boolean isFullBucketName; + @Override public IStorageReader getReader(TenantInfo tenant, String projectRegion) { - return new StorageReaderImpl(tenant, projectRegion); + return new StorageReaderImpl(tenant, projectRegion, isFullBucketName); } } diff --git a/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderImpl.java b/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderImpl.java index 30620ee300969ddc4fa7104d9fd0b42cbcd0d5f9..68a5ec702285ff228ae09b8bb567833a31f53760 100644 --- a/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderImpl.java +++ b/provider/legal-gcp/src/main/java/org/opengroup/osdu/legal/countries/StorageReaderImpl.java @@ -2,6 +2,7 @@ package org.opengroup.osdu.legal.countries; import com.google.cloud.storage.*; +import java.util.Objects; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; import org.springframework.http.MediaType; @@ -14,16 +15,22 @@ public class StorageReaderImpl implements IStorageReader { private String projectRegion; private Storage storage; - private static final String BUCKET_NAME = "legal-service-configuration"; + protected static final String BUCKET_NAME = "legal-service-configuration"; private static final String FILE_NAME = "Legal_COO.json"; + private Boolean isFullBucketName = false; public StorageReaderImpl(TenantInfo tenantInfo, String projectRegion) { + new StorageReaderImpl(tenantInfo, projectRegion, false); + } + + public StorageReaderImpl(TenantInfo tenantInfo, String projectRegion, Boolean isFullBucketName) { this.tenantInfo = tenantInfo; this.projectRegion = projectRegion; this.storage = getStorage(); - } + this.isFullBucketName = isFullBucketName; + } - @Override + @Override public byte[] readAllBytes() { BlobId blobId = getBlobId(); byte[] content = null; @@ -67,8 +74,11 @@ public class StorageReaderImpl implements IStorageReader { this.storage.create(blobInfo, "".getBytes(UTF_8)); } - private String getTenantBucketName() { - return this.tenantInfo.getName() + "-" + BUCKET_NAME; + protected String getTenantBucketName() { + if (Objects.nonNull(isFullBucketName) && isFullBucketName) { + return this.tenantInfo.getProjectId() + "-" + this.tenantInfo.getName() + "-" + BUCKET_NAME; + } + return this.tenantInfo.getName() + "-" + BUCKET_NAME; } } diff --git a/provider/legal-gcp/src/main/resources/application.properties b/provider/legal-gcp/src/main/resources/application.properties index a9ffebdae689b1d1d115e882e05298a6b967cc9b..bf07a45760f74579a99557bef569fc1ba61d7b67 100644 --- a/provider/legal-gcp/src/main/resources/application.properties +++ b/provider/legal-gcp/src/main/resources/application.properties @@ -8,4 +8,4 @@ server.port=8080 JAVA_HEAP_OPTS=-Xms4096M -Xmx4096M JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45 - +enable.full.bucket.name=false \ No newline at end of file diff --git a/provider/legal-gcp/src/test/java/org/opengroup/osdu/legal/countries/StorageReaderImplTests.java b/provider/legal-gcp/src/test/java/org/opengroup/osdu/legal/countries/StorageReaderImplTests.java index 83d92384787ab5690915adec911e7a0563e9741b..5ddca787acecc9855c7258b1cbc47e806e255571 100644 --- a/provider/legal-gcp/src/test/java/org/opengroup/osdu/legal/countries/StorageReaderImplTests.java +++ b/provider/legal-gcp/src/test/java/org/opengroup/osdu/legal/countries/StorageReaderImplTests.java @@ -13,6 +13,7 @@ import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.*; +import static org.opengroup.osdu.legal.countries.StorageReaderImpl.BUCKET_NAME; import static org.powermock.api.mockito.PowerMockito.when; @RunWith(MockitoJUnitRunner.class) @@ -74,4 +75,37 @@ public class StorageReaderImplTests { byte[] bytes = sut.readAllBytes(); assertEquals(expectedBytes, bytes); } + + @Test + public void should_returnFullBucketName_when_IsFullBucketName_is_true() { + when(tenantInfo.getName()).thenReturn("tenant1"); + when(tenantInfo.getProjectId()).thenReturn("projectId1"); + String bucketName = tenantInfo.getProjectId() + "-" + tenantInfo.getName() + "-" + BUCKET_NAME; + StorageReaderImpl storageReader = new StorageReaderImpl(tenantInfo, null, + true); + String resultBucketName = storageReader.getTenantBucketName(); + assertEquals(bucketName, resultBucketName); + } + + @Test + public void should_returnBucketName_when_IsFullBucketName_is_false() { + when(tenantInfo.getName()).thenReturn("tenant1"); + when(tenantInfo.getProjectId()).thenReturn("projectId1"); + String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME; + StorageReaderImpl storageReader = new StorageReaderImpl(tenantInfo, null, + false); + String resultBucketName = storageReader.getTenantBucketName(); + assertEquals(bucketName, resultBucketName); + } + + @Test + public void should_returnBucketName_when_IsFullBucketName_is_null() { + when(tenantInfo.getName()).thenReturn("tenant1"); + when(tenantInfo.getProjectId()).thenReturn("projectId1"); + String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME; + StorageReaderImpl storageReader = new StorageReaderImpl(tenantInfo, null, + null); + String resultBucketName = storageReader.getTenantBucketName(); + assertEquals(bucketName, resultBucketName); + } } \ No newline at end of file diff --git a/provider/legal-gcp/src/test/resources/application.properties b/provider/legal-gcp/src/test/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..f8c687e1ba7be85f17ef24de4ce700caf3429683 --- /dev/null +++ b/provider/legal-gcp/src/test/resources/application.properties @@ -0,0 +1,3 @@ +enable.full.bucket.name=false + + diff --git a/testing/legal-test-azure/pom.xml b/testing/legal-test-azure/pom.xml index 042cc6961e7b0297d068a9b855347a9e6c107364..eb7d0cd74467aedc6cc6d34be0f9b5df0828704c 100644 --- a/testing/legal-test-azure/pom.xml +++ b/testing/legal-test-azure/pom.xml @@ -30,6 +30,8 @@ <maven.compiler.source>1.8</maven.compiler.source> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> + <jackson.version>2.10.1</jackson.version> + <corelib.version>0.0.33</corelib.version> </properties> <dependencies> <dependency> @@ -41,13 +43,13 @@ <dependency> <groupId>com.azure</groupId> <artifactId>azure-storage-blob</artifactId> - <version>12.0.0-preview.2</version> + <version>12.3.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-servicebus --> <dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-servicebus</artifactId> - <version>1.2.8</version> + <version>3.1.4</version> </dependency> <!-- Tests --> @@ -56,7 +58,31 @@ <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> - </dependency> + </dependency> + <!-- Added depdencies Azure Service Principle --> + <dependency> + <groupId>io.netty</groupId> + <artifactId>netty-all</artifactId> + <version>4.1.50.Final</version> + </dependency> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib-azure</artifactId> + <version>${corelib.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>com.azure</groupId> + <artifactId>azure-core-http-netty</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>${jackson.version}</version> + <scope>test</scope> + </dependency> </dependencies> <repositories> diff --git a/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureLegalTagUtils.java b/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureLegalTagUtils.java index 54cef5b34107d630e9c28e22c1fcfb426b2ad218..f21d324fe88691eb624e64c0dae4526760f7611b 100644 --- a/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureLegalTagUtils.java +++ b/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureLegalTagUtils.java @@ -16,50 +16,90 @@ package org.opengroup.osdu.legal.util; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import com.azure.storage.blob.BlobServiceClient; -import com.azure.storage.blob.BlobServiceClientBuilder; -import com.azure.storage.blob.BlockBlobClient; -import com.azure.storage.blob.ContainerClient; -import com.azure.storage.common.credentials.SharedKeyCredential; +import com.azure.identity.ClientSecretCredential; +import com.azure.identity.ClientSecretCredentialBuilder; +import com.azure.storage.blob.BlobContainerClient; +import com.azure.storage.blob.BlobContainerClientBuilder; +import com.azure.storage.blob.BlobUrlParts; +import com.azure.storage.blob.specialized.BlockBlobClient; import com.google.common.base.Strings; +import org.opengroup.osdu.azure.util.AzureServicePrincipal; public class AzureLegalTagUtils extends LegalTagUtils { private static final String FILE_NAME = "Legal_COO.json"; private static final String CONTAINER_NAME_AZURE = "legal-service-azure-configuration"; + private static String clientSecret = System.getProperty("AZURE_TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("AZURE_TESTER_SERVICEPRINCIPAL_SECRET")); + private static String clientId = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); + private static String tenantId = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID")); + private static String storageAccount = System.getProperty("AZURE_LEGAL_STORAGE_ACCOUNT", System.getenv("AZURE_LEGAL_STORAGE_ACCOUNT")).toLowerCase(); + private static String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID")); @Override public synchronized void uploadTenantTestingConfigFile() { try { - String storageAccount = System.getProperty("AZURE_LEGAL_STORAGE_ACCOUNT", System.getenv("AZURE_LEGAL_STORAGE_ACCOUNT")).toLowerCase(); - String storageAccountKey = System.getProperty("AZURE_LEGAL_STORAGE_KEY", System.getenv("AZURE_LEGAL_STORAGE_KEY")); - SharedKeyCredential credential = new SharedKeyCredential(storageAccount, storageAccountKey); - BlobServiceClient storageClient = new BlobServiceClientBuilder() - .endpoint(String.format("https://%s.blob.core.windows.net", storageAccount)) - .credential(credential) - .buildClient(); - ContainerClient containerClient = storageClient - .getContainerClient(CONTAINER_NAME_AZURE); - BlockBlobClient blobClient = containerClient.getBlockBlobClient(FILE_NAME); - String content = readTestFile("TenantConfigTestingPurpose.json"); - InputStream dataStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); - blobClient.upload(dataStream, content.length()); - dataStream.close(); + String blobPath = generateBlobPath(storageAccount, CONTAINER_NAME_AZURE, FILE_NAME); + BlobUrlParts parts = BlobUrlParts.parse(blobPath); + BlobContainerClient blobContainerClient = getBlobContainerClient(parts.getAccountName(), parts.getBlobContainerName()); + if (!blobContainerClient.exists()) { + createContainer(parts.getBlobContainerName()); + } + BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(parts.getBlobName()).getBlockBlobClient(); + if (!blockBlobClient.exists()) { + String content = readTestFile("TenantConfigTestingPurpose.json"); + try (ByteArrayInputStream dataStream = new ByteArrayInputStream(content.getBytes())) { + blockBlobClient.upload(dataStream, content.length()); + } catch (Exception e) { + e.printStackTrace(); + throw new AssertionError(String.format("Error: Could not create test %s file blob", parts.getBlobName()), e); + } + } }catch (IOException ex){ ex.printStackTrace(); } } - + + private static String generateContainerPath(String accountName, String containerName) { + return String.format("https://%s.blob.core.windows.net/%s", accountName, containerName); + } + + public void createContainer(String containerName) + { + String containerPath = generateContainerPath(storageAccount, containerName); + BlobUrlParts parts = BlobUrlParts.parse(containerPath); + BlobContainerClient blobContainerClient = getBlobContainerClient(parts.getAccountName(), parts.getBlobContainerName()); + if(!blobContainerClient.exists()){ + blobContainerClient.create(); + + } + } + + private static String generateBlobPath(String accountName, String containerName, String blobName) { + return String.format("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName); + } + + private BlobContainerClient getBlobContainerClient(String accountName, String containerName) { + ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder() + .clientSecret(clientSecret) + .clientId(clientId) + .tenantId(tenantId) + .build(); + BlobContainerClient blobContainerClient = new BlobContainerClientBuilder() + .endpoint(getBlobAccountUrl(accountName)) + .credential(clientSecretCredential) + .containerName(containerName) + .buildClient(); + return blobContainerClient; + } + + private static String getBlobAccountUrl(String accountName) { + return String.format("https://%s.blob.core.windows.net", accountName); + } + @Override public synchronized String accessToken() throws Exception { if (Strings.isNullOrEmpty(token)) { - String sp_id = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); - String sp_secret = System.getProperty("AZURE_TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("AZURE_TESTER_SERVICEPRINCIPAL_SECRET")); - String tenant_id = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID")); - String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID")); - token = AzureServicePrincipal.getIdToken(sp_id, sp_secret, tenant_id, app_resource_id); + token = new AzureServicePrincipal().getIdToken(clientId, clientSecret, tenantId, app_resource_id); } return "Bearer " + token; } diff --git a/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureServicePrincipal.java b/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureServicePrincipal.java deleted file mode 100644 index 84b9a699a3a09ae6982ad788ae84baa6c6b11a39..0000000000000000000000000000000000000000 --- a/testing/legal-test-azure/src/test/java/org/opengroup/osdu/legal/util/AzureServicePrincipal.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright © Microsoft Corporation -// -// 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.legal.util; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; - -public class AzureServicePrincipal { - public static String getIdToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception { - String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id); - URL url = new URL(aad_endpoint); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - - Map<String, String> parameters = new HashMap<>(); - parameters.put("grant_type", "client_credentials"); - parameters.put("client_id", sp_id); - parameters.put("client_secret", sp_secret); - parameters.put("resource", app_resource_id); - - con.setDoOutput(true); - DataOutputStream out = new DataOutputStream(con.getOutputStream()); - out.writeBytes(getParamsString(parameters)); - out.flush(); - out.close(); - - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuffer content = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); - - con.disconnect(); - - Gson gson = new Gson(); - JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); - String token = jobj.get("access_token").getAsString(); - return token; - } - - private static String getParamsString(Map<String, String> params) - throws UnsupportedEncodingException { - StringBuilder result = new StringBuilder(); - - for (Map.Entry<String, String> entry : params.entrySet()) { - result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); - result.append("="); - result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); - result.append("&"); - } - - String resultString = result.toString(); - return resultString.length() > 0 - ? resultString.substring(0, resultString.length() - 1) - : resultString; - } -} diff --git a/testing/legal-test-core/pom.xml b/testing/legal-test-core/pom.xml index d8608b4c6fed497d05f64b629bc977eeef5479ea..969651efa533300ddf0a0202579659675293be18 100644 --- a/testing/legal-test-core/pom.xml +++ b/testing/legal-test-core/pom.xml @@ -45,6 +45,12 @@ <artifactId>pact-jvm-provider-junit_2.12</artifactId> <version>3.5.5</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + <scope>provided</scope> + </dependency> </dependencies> <repositories> diff --git a/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/AcceptanceBaseTest.java b/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/AcceptanceBaseTest.java index 3266e212c49553c599d7086170d2c8b49a0ad252..12b72e4f4e89d81f6607971b12443a3eeecb4139 100644 --- a/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/AcceptanceBaseTest.java +++ b/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/AcceptanceBaseTest.java @@ -5,13 +5,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.opengroup.osdu.legal.util.Constants.DATA_PARTITION_ID; +import com.sun.jersey.api.client.ClientResponse; import java.util.HashMap; import java.util.Map; - -import com.sun.jersey.api.client.ClientResponse; - +import java.util.Objects; +import lombok.extern.java.Log; import org.junit.Test; +@Log public abstract class AcceptanceBaseTest { protected LegalTagUtils legalTagUtils; @@ -84,17 +85,25 @@ public abstract class AcceptanceBaseTest { return response; } - protected ClientResponse validateAccess(int expectedResponse) throws Exception { - Map<String, String> headers = new HashMap<>(); - headers.put(DATA_PARTITION_ID, LegalTagUtils.getMyDataPartition()); - - ClientResponse response = legalTagUtils.send(this.getApi(), this.getHttpMethod(), legalTagUtils.accessToken(), getBody(), getQuery(), headers); - assertEquals(expectedResponse, response.getStatus()); - if(expectedResponse == 204) - assertNull(response.getType()); - else if(response.getType() != null) { - assertTrue(response.getType().toString().toLowerCase().indexOf("application/json") >= 0); - } - return response; - } + protected ClientResponse validateAccess(int expectedResponse) throws Exception { + Map<String, String> headers = new HashMap<>(); + headers.put(DATA_PARTITION_ID, LegalTagUtils.getMyDataPartition()); + + ClientResponse response = legalTagUtils + .send(this.getApi(), this.getHttpMethod(), legalTagUtils.accessToken(), getBody(), + getQuery(), headers); + log.info("Response status = " + response.getStatus()); + assertEquals(expectedResponse, response.getStatus()); + if (expectedResponse == 204) { + if (Objects.nonNull(response.getType())) { + log.info("Content-Type = " + response.getType().toString()); + assertTrue(response.getType().toString().toLowerCase().indexOf("text/html") >= 0); //Google Cloud Run specific + } else { + assertNull(response.getType()); + } + } else if (response.getType() != null) { + assertTrue(response.getType().toString().toLowerCase().indexOf("application/json") >= 0); + } + return response; + } } \ No newline at end of file diff --git a/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/TestUtils.java b/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/TestUtils.java index 1f026e853325388feb0480b5e4622131c53f84f8..e61a6934736e6bdcd3e64eee597bcb97371b862b 100644 --- a/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/TestUtils.java +++ b/testing/legal-test-core/src/main/java/org/opengroup/osdu/legal/util/TestUtils.java @@ -18,6 +18,7 @@ import com.google.gson.Gson; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; +import javax.ws.rs.core.MediaType; public class TestUtils { @@ -77,19 +78,22 @@ public class TestUtils { return headers; } - public ClientResponse send(String path, String httpMethod, String token, String requestBody, String query, Map<String,String> headers) throws Exception { + public ClientResponse send(String path, String httpMethod, String token, String requestBody, + String query, Map<String, String> headers) throws Exception { - Client client = getClient(); - // client.setConnectTimeout(5000); - // client.setReadTimeout(30000); - WebResource webResource = client.resource(getApiPath(path + query)); - final WebResource.Builder builder = webResource.accept("application/json").type("application/json") - .header("Authorization", token); - headers.forEach((k, v) -> builder.header(k, v)); - ClientResponse response = builder.method(httpMethod, ClientResponse.class, requestBody); + Client client = getClient(); + WebResource webResource = client.resource(getApiPath(path + query)); - return response; - } + final WebResource.Builder builder = webResource.getRequestBuilder(); + builder.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON). + header("Authorization", token); + + headers.forEach(builder::header); + + ClientResponse response = builder.method(httpMethod, ClientResponse.class, requestBody); + + return response; + } @SuppressWarnings("unchecked") public <T> T getResult(ClientResponse response, int exepectedStatus, Class<T> classOfT) { diff --git a/testing/legal-test-gcp/pom.xml b/testing/legal-test-gcp/pom.xml index 03535c75e84ed733aa2e97995864ec9df7e2af76..a8c42dc0b3a6f4f93a8aeeac551536b1e3b43681 100644 --- a/testing/legal-test-gcp/pom.xml +++ b/testing/legal-test-gcp/pom.xml @@ -117,6 +117,12 @@ <artifactId>guava</artifactId> <version>27.1-jre</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + <scope>provided</scope> + </dependency> <!-- Tests --> <dependency> @@ -124,9 +130,22 @@ <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> - </dependency> + </dependency> + + <!--Logging--> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-to-slf4j</artifactId> + <version>2.11.2</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.8.0-beta4</version> + </dependency> </dependencies> + <!-- can remove this? --> <repositories> <repository> diff --git a/testing/legal-test-gcp/src/test/java/org/opengroup/osdu/legal/util/GCPLegalTagUtils.java b/testing/legal-test-gcp/src/test/java/org/opengroup/osdu/legal/util/GCPLegalTagUtils.java index c1d1eafe31f31e39b5fb8fa57bf3da971ba7fa4e..af9a44b8410492abb8c814af80b631325050d91f 100644 --- a/testing/legal-test-gcp/src/test/java/org/opengroup/osdu/legal/util/GCPLegalTagUtils.java +++ b/testing/legal-test-gcp/src/test/java/org/opengroup/osdu/legal/util/GCPLegalTagUtils.java @@ -12,7 +12,13 @@ import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; import com.google.common.collect.Lists; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Base64; +import lombok.extern.java.Log; +@Log public class GCPLegalTagUtils extends LegalTagUtils { private static final String BUCKET_NAME = "legal-service-configuration"; private static final String FILE_NAME = "Legal_COO.json"; @@ -38,11 +44,30 @@ public class GCPLegalTagUtils extends LegalTagUtils { } } - private static String getTenantBucketName() { - String tenantName = System.getProperty("MY_TENANT_PROJECT", System.getenv("MY_TENANT_PROJECT")).toLowerCase(); - return tenantName + "-" +BUCKET_NAME; + private static String getTenantBucketName() { + String tenantName = System + .getProperty("MY_TENANT_PROJECT", System.getenv("MY_TENANT_PROJECT")).toLowerCase(); + String projectName = System.getProperty("GCLOUD_PROJECT", System.getenv("GCLOUD_PROJECT")) + .toLowerCase(); + String enableFullBucketName = System.getProperty("ENABLE_FULL_BUCKET_NAME", + System.getenv("ENABLE_FULL_BUCKET_NAME")); + + enableFullBucketName = (Strings.isNullOrEmpty(enableFullBucketName) ? "false" + : enableFullBucketName).toLowerCase(); + + log.info("ENABLE_FULL_BUCKET_NAME = " + enableFullBucketName); + + String bucketName; + if (Boolean.parseBoolean(enableFullBucketName)) { + bucketName = projectName + "-" + tenantName + "-" + BUCKET_NAME; + } else { + bucketName = tenantName + "-" + BUCKET_NAME; } + log.info("bucketName = " + bucketName); + return bucketName; + } + @Override public synchronized String accessToken() throws Exception { if (Strings.isNullOrEmpty(token)) { diff --git a/testing/pom.xml b/testing/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..0299f5e71c65c621e972fcb0254b4609854a2353 --- /dev/null +++ b/testing/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2017-2019, Schlumberger + + 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 xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.opengroup.osdu.legal</groupId> + <artifactId>os-legal-testing</artifactId> + <version>0.0.2-SNAPSHOT</version> + <description>Root Legal Service project</description> + <packaging>pom</packaging> + + <licenses> + <license> + <name>Apache License, Version 2.0</name> + <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + <modules> + <module>legal-test-core</module> + <module>legal-test-aws</module> + <module>legal-test-azure</module> + <module>legal-test-gcp</module> + <module>legal-test-ibm</module> + </modules> + + <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/74/packages/maven</url> + </repository> + <snapshotRepository> + <id>${gitlab-server}</id> + <url>https://community.opengroup.org/api/v4/projects/74/packages/maven</url> + </snapshotRepository> + </distributionManagement> + +</project>