Skip to content

Commit

Permalink
Add Interops Module
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalig committed Oct 16, 2020
1 parent 4bc4a6e commit ef46b00
Show file tree
Hide file tree
Showing 16 changed files with 652 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/tagged_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
TESTCONTAINERS_RYUK_DISABLED: true
- name: shasum
- name: "Calculate shasum for SDK WS"
run: shasum -a 256 dpppt-backend-sdk/dpppt-backend-sdk-ws/target/dpppt-backend-sdk-ws.jar > dpppt-backend-sdk/dpppt-backend-sdk-ws/target/dpppt-backend-sdk-ws.sha256
shell: bash
- name: "Calculate shasum for SDK Interops"
run: shasum -a 256 dpppt-backend-sdk/dpppt-backend-sdk-interops/target/dpppt-backend-sdk-interops.jar > dpppt-backend-sdk/dpppt-backend-sdk-interops/target/dpppt-backend-sdk-interops.sha256
shell: bash
- name: "Create new release"
uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand All @@ -45,4 +48,6 @@ jobs:
dpppt-backend-sdk/dpppt-backend-sdk-ws/target/dpppt-backend-sdk-ws.jar
dpppt-backend-sdk/dpppt-backend-sdk-ws/target/dpppt-backend-sdk-ws.sha256
dpppt-backend-sdk/dpppt-backend-sdk-ws/generated/swagger/swagger.yaml
dpppt-backend-sdk/dpppt-backend-sdk-interops/target/dpppt-backend-sdk-interops.jar
dpppt-backend-sdk/dpppt-backend-sdk-interops/target/dpppt-backend-sdk-interops.sha256
110 changes: 110 additions & 0 deletions dpppt-backend-sdk/dpppt-backend-sdk-interops/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!-- ~ Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> ~
~ This Source Code Form is subject to the terms of the Mozilla Public ~ License,
v. 2.0. If a copy of the MPL was not distributed with this ~ file, You can
obtain one at https://mozilla.org/MPL/2.0/. ~ ~ SPDX-License-Identifier:
MPL-2.0 -->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<parent>
<groupId>org.dpppt</groupId>
<artifactId>dpppt-backend-sdk</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dpppt-backend-sdk-interops</artifactId>
<name>DP3T Backend SDK Interops Service</name>
<packaging>jar</packaging>

<properties>
<start-class>org.dpppt.backend.sdk.interops.Application</start-class>
<sonar.projectKey>DP-3T_dp3t-sdk-backend</sonar.projectKey>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- dp3t models -->
<dependency>
<groupId>org.dpppt</groupId>
<artifactId>dpppt-backend-sdk-model</artifactId>
</dependency>

<dependency>
<groupId>org.dpppt</groupId>
<artifactId>dpppt-backend-sdk-data</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- Spring Security Core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>

<!-- Spring Security Config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>

<!-- Spring Security Web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>

</dependencies>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>${spring-boot-version}</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>
dpppt-backend-sdk-interops
</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>org.dpppt.backend.sdk.interops.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.backend.sdk.interops;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@ComponentScan(basePackages = {"org.dpppt.backend.sdk.interops.config"})
@EnableAutoConfiguration(
exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
@EnableWebMvc
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.dpppt.backend.sdk.interops.config;

import org.dpppt.backend.sdk.interops.config.configbeans.ActuatorSecurityConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.info.InfoEndpoint;
import org.springframework.boot.actuate.logging.LoggersEndpoint;
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 9)
@Profile(value = "actuator-security")
@EnableWebSecurity
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {

private static final String PROMETHEUS_ROLE = "PROMETHEUS";

@Value("${ws.monitor.prometheus.user}")
private String user;

@Autowired Environment environment;
// region Actuator Passwords
// ----------------------------------------------------------------------------------------------------------------------------------
@Bean
@Profile("cloud-dev")
ActuatorSecurityConfig passwordCloudDev() {
return new ActuatorSecurityConfig(
user, environment.getProperty("vcap.services.ha_prometheus_dev.credentials.password"));
}

@Bean
@Profile("cloud-test")
ActuatorSecurityConfig passwordCloudTest() {
return new ActuatorSecurityConfig(
user, environment.getProperty("vcap.services.ha_prometheus_test.credentials.password"));
}

@Bean
@Profile("cloud-abn")
ActuatorSecurityConfig passwordCloudAbn() {
return new ActuatorSecurityConfig(
user, environment.getProperty("vcap.services.ha_prometheus_abn.credentials.password"));
}

@Bean
@Profile("cloud-prod")
ActuatorSecurityConfig passwordProdAbn() {
return new ActuatorSecurityConfig(
user, environment.getProperty("vcap.services.ha_prometheus_prod.credentials.password"));
}

@Bean
@ConditionalOnMissingBean
ActuatorSecurityConfig passwordDefault() {
return new ActuatorSecurityConfig(
user, environment.getProperty("ws.monitor.prometheus.password"));
}
// ----------------------------------------------------------------------------------------------------------------------------------
// endregion

@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest
.toAnyEndpoint())
.authorizeRequests()
.requestMatchers(
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to(
HealthEndpoint.class))
.permitAll()
.requestMatchers(
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to(
InfoEndpoint.class))
.permitAll()
.requestMatchers(
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to(
LoggersEndpoint.class))
.hasRole(PROMETHEUS_ROLE)
.requestMatchers(
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to(
PrometheusScrapeEndpoint.class))
.hasRole(PROMETHEUS_ROLE)
.anyRequest()
.denyAll()
.and()
.httpBasic();

http.csrf().ignoringAntMatchers("/actuator/loggers/**");
}

@Autowired
protected void configureGlobal(
AuthenticationManagerBuilder auth, ActuatorSecurityConfig securityConfig) throws Exception {
auth.inMemoryAuthentication()
.withUser(securityConfig.getUsername())
.password(passwordEncoder().encode(securityConfig.getPassword()))
.roles(PROMETHEUS_ROLE);
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.backend.sdk.interops.config;

import javax.sql.DataSource;
import org.flywaydb.core.Flyway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableScheduling
public abstract class WSBaseConfig implements SchedulingConfigurer, WebMvcConfigurer {

protected final Logger logger = LoggerFactory.getLogger(getClass());

public abstract DataSource dataSource();

public abstract Flyway flyway();

public abstract String getDbType();

@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.backend.sdk.interops.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("cloud-abn")
public class WSCloudAbnConfig extends WSCloudBaseConfig {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.backend.sdk.interops.config;

import javax.sql.DataSource;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

@Configuration
public abstract class WSCloudBaseConfig extends WSBaseConfig {

@Autowired @Lazy private DataSource dataSource;

@Override
public DataSource dataSource() {
return dataSource;
}

@Bean
@Override
public Flyway flyway() {
Flyway flyWay =
Flyway.configure()
.dataSource(dataSource())
.locations("classpath:/db/migration/pgsql_cluster")
.load();
flyWay.migrate();
return flyWay;
}

@Override
public String getDbType() {
return "pgsql";
}
}
Loading

0 comments on commit ef46b00

Please sign in to comment.