summaryrefslogtreecommitdiffstats
path: root/rest-services
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services')
-rw-r--r--rest-services/cbs-client/pom.xml2
-rw-r--r--rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java5
-rw-r--r--rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java16
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java117
-rw-r--r--rest-services/dmaap-client/pom.xml2
-rw-r--r--rest-services/http-client/pom.xml2
-rw-r--r--rest-services/model/pom.xml2
-rw-r--r--rest-services/pom.xml2
8 files changed, 115 insertions, 33 deletions
diff --git a/rest-services/cbs-client/pom.xml b/rest-services/cbs-client/pom.xml
index 717e3a4f..1aaf74b9 100644
--- a/rest-services/cbs-client/pom.xml
+++ b/rest-services/cbs-client/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.6-SNAPSHOT</version>
+ <version>1.8.7-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java
index 00dbf8a0..e43cf312 100644
--- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java
+++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java
@@ -28,6 +28,8 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.CbsClientRes
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.CbsLookup;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
import org.onap.dcaegen2.services.sdk.security.ssl.TrustStoreKeys;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
/**
@@ -38,6 +40,8 @@ import reactor.core.publisher.Mono;
* @since 1.1.2
*/
public class CbsClientFactory {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CbsClientFactory.class);
+
/**
* <p>Creates Mono which will emit instance of {@link CbsClient} when service discovery is complete.</p>
*
@@ -55,6 +59,7 @@ public class CbsClientFactory {
* @since 1.1.2
*/
public static @NotNull Mono<CbsClient> createCbsClient(CbsClientConfiguration configuration) {
+ LOGGER.info("Configuration used for CBS Client: {}", configuration);
return Mono.fromCallable(() -> buildHttpClient(configuration.trustStoreKeys()))
.cache()
.flatMap(httpClient -> createCbsClientMono(httpClient, configuration));
diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java
index 41848855..6eec6674 100644
--- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java
+++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java
@@ -72,6 +72,15 @@ public interface CbsClientConfiguration {
*/
String ENV_APP_NAME = "HOSTNAME";
+ /**
+ * Name of environment variable containing path to application config file.
+ */
+ String ENV_CBS_CLIENT_CONFIG_PATH = "CBS_CLIENT_CONFIG_PATH";
+
+ /**
+ * Name of environment variable containing path to policies file.
+ */
+ String ENV_CBS_CLIENT_POLICY_PATH = "CBS_CLIENT_POLICY_PATH";
/**
* Name of environment variable containing Consul host name.
@@ -148,6 +157,13 @@ public interface CbsClientConfiguration {
ImmutableCbsClientConfiguration.Builder configBuilder = ImmutableCbsClientConfiguration.builder()
.hostname(getEnv(ENV_CBS_HOSTNAME))
.appName(getEnv(ENV_APP_NAME));
+
+ Optional.ofNullable(System.getenv(ENV_CBS_CLIENT_CONFIG_PATH))
+ .ifPresent(configBuilder::configMapFilePath);
+
+ Optional.ofNullable(System.getenv(ENV_CBS_CLIENT_POLICY_PATH))
+ .ifPresent(configBuilder::policySyncFilePath);
+
return Optional.ofNullable(pathToCaCert).filter(certPath -> !"".equals(certPath))
.map(certPath -> createSslHttpConfig(configBuilder, certPath))
.orElseGet(() -> createPlainHttpConfig(configBuilder));
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
index 107c2d32..2e57adaa 100644
--- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================
* DCAEGEN2-SERVICES-SDK
* =========================================================
- * Copyright (C) 2019 Nokia. All rights reserved.
+ * Copyright (C) 2019-2021 Nokia. All rights reserved.
* =========================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api;
import org.junit.Rule;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.CbsClientConfigurationException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
@@ -40,17 +41,28 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
class CbsClientConfigurationTest {
+ public static final String ENV_DCAE_CA_CERTPATH = "DCAE_CA_CERTPATH";
+ public static final String ENV_CONFIG_BINDING_SERVICE = "CONFIG_BINDING_SERVICE";
+ public static final String ENV_CONFIG_BINDING_SERVICE_SERVICE_PORT = "CONFIG_BINDING_SERVICE_SERVICE_PORT";
+ public static final String ENV_HOSTNAME = "HOSTNAME";
+ public static final String ENV_CONSUL_HOST = "CONSUL_HOST";
+ public static final String ENV_CBS_CLIENT_CONFIG_PATH = "CBS_CLIENT_CONFIG_PATH";
+ public static final String ENV_CBS_CLIENT_POLICY_PATH = "CBS_CLIENT_POLICY_PATH";
+
@Rule
public final EnvironmentVariables envs = new EnvironmentVariables();
+ @BeforeEach
+ void setUp(){
+ envs.clear(ENV_DCAE_CA_CERTPATH, ENV_CONFIG_BINDING_SERVICE, ENV_CONFIG_BINDING_SERVICE_SERVICE_PORT,
+ ENV_HOSTNAME, ENV_CONSUL_HOST, ENV_CBS_CLIENT_CONFIG_PATH, ENV_CBS_CLIENT_POLICY_PATH);
+ }
+
@Test
void fromEnvironment_shouldReturnConfigurationForConnectionWithoutTls_when_DCAE_CA_CERTPATH_isEmpty() {
// given
- envs.set("DCAE_CA_CERTPATH", "");
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "10000");
- envs.set("HOSTNAME", "dcae-prh");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ createBasicValidEnvsConfiguration();
+ envs.set(ENV_DCAE_CA_CERTPATH, "");
// when
CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
@@ -63,10 +75,10 @@ class CbsClientConfigurationTest {
@Test
void fromEnvironment_shouldReturnConfigurationForConnectionOverTls_when_DCAE_CA_CERTPATH_isSet() throws URISyntaxException {
// given
- envs.set("DCAE_CA_CERTPATH", preparePathToCertFile());
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("HOSTNAME", "dcae-prh");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ envs.set(ENV_DCAE_CA_CERTPATH, preparePathToCertFile());
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_HOSTNAME, "dcae-prh");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
// when
CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
@@ -77,13 +89,55 @@ class CbsClientConfigurationTest {
}
@Test
+ void fromEnvironment_shouldReturnConfigurationWithCorrectConfigPath_when_CBS_CLIENT_CONFIG_PATH_isSet() {
+ // given
+ createBasicValidEnvsConfiguration();
+ envs.set(ENV_CBS_CLIENT_CONFIG_PATH, "/new/config/path/application.yaml");
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration).isNotNull();
+ assertThat(configuration.configMapFilePath()).isEqualTo("/new/config/path/application.yaml");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturnConfigurationWithCorrectPolicyPath_when_CBS_CLIENT_POLICY_PATH_isSet() {
+ // given
+ createBasicValidEnvsConfiguration();
+ envs.set(ENV_CBS_CLIENT_POLICY_PATH, "/new/config/path/policy.json");
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration).isNotNull();
+ assertThat(configuration.policySyncFilePath()).isEqualTo("/new/config/path/policy.json");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturnConfigurationWithDefaultPolicyAndConfigPaths_whenEnvsNotSet() {
+ // given
+ createBasicValidEnvsConfiguration();
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration).isNotNull();
+ assertThat(configuration.configMapFilePath()).isEqualTo("/app-config/application_config.yaml");
+ assertThat(configuration.policySyncFilePath()).isEqualTo("/etc/policies/policies.json");
+ }
+
+ @Test
void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_DCAE_CA_CERTPATH_is_Null() {
// given
- envs.set("DCAE_CA_CERTPATH", null);
- envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "9090");
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("HOSTNAME", "dcae-prh");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ envs.set(ENV_DCAE_CA_CERTPATH, null);
+ envs.set(ENV_CONFIG_BINDING_SERVICE_SERVICE_PORT, "9090");
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_HOSTNAME, "dcae-prh");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
// when
CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
@@ -102,10 +156,10 @@ class CbsClientConfigurationTest {
@Test
void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_DCAE_CA_CERTPATH_isWrong() {
// given
- envs.set("DCAE_CA_CERTPATH", "/home/cacert.pem");
- envs.set("HOSTNAME", "dcae-prh");
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ envs.set(ENV_DCAE_CA_CERTPATH, "/home/cacert.pem");
+ envs.set(ENV_HOSTNAME, "dcae-prh");
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
// then
assertThatExceptionOfType(CbsClientConfigurationException.class)
@@ -116,10 +170,10 @@ class CbsClientConfigurationTest {
@Test
void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_HOSTNAME_isMissing() throws URISyntaxException {
// given
- envs.set("HOSTNAME", "");
- envs.set("DCAE_CA_CERTPATH", preparePathToCertFile());
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ envs.set(ENV_HOSTNAME, "");
+ envs.set(ENV_DCAE_CA_CERTPATH, preparePathToCertFile());
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
// then
assertThatExceptionOfType(CbsClientConfigurationException.class)
@@ -130,11 +184,11 @@ class CbsClientConfigurationTest {
@Test
void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_CONFIG_BINDING_SERVICE_SERVICE_PORT_isEmpty() {
// given
- envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "");
- envs.set("DCAE_CA_CERTPATH", "");
- envs.set("HOSTNAME", "dcae-prh");
- envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
- envs.set("CONSUL_HOST", "consul-server.onap");
+ envs.set(ENV_CONFIG_BINDING_SERVICE_SERVICE_PORT, "");
+ envs.set(ENV_DCAE_CA_CERTPATH, "");
+ envs.set(ENV_HOSTNAME, "dcae-prh");
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
// then
assertThatExceptionOfType(CbsClientConfigurationException.class)
@@ -142,6 +196,13 @@ class CbsClientConfigurationTest {
.withMessageContaining("Cannot read CONFIG_BINDING_SERVICE_SERVICE_PORT from environment.");
}
+ private void createBasicValidEnvsConfiguration() {
+ envs.set(ENV_CONFIG_BINDING_SERVICE, "config-binding-service");
+ envs.set(ENV_CONFIG_BINDING_SERVICE_SERVICE_PORT, "10000");
+ envs.set(ENV_HOSTNAME, "dcae-prh");
+ envs.set(ENV_CONSUL_HOST, "consul-server.onap");
+ }
+
private String preparePathToCertFile() throws URISyntaxException {
return Paths.get(Passwords.class.getResource("/test-certs/cacert.pem").toURI()) + "";
}
diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml
index 2462a440..7a9e584c 100644
--- a/rest-services/dmaap-client/pom.xml
+++ b/rest-services/dmaap-client/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.6-SNAPSHOT</version>
+ <version>1.8.7-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/http-client/pom.xml b/rest-services/http-client/pom.xml
index 15338406..f0edcdf5 100644
--- a/rest-services/http-client/pom.xml
+++ b/rest-services/http-client/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.6-SNAPSHOT</version>
+ <version>1.8.7-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/model/pom.xml b/rest-services/model/pom.xml
index 431039eb..cdf7a76e 100644
--- a/rest-services/model/pom.xml
+++ b/rest-services/model/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.6-SNAPSHOT</version>
+ <version>1.8.7-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/pom.xml b/rest-services/pom.xml
index 0f777a27..2dad8de1 100644
--- a/rest-services/pom.xml
+++ b/rest-services/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services</groupId>
<artifactId>sdk</artifactId>
- <version>1.8.6-SNAPSHOT</version>
+ <version>1.8.7-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>