From 908088a44ecd1bd364ab73cac073b89c92b187f0 Mon Sep 17 00:00:00 2001 From: Tommy Carpenter Date: Tue, 23 Apr 2019 10:24:08 -0400 Subject: Do not hardcode CBS name Change-Id: I80dd0d74368528b161a37a597d07c3de242b1e3e Issue-ID: DCAEGEN2-1450 Signed-off-by: Tommy Carpenter --- .../onap_dcae_cbs_docker_client/client.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client') diff --git a/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py b/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py index 3f2fcf2..80c9f75 100644 --- a/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py +++ b/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py @@ -53,11 +53,13 @@ def _get_envs(): Returns hostname, consul_host. If the necessary ENVs are not found, this is fatal, and raises an exception. """ - if "HOSTNAME" not in os.environ or "CONSUL_HOST" not in os.environ: - raise ENVsMissing("HOSTNAME or CONSUL_HOST missing") - hostname = os.environ["HOSTNAME"] - consul_host = os.environ["CONSUL_HOST"] - return hostname, consul_host + try: + hostname = os.environ["HOSTNAME"] # this is the name of the component itself + consul_host = os.environ["CONSUL_HOST"] # this is the host of consul itself + cbs_name = os.environ["CONFIG_BINDING_SERVICE"] # this is the name under which the CBS is registered in Consul. + except KeyError as e: + raise ENVsMissing("Required ENV Variable {0} missing".format(e)) + return hostname, consul_host, cbs_name def _get_path(path): @@ -72,14 +74,14 @@ def _get_path(path): config = {} - hostname, consul_host = _get_envs() + hostname, consul_host, cbs_name = _get_envs() # not sure how I as the component developer is supposed to know consul port consul_url = "http://{0}:8500".format(consul_host) try: # get my config - cbs_url = _get_uri_from_consul(consul_url, "config_binding_service") + cbs_url = _get_uri_from_consul(consul_url, cbs_name) my_config_endpoint = "{0}/{1}/{2}".format(cbs_url, path, hostname) res = requests.get(my_config_endpoint) -- cgit 1.2.3-korg