Skip to content

Commit

Permalink
Merge pull request #218 from DP-3T/feature/clouddbpoolconfig
Browse files Browse the repository at this point in the history
Feature/clouddbpoolconfig
  • Loading branch information
martinalig authored Aug 21, 2020
2 parents b8c6476 + a52d648 commit 100bcde
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
67 changes: 34 additions & 33 deletions dpppt-backend-sdk/dpppt-backend-sdk-ws/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<!--
~ 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
-->
<!-- ~ 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"
Expand Down Expand Up @@ -36,6 +32,11 @@
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>

<dependency>
<groupId>ch.ubique.openapi</groupId>
<artifactId>doc-annotations</artifactId>
Expand Down Expand Up @@ -74,7 +75,7 @@
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.65</version>
</dependency>
Expand Down Expand Up @@ -109,7 +110,7 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependency>

<dependency>
<groupId>com.hubspot.jackson</groupId>
Expand Down Expand Up @@ -153,31 +154,31 @@
</executions>
</plugin>
<plugin>
<groupId>ch.ubique.openapi</groupId>
<artifactId>springboot-swagger-3</artifactId>
<version>1.2.8</version>
<configuration>
<apiVersion>1.0-gapple</apiVersion>
<basePackages>
org.dpppt.backend.sdk.model
</basePackages>
<groupId>ch.ubique.openapi</groupId>
<artifactId>springboot-swagger-3</artifactId>
<version>1.2.8</version>
<configuration>
<apiVersion>1.0-gapple</apiVersion>
<basePackages>
org.dpppt.backend.sdk.model
</basePackages>
<blackListedPackages>
<blackListedPackage>com.google.protobuf</blackListedPackage>
</blackListedPackages>
<ignoredTypes>
<ignoredType>byte</ignoredType>
</ignoredTypes>
<controllers>
<controller>org.dpppt.backend.sdk.ws.controller.DPPPTController</controller>
<controllers>
<controller>org.dpppt.backend.sdk.ws.controller.DPPPTController</controller>
<controller> org.dpppt.backend.sdk.ws.controller.GaenController</controller>
</controllers>
<description>DP3T API</description>
<apiUrls>
<apiUrl>https://demo.dpppt.org</apiUrl>
</apiUrls>
<title>DP3T API</title>
</configuration>
</plugin>
</controllers>
<description>DP3T API</description>
<apiUrls>
<apiUrl>https://demo.dpppt.org</apiUrl>
</apiUrls>
<title>DP3T API</title>
</configuration>
</plugin>
</plugins>
</build>

Expand All @@ -190,16 +191,16 @@
<name>bintray</name>
<url>https://dl.bintray.com/ubique-oss/springboot-swagger3</url>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>

<repositories>
<repository>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>ubique-oss-springboot-swagger3</id>
<name>bintray</name>
<url>https://dl.bintray.com/ubique-oss/springboot-swagger3</url>
</repository>
</repositories>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,48 @@

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

import java.util.Map;

import javax.sql.DataSource;

import org.dpppt.backend.sdk.ws.security.KeyVault;
import org.dpppt.backend.sdk.ws.security.KeyVault.PrivateKeyNoSuitableEncodingFoundException;
import org.dpppt.backend.sdk.ws.security.KeyVault.PublicKeyNoSuitableEncodingFoundException;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.CloudFactory;
import org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig;
import org.springframework.cloud.service.relational.DataSourceConfig;
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;

abstract String getPublicKey();

abstract String getPrivateKey();

@Value("${ws.cloud.base.config.publicKey.fromCertificate:true}")
private boolean publicKeyFromCertificate;

@Value("${datasource.maximumPoolSize}")
int dataSourceMaximumPoolSize;

@Value("${datasource.connectionTimeout}")
int dataSourceConnectionTimeout;

@Value("${datasource.leakDetectionThreshold:0}")
int dataSourceLeakDetectionThreshold;

@Bean
@Override
public DataSource dataSource() {
return dataSource;
PoolConfig poolConfig = new PoolConfig(dataSourceMaximumPoolSize, dataSourceConnectionTimeout);
DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null, null,
Map.of("leakDetectionThreshold", dataSourceLeakDetectionThreshold));
CloudFactory factory = new CloudFactory();
return factory.getCloud().getSingletonServiceConnector(DataSource.class, dbConfig);
}

@Bean
Expand All @@ -60,8 +73,8 @@ public String getDbType() {
protected KeyVault keyVault() {
var privateKey = getPrivateKey();
var publicKey = getPublicKey();
if(privateKey.isEmpty() || publicKey.isEmpty()) {

if (privateKey.isEmpty() || publicKey.isEmpty()) {
var kp = super.getKeyPair(algorithm);
var gaenKp = new KeyVault.KeyVaultKeyPair("gaen", kp);
var nextDayJWTKp = new KeyVault.KeyVaultKeyPair("nextDayJWT", kp);
Expand All @@ -71,7 +84,7 @@ protected KeyVault keyVault() {

var gaen = new KeyVault.KeyVaultEntry("gaen", getPrivateKey(), getPublicKey(), "EC");
var nextDayJWT = new KeyVault.KeyVaultEntry("nextDayJWT", getPrivateKey(), getPublicKey(), "EC");
var hashFilter = new KeyVault.KeyVaultEntry("hashFilter", getPrivateKey(), getPublicKey(), "EC");
var hashFilter = new KeyVault.KeyVaultEntry("hashFilter", getPrivateKey(), getPublicKey(), "EC");

try {
return new KeyVault(gaen, nextDayJWT, hashFilter);
Expand Down

0 comments on commit 100bcde

Please sign in to comment.