aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java')
-rw-r--r--rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java103
1 files changed, 99 insertions, 4 deletions
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 fa265d85..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
@@ -4,7 +4,6 @@
* =========================================================
* Copyright (C) 2019-2021 Nokia. All rights reserved.
* Copyright (C) 2021 Wipro Limited.
- * Copyright (C) 2022 AT&T Intellectual Property. 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.
@@ -51,7 +50,7 @@ public interface CbsClientConfiguration {
String TRUST_JKS = "trust.jks";
String TRUST_PASS = "trust.pass";
-
+ Integer PORT_FOR_CBS_OVER_TLS = 10443;
/**
* Name of environment variable containing path to the cacert.pem file.
@@ -59,6 +58,16 @@ public interface CbsClientConfiguration {
String DCAE_CA_CERT_PATH = "DCAE_CA_CERTPATH";
/**
+ * Name of environment variable containing Config Binding Service network hostname.
+ */
+ String ENV_CBS_HOSTNAME = "CONFIG_BINDING_SERVICE";
+
+ /**
+ * Name of environment variable containing Config Binding Service network port.
+ */
+ String ENV_CBS_PORT = "CONFIG_BINDING_SERVICE_SERVICE_PORT";
+
+ /**
* Name of environment variable containing current application name.
*/
String ENV_APP_NAME = "HOSTNAME";
@@ -73,16 +82,61 @@ public interface CbsClientConfiguration {
*/
String ENV_CBS_CLIENT_POLICY_PATH = "CBS_CLIENT_POLICY_PATH";
+ /**
+ * Name of environment variable containing Consul host name.
+ *
+ * @deprecated CBS lookup in Consul service should not be needed,
+ * instead {@link #ENV_CBS_HOSTNAME} should be used directly.
+ */
+ @Deprecated
+ String ENV_CONSUL_HOST = "CONSUL_HOST";
+
+ /**
+ * Name of environment variable containing Config Binding Service <em>service name</em> as registered in Consul
+ * services API.
+ *
+ * @deprecated CBS lookup in Consul service should not be needed,
+ * instead {@link #ENV_CBS_HOSTNAME} should be used directly.
+ */
+ @Deprecated
+ String ENV_CBS_NAME = "CONFIG_BINDING_SERVICE";
+
+ @Value.Parameter
+ @Nullable
+ String hostname();
+
+ @Value.Parameter
+ @Nullable
+ Integer port();
@Value.Parameter
String appName();
+ @Value.Parameter
+ @Nullable
+ String protocol();
+
@Value.Default
default @Nullable TrustStoreKeys trustStoreKeys() {
return null;
}
@Value.Default
+ @Deprecated
+ default String consulHost() {
+ return "consul-server";
+ }
+ @Value.Default
+ @Deprecated
+ default Integer consulPort() {
+ return 8500;
+ }
+ @Value.Default
+ @Deprecated
+ default String cbsName() {
+ return "config-binding-service";
+ }
+ @Value.Default
default String configMapFilePath() {
return "/app-config/application_config.yaml";
}
@@ -91,7 +145,6 @@ public interface CbsClientConfiguration {
return "/etc/policies/policies.json";
}
-
/**
* Creates CbsClientConfiguration from system environment variables.
*
@@ -102,6 +155,7 @@ public interface CbsClientConfiguration {
String pathToCaCert = System.getenv(DCAE_CA_CERT_PATH);
ImmutableCbsClientConfiguration.Builder configBuilder = ImmutableCbsClientConfiguration.builder()
+ .hostname(getEnv(ENV_CBS_HOSTNAME))
.appName(getEnv(ENV_APP_NAME));
Optional.ofNullable(System.getenv(ENV_CBS_CLIENT_CONFIG_PATH))
@@ -109,7 +163,41 @@ public interface CbsClientConfiguration {
Optional.ofNullable(System.getenv(ENV_CBS_CLIENT_POLICY_PATH))
.ifPresent(configBuilder::policySyncFilePath);
- return configBuilder.build();
+
+ return Optional.ofNullable(pathToCaCert).filter(certPath -> !"".equals(certPath))
+ .map(certPath -> createSslHttpConfig(configBuilder, certPath))
+ .orElseGet(() -> createPlainHttpConfig(configBuilder));
+ }
+
+ static CbsClientConfiguration createPlainHttpConfig(ImmutableCbsClientConfiguration.Builder configBuilder) {
+ LOGGER.info("CBS client will use plain http protocol.");
+ return configBuilder
+ .protocol("http")
+ .port(Integer.valueOf(getEnv(ENV_CBS_PORT)))
+ .build();
+ }
+
+ static CbsClientConfiguration createSslHttpConfig(ImmutableCbsClientConfiguration.Builder configBuilder,
+ String pathToCaCert) {
+ LOGGER.info("CBS client will use http over TLS.");
+ return configBuilder
+ .trustStoreKeys(crateSecurityKeysFromEnvironment(createPathToJksFile(pathToCaCert)))
+ .port(PORT_FOR_CBS_OVER_TLS)
+ .protocol("https")
+ .build();
+ }
+
+ static TrustStoreKeys crateSecurityKeysFromEnvironment(String pathToCerts) {
+ LOGGER.info("Path to cert files: {}", pathToCerts + "/");
+ validateIfFilesExist(pathToCerts);
+ return ImmutableTrustStoreKeys.builder()
+ .trustStore(SecurityKeysStore.fromPath(Paths.get(pathToCerts + "/" + TRUST_JKS)))
+ .trustStorePassword(Passwords.fromPath(Paths.get(pathToCerts + "/" + TRUST_PASS)))
+ .build();
+ }
+
+ static String createPathToJksFile(String pathToCaCertPemFile) {
+ return pathToCaCertPemFile.substring(0, pathToCaCertPemFile.lastIndexOf("/"));
}
static String getEnv(String envName) {
@@ -124,5 +212,12 @@ public interface CbsClientConfiguration {
}
}
+ static void validateIfFilesExist(String pathToFile) {
+ boolean areFilesExist = Files.exists(Paths.get(pathToFile + "/" + TRUST_JKS)) &&
+ Files.exists(Paths.get(pathToFile + "/" + TRUST_PASS));
+ if (!areFilesExist) {
+ throw new CbsClientConfigurationException("Required files do not exist in " + pathToFile + " directory.");
+ }
+ }
}