aboutsummaryrefslogtreecommitdiffstats
path: root/config_binding_service/controller.py
diff options
context:
space:
mode:
Diffstat (limited to 'config_binding_service/controller.py')
-rw-r--r--config_binding_service/controller.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/config_binding_service/controller.py b/config_binding_service/controller.py
index 4ece194..dbdb57b 100644
--- a/config_binding_service/controller.py
+++ b/config_binding_service/controller.py
@@ -16,13 +16,14 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-from config_binding_service import client, get_consul_uri, get_logger
import requests
-from flask import request, Response
+from flask import Response
import json
+from config_binding_service import client, get_consul_uri, get_logger
_logger = get_logger(__name__)
+
def bind_all(service_component_name):
try:
allk = client.resolve_all(service_component_name)
@@ -37,12 +38,13 @@ def bind_all(service_component_name):
return Response(response="Unknown error: please report",
status=500)
+
def bind_config_for_scn(service_component_name):
try:
bound = client.resolve(service_component_name)
return Response(response=json.dumps(bound),
- status=200,
- mimetype="application/json")
+ status=200,
+ mimetype="application/json")
except client.CantGetConfig as e:
return Response(status=e.code,
response=e.response)
@@ -51,14 +53,33 @@ def bind_config_for_scn(service_component_name):
return Response(response="Please report this error",
status=500)
+
+def get_key(key, service_component_name):
+ try:
+ bound = client.get_key(key, service_component_name)
+ return Response(response=json.dumps(bound),
+ status=200,
+ mimetype="application/json")
+ except client.CantGetConfig as e:
+ return Response(status=e.code,
+ response=e.response)
+ except client.BadRequest as exc:
+ return Response(status=exc.code,
+ response=exc.response,
+ mimetype="text/plain")
+ except Exception as e: #should never happen...
+ _logger.error(e)
+ return Response(response="Please report this error",
+ status=500)
+
+
def healthcheck():
#got this far, I must be alive... check my connection to Consul by checking myself
CONSUL = get_consul_uri()
res = requests.get("{0}/v1/catalog/service/config_binding_service".format(CONSUL))
if res.status_code == 200:
- return Response(response = "CBS is alive and Consul connection OK",
- status = 200)
+ return Response(response="CBS is alive and Consul connection OK",
+ status=200)
else:
- return Response(response = "CBS is alive but cannot reach Consul",
- status = 503)
-
+ return Response(response="CBS is alive but cannot reach Consul",
+ status=503)