aboutsummaryrefslogtreecommitdiffstats
path: root/config_binding_service/controller.py
diff options
context:
space:
mode:
authorTommy Carpenter <tommy@research.att.com>2018-02-27 21:20:00 -0500
committerTommy Carpenter <tommy@research.att.com>2018-03-01 11:23:40 -0500
commit16841e4acee2cc31558bdaf618d68e4349c06168 (patch)
treea9bff5ca8af6256122cc0e406bac81f8fb6fba31 /config_binding_service/controller.py
parent584b93a74f760beb51f973412a092533c838faeb (diff)
Add a new endpoint for getting arbitrary keys
Change-Id: I4888bf3c596bee72637a881830cef4835076bcb2 Issue-ID: DCAEGEN2-348 Signed-off-by: Tommy Carpenter <tommy@research.att.com>
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)