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.
# os-register-gcp
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.
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.
## Running locally
## 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.
### Requirements
### Requirements
* Java 8
* Java 8
...
@@ -36,33 +22,28 @@ This project uses [Lombok](https://projectlombok.org/) for code generation. You
...
@@ -36,33 +22,28 @@ This project uses [Lombok](https://projectlombok.org/) for code generation. You
| `DE_ADMIN_TESTER` | `********` | A base64 encoded google service account json credentials with _admin_ level authorization for OSDU services | yes ||
| `DE_EDITOR_TESTER` | `********` | A base64 encoded google service account json credentials with _editor_ level authorization for OSDU services | yes ||
| `ENTITLEMENTS_API` | ex `https://entitlements.com/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment |
| `DE_NO_ACCESS_TESTER` | `********` | A base64 encoded google service account json credentials with no authorization for OSDU services | yes ||
| `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 |
| `INTEGRATION_TEST_AUDIENCES` | ex `*****.apps.googleusercontent.com` | Client ID for getting access to cloud resources | yes | https://console.cloud.google.com/apis/credentials |
**System Environment required to run integration tests**
**System Environment required to run service**
| name | value | description | sensitive? | source |
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| --- | --- | --- | --- | --- |
| `ENVIRONMENT` | `local` | service running environment | no ||
| `SPRING_PROFILES_ACTIVE` | `local` | spring active profile | no |
You will need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`:
You will need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`:
```bash
```bash
$ cat ~/.m2/settings.xml
$ cat ~/.m2/settings.xml
<?xml version="1.0"encoding="UTF-8"?>
<?xml version="1.0"encoding="UTF-8"?>
...
@@ -90,21 +72,131 @@ $ cat ~/.m2/settings.xml
...
@@ -90,21 +72,131 @@ $ cat ~/.m2/settings.xml
</settings>
</settings>
```
```
### Build and run the application
* Update the Google cloud SDK to the latest version:
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
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:
```bash
```bash
# build + test + install core service code
# build + test + install core service code
$ cd register-core/ && mvn clean install
$ (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 | output of infrastructure deployment |
| `DE_ADMIN_TESTER` | `********` | A base64 encoded google service account json credentials with _admin_ level authorization for OSDU services | yes | output of infrastructure deployment |
| `DE_EDITOR_TESTER` | `********` | A base64 encoded google service account json credentials with _editor_ level authorization for OSDU services | yes | output of infrastructure deployment |
| `DE_NO_ACCESS_TESTER` | `********` | A base64 encoded google service account json credentials with no authorization for OSDU services | yes | output of infrastructure deployment |
| `REGISTER_BASE_URL` | ex `https://os-register-dot-opendes.appspot.com/api/register/v1` | Register API endpoint | yes | output of infrastructure deployment |
| `ENVIRONMENT` | ex `local` | 'local' for local testing or 'dev' for dev testing | no | output of infrastructure deployment |
| `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 |
**Entitlements configuration for integration accounts**
* 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
```
```
### Test the application
Add **Cloud KMS CryptoKey Encrypter/Decrypter** role to the **App Engine default service account** of the master project through IAM - Role tab
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.
\ No newline at end of file
Add "Cloud KMS Encrypt/Decrypt" role to the "App Engine default service account" of ***master project***