Skip to content
Snippets Groups Projects
README.md 9.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • # Register Service
    
    David Diederich's avatar
    David Diederich committed
    os-register-gcp is a [Spring Boot](https://spring.io/projects/spring-boot) service that hosts CRUD APIs that allows consumers to register a push endpoint that can be triggered when data change events happen 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.
    
    David Diederich's avatar
    David Diederich committed
    
    ### Requirements
    * Java 8
    * [Maven 3.6.0+](https://maven.apache.org/download.cgi)
    * GCloud command line tool
    * GCloud access to opendes project
    
    ### General Tips
    
    **Environment Variable Management**
    The following tools make environment variable configuration simpler
     - [direnv](https://direnv.net/) - for a shell/terminal environment
     - [EnvFile](https://plugins.jetbrains.com/plugin/7861-envfile) - for [Intellij IDEA](https://www.jetbrains.com/idea/)
    
    **Lombok**
    This project uses [Lombok](https://projectlombok.org/) for code generation. You may need to configure your IDE to take advantage of this tool.
     - [Intellij configuration](https://projectlombok.org/setup/intellij)
     - [VSCode configuration](https://projectlombok.org/setup/vscode)
    
    
    ### Installation
    In order to run the service locally or remotely, you will need to have the following environment variables defined.
    
    David Diederich's avatar
    David Diederich committed
    
    | name | value | description | sensitive? | source |
    | ---  | ---   | ---         | ---        | ---    |
    
    | `LOG_PREFIX` | `service` | Logging prefix | no | - |
    | `SERVER_SERVLET_CONTEXPATH` | `/api/register/v1` | Register context path | no | - |
    | `ENTITLEMENTS_API` | ex `https://entitlements.com/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment |
    | `STORAGE_API` | ex `https://os-storage-dot-opendes.appspot.com/api/storage/v2` | Storage API endpoint | no | output of infrastructure deployment |
    | `RECORDS_CHANGE_PUBSUB_ENDPOINT` | ex `https://os-notification-dot-opendes.appspot.com/push-handlers/records-changed` | Notification API endpoint 'records-changed'  | no | output of infrastructure deployment |
    | `GOOGLE_CLOUD_PROJECT` | ex `opendes` | Google Cloud Project Id | no | output of infrastructure deployment |
    | `SUBSCRIBER_SECRET` | `********` | - | yes | output of infrastructure deployment |
    | `SUBSCRIBER_PRIVATE_KEY_ID` | `********` | - | yes | output of infrastructure deployment |
    | `INTEGRATION_TEST_AUDIENCES` | ex `*****.apps.googleusercontent.com` | Client ID for getting access to cloud resources | yes | https://console.cloud.google.com/apis/credentials |
    
    David Diederich's avatar
    David Diederich committed
    
    
    **System Environment required to run service**
    
    David Diederich's avatar
    David Diederich committed
    
    | name | value | description | sensitive? | source |
    | ---  | ---   | ---         | ---        | ---    |
    
    | `SPRING_PROFILES_ACTIVE` | `local` | spring active profile | no |
    
    David Diederich's avatar
    David Diederich committed
    
    
    ### Run Locally
    
    David Diederich's avatar
    David Diederich committed
    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 will need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`:
    
    David Diederich's avatar
    David Diederich committed
    ```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>slb-des-ext-collaboration</username>
                <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
                <password>${VSTS_FEED_TOKEN}</password>
            </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 register service's root folder and run:
    
    ```bash
    mvn jetty:run
    ## Testing
    * Navigate to register 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/register-gcp/ && mvn spring-boot:run -Dspring-boot.run.profiles=local 
    ```
    
    ## Testing
    Navigate to register service's root folder and run all the tests:
    
    
    David Diederich's avatar
    David Diederich committed
    ```bash
    # build + test + install core service code
    
    $ (cd register-core/ && mvn clean install)
    ```
    
    ## Test the application
    
    After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/api/register/v1/swagger-ui.html](http://localhost:8080/api/register/v1/swagger-ui.html). If the request does not fail, you can then run the integration tests.
    
    ### Running E2E Tests 
    
    This section describes how to run cloud OSDU E2E tests (testing/register-test-gcp).
    
    You will need to have the following environment variables defined.
    
    | name | value | description | sensitive? | source |
    | ---  | ---   | ---         | ---        | ---    |
    
    | `DE_OPS_TESTER` | `********` | A base64 encoded google service account json credentials with _ops_ level authorization for OSDU services | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
    | `DE_ADMIN_TESTER` | `********` | A base64 encoded google service account json credentials with _admin_ level authorization for OSDU services | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
    | `DE_EDITOR_TESTER` | `********` | A base64 encoded google service account json credentials with _editor_ level authorization for OSDU services | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
    | `DE_NO_ACCESS_TESTER` | `********` | A base64 encoded google service account json credentials with no authorization for OSDU services | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
    | `REGISTER_BASE_URL` | ex `https://os-register-dot-opendes.appspot.com/` | Register API endpoint | no | output of infrastructure deployment |
    | `ENVIRONMENT` | ex `local` | 'local' for local testing or 'dev' for dev testing | no | - |
    
    | `SUBSCRIBER_SECRET` | ex `********` | Sensitive secret to run HMAC tests | yes | output of infrastructure deployment |
    | `INTEGRATION_TEST_AUDIENCE` | ex `*****.apps.googleusercontent.com` | Client ID for getting access to cloud resources | yes | https://console.cloud.google.com/apis/credentials |
    
    | `CLIENT_TENANT` | ex `opendes` | Client tenant | no | - |
    | `OSDU_TENANT` | ex `osdu` | Osdu tenant | no | - |
    | `SUBSCRIPTION_ID` | `********` | Subscription id | no | - |
    
    
    **Entitlements configuration for integration accounts**
    
    David Diederich's avatar
    David Diederich committed
    
    
    | DE_OPS_TESTER | DE_ADMIN_TESTER | DE_EDITOR_TESTER | DE_NO_ACCESS_TESTER
    | ---  | ---  | ---  | --- |
    
    | service.entitlements.user<br/>users.datalake.ops<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | service.entitlements.user<br/>users.datalake.admins<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | users<br/>service.entitlements.user<br/>users.datalake.editors<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com | users<br/>service.entitlements.user<br/>data.test1<br/>data.integration.test<br/>users@{tenant1}@{domain}.com
    
    David Diederich's avatar
    David Diederich committed
    
    
    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
    
    David Diederich's avatar
    David Diederich committed
    #       above are already exported in your environment.
    
    $ (cd testing/register-test-gcp/ && mvn clean test)
    ```
    
    ## Deployment
    
    * Data-Lake Register Google Cloud Endpoints on App Engine Flex environment
      * Edit the app.yaml
        * Open the [app.yaml](src/main/appengine/app.yaml) file in editor, and replace the YOUR-PROJECT-ID `PROJECT` line with Google Cloud Platform project Id. Also update `INTEGRATION_TEST_AUDIENCE`, `SUBSCRIBER_PRIVATE_KEY_ID`, `SPRING_PROFILES_ACTIVE`, `ENTITLEMENTS_API`, `STORAGE_API`, `RECORDS_CHANGE_PUBSUB_ENDPOINT`, `GOOGLE_CLOUD_PROJECT` and `STORAGE_API`  based on your deployment
      * Google Documentation: https://cloud.google.com/cloud-build/docs/deploying-builds/deploy-appengine
    
    #### Cloud KMS Setup
    
    Enable cloud KMS on master project
    
    Create king ring and key in the ***master project***
    
    ```bash
        gcloud services enable cloudkms.googleapis.com
        export KEYRING_NAME="csqp"
        export CRYPTOKEY_NAME="registerService"
        gcloud kms keyrings create $KEYRING_NAME --location global
        gcloud kms keys create $CRYPTOKEY_NAME --location global \
        		--keyring $KEYRING_NAME \
        		--purpose encryption
    
    David Diederich's avatar
    David Diederich committed
    ```
    
    
    Add **Cloud KMS CryptoKey Encrypter/Decrypter** role to the **App Engine default service account** of the master project through IAM - Role tab
    
    Add "Cloud KMS Encrypt/Decrypt" role to the "App Engine default service account" of ***master project***
    
    ## 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.