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:
authorTony Hansen <tony@att.com>2022-10-04 00:19:36 +0000
committerGerrit Code Review <gerrit@onap.org>2022-10-04 00:19:36 +0000
commit446e7a61af43f6ef1f1b9429201834ee86b60c4b (patch)
tree7328bba66086bb037ecb4b84168d418694f5940e /rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/CbsClientConfiguration.java
parentcc22bef3a8598a032d0801ced9522cf77f47a6cd (diff)
parent592f371519d0647b7ae9a0a2fc601c757133cf0d (diff)
Merge "Remove CBS and Consul dependencies from CBSClient lib"
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, 4 insertions, 99 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 6eec6674..fa265d85 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,6 +4,7 @@
* =========================================================
* 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.
@@ -50,7 +51,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.
@@ -58,16 +59,6 @@ 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";
@@ -82,61 +73,16 @@ 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";
}
@@ -145,6 +91,7 @@ public interface CbsClientConfiguration {
return "/etc/policies/policies.json";
}
+
/**
* Creates CbsClientConfiguration from system environment variables.
*
@@ -155,7 +102,6 @@ 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))
@@ -163,41 +109,7 @@ public interface CbsClientConfiguration {
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));
- }
-
- 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("/"));
+ return configBuilder.build();
}
static String getEnv(String envName) {
@@ -212,12 +124,5 @@ 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.");
- }
- }
}