Commit 6af0d00b authored by David Diederich's avatar David Diederich
Browse files

Initial Import

parents
**/.idea
**/target
**/build
**/.gradle
**/out
**/*.iml
**/dependency-reduced-pom.xml
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.
# Notification service
The Notification service, with Register service, allow interested consumers to subscribe to data and metadata changes using a publisher/subscriber pattern
##Dependencies needed to run the code locally
* JDK11
* Maven
* Azure Devops access to slb-des-ext-collaboration organization. You need to generate a PAT that can access dependencies held in the Azure artifacts
* Working Register service endpoint
## Build and run service locally
* Build the service and run the unit tests. This step also generates the executable jar file. Run this command from the root folder, where parent pom.xml resides
**Note**: At runtime, you must set a Spring profile so the right runtime configuration gets picked up for your app. Since this is a Spring Boot application, runtime configuration is defined in one of the application properties files under `<provider>->src->main->resources`. You can set the right Spring Boot runtime profile with `-Dspring.profiles.active=test`. Please read [this](https://stackoverflow.com/questions/39738901/how-do-i-activate-a-spring-boot-profile-when-running-from-intellij) for more info.
```
mvn clean install
```
* To run the service locally, navigate to `provider/notification-<your_provider>/target` directory and execute the spring-boot jar
```
java -jar notification-gcp-1.0.0-spring-boot.jar
```
* To debug service locally, create a remote debug configuration first and then use following command to start service in debug mode
```
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar notification-gcp-1.0.0-spring-boot.jar
```
**Note:** The port number "8000" in the command should match with the remote debug config settings.
## Access the service:
The port and path for the service endpoint can be configured in ```application.properties``` as following. If not specified, then the web container (ex. Tomcat) default is used:
```bash
server.servlet.contextPath=/
server.port=8080
```
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<password>${VSTS_FEED_TOKEN}</password>
</server>
</servers>
</settings>
\ No newline at end of file
trigger: [ 'master' ]
pool:
name: Hosted Ubuntu 1604
demands: maven
variables:
osProjectName: notification
dockerDir: provider/$(osProjectName)-gcp/docker
imageName: os-$(osProjectName)-app
sourceImageName: gcr.io/opendes/$(imageName)
tag: $(Build.BuildNumber)
steps:
- task: DownloadSecureFile@1
name: gcrKey
inputs:
secureFile: cicd-push-image-to-cr-keyfile.json
- task: Maven@3
displayName: 'Build and test'
inputs:
jdkVersionOption: 1.8
jdkArchitectureOption: 'x64'
mavenPomFile: 'pom.xml'
goals: "clean install"
options: '--settings configuration/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)'
testResultsFiles: '**/TEST-*.xml'
- bash: |
#!/bin/bash
set -e
pushd $(dockerDir)
docker-compose build $(imageName)
echo 'Image done.'
cat $(gcrKey.secureFilePath) | docker login -u _json_key --password-stdin https://gcr.io
echo 'Login done.'
docker tag $(sourceImageName) $(sourceImageName):$(tag)
docker push $(sourceImageName):$(tag)
popd
displayName: 'Docker image build and push'
- bash: |
sed -i -e "s|{{definitionName}}|$(build.DefinitionName)|g" deploy.sh
sed -i -e "s|{{sourceBranchName}}|$(build.SourceBranchName)|g" deploy.sh
sed -i -e "s|{{buildNumber}}|$(build.BuildNumber)|g" deploy.sh
workingDirectory: provider/notification-gcp/scripts
displayName: 'Gomplate GCP deploy script'
- task: ArchiveFiles@2
displayName: 'Archive integration-tests'
inputs:
rootFolderOrFile: 'testing'
archiveFile: 'provider/notification-gcp/target/integration-tests.zip'
includeRootFolder: false
- task: CopyFiles@2
displayName: 'Copy deployable jar and integration tests zip'
inputs:
sourceFolder: 'provider/notification-gcp/target'
contents: |
*spring-boot.jar
integration-tests.zip
targetFolder: '$(build.artifactstagingdirectory)/deploy'
- task: CopyFiles@2
displayName: 'Copy maven settings.xml'
inputs:
sourceFolder: 'configuration'
contents: 'settings.xml'
targetFolder: '$(build.artifactstagingdirectory)/deploy'
- task: CopyFiles@2
displayName: 'Copy deploy scripts'
inputs:
sourceFolder: 'provider/notification-gcp/scripts'
contents: '**'
targetFolder: '$(build.artifactstagingdirectory)/deploy'
- task: CopyFiles@2
displayName: 'Copy deployment yaml'
inputs:
sourceFolder: 'provider/notification-gcp/src/main/appengine'
contents: '**'
targetFolder: '$(build.artifactstagingdirectory)/deploy'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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</groupId>
<artifactId>notification-core</artifactId>
<version>1.0.0</version>
<name>notification-core</name>
<description>Core module for the notification service</description>
<packaging>jar</packaging>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-notification</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<java.version>8</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>os-core</id>
<url>https://pkgs.dev.azure.com/slb-des-ext-collaboration/_packaging/os-core/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.0.19</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.1.23</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.30.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.30.1</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.30.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0-jre</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-iam</artifactId>
<version>v1-rev289-1.25.0</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.3</version>
</dependency>
<!--
A security vulnerability in spring-web library is reported: A potential remote code execution (RCE) issue.
Depending on how the library is implemented, it may or may not manifest.
As strongly recommendation: Do not use Java serialization for external endpoints, in particular not for unauthorized ones
Please see detail for the case: https://bugzilla.redhat.com/show_bug.cgi?id=1357929
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.7.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>tomcat-embed-el</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-core</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-websocket</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<version>2.2.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>2.0.27.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.2.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.whitesource</groupId>
<artifactId>whitesource-maven-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<orgToken>${orgToken}</orgToken>
<wssUrl>https://app-eu.whitesourcesoftware.com/agent</wssUrl>
<aggregateModules>true</aggregateModules>
<product>DPS</product>
<aggregateProjectName>dps-search</aggregateProjectName>
<forceCheckAllDependencies>false</forceCheckAllDependencies>
<checkPolicies>false</checkPolicies>
<forceUpdate>true</forceUpdate>
<failOnError>true</failOnError>
<excludes>
<exclude>integration-tests</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.7.RELEASE</version>
<configuration>
<profiles>
<profile>local</profile>
</profiles>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
org.opengroup.osdu.notification.Application
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* 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.notification;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import javax.annotation.PostConstruct;
@SpringBootApplication
@ComponentScan({"org.opengroup.osdu"})
@EnableAsync
public class Application {
public static void main(String[] args) {
SpringApplication.run(new Class[] { Application.class} , args);
}
}
/*
* 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.notification;
import org.springframework.context.annotation.Configuration;
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.WebSecurityConfigurerAdapter;
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.httpBasic().disable()
.csrf().disable(); //disable default authN. AuthN handled by endpoints proxy
}
}
\ No newline at end of file
/*
* 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.notification.api;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RequestMapping("/error")
@Controller
public class GlobalErrorController implements ErrorController {
@GetMapping
@ResponseBody
public String handleErrorGet(HttpServletRequest request) {
return getString(request);
}
@DeleteMapping
@ResponseBody
public String handleErrorDelete(HttpServletRequest request) {
return getString(request);
}
@PostMapping
@ResponseBody
public String handleErrorPost(HttpServletRequest request) {
return getString(request);
}
@PatchMapping
@ResponseBody
public String handleErrorPatch(HttpServletRequest request) {
return getString(request);
}
@PutMapping
@ResponseBody
public String handleErrorPut(HttpServletRequest request) {
return getString(request);
}
private String getString(HttpServletRequest request) {