Skip to content

Commit

Permalink
Merge pull request #56 from bcgov/dev
Browse files Browse the repository at this point in the history
Release route paging fix
  • Loading branch information
ikethecoder authored Nov 30, 2021
2 parents 6812322 + c75986e commit 0f3bf52
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
6 changes: 6 additions & 0 deletions microservices/gatewayApi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def expired_token(error):
content = jsonify({"error":"Token Expired"})
return make_response(content, HTTPStatus.UNAUTHORIZED)

@app.errorhandler(Exception)
def other_exception(error):
log.error(error)
content = jsonify({"error":"Unexpected Error"})
return make_response(content, HTTPStatus.BAD_REQUEST)

@app.route('/', methods=['GET'], strict_slashes=False)
def index():
"""
Expand Down
3 changes: 3 additions & 0 deletions microservices/gatewayApi/v1/routes/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def update_namespace(namespace: str) -> object:
log.error("Namespace validation failed %s", namespace)
abort(make_response(jsonify(error="Namespace name validation failed. Reference regular expression '%s'." % namespace_validation_rule), 400))

log.info("Updating namespace %s" % namespace)

try:
svc = NamespaceService()

ns_group = svc.get_namespace (namespace)
log.info("-> Found %s" % ns_group)

svc.update_ns_attributes (ns_group, params)

Expand Down
30 changes: 19 additions & 11 deletions microservices/gatewayJobScheduler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@ def get_namespace_attributes(self, namespace):

def get_routes():
try:
p1 = Popen(shlex.split("curl %s/routes" % os.getenv('KONG_ADMIN_API_URL')), stdout=PIPE)
run = Popen(shlex.split(
"jq '.data'"), stdin=p1.stdout, stdout=PIPE, stderr=PIPE)
out, err = run.communicate()
endpoint = "/routes"
routes_list = []
while True:
p1 = Popen(shlex.split("curl %s%s" % (os.getenv('KONG_ADMIN_API_URL'), endpoint)), stdout=PIPE)
run = Popen(shlex.split(
"jq ."), stdin=p1.stdout, stdout=PIPE, stderr=PIPE)
out, err = run.communicate()

if run.returncode != 0:
logger.error("Failed to get existing routes - %s - %s", out, err)
clear('sync-routes')
exit(1)

result = json.loads(out)
routes_list = routes_list + result['data']

if result['next'] == None:
return routes_list
endpoint = result['next']

if run.returncode != 0:
logger.error("Failed to get existing routes - %s - %s", out, err)
clear('sync-routes')
exit(1)

return json.loads(out)
except:
traceback.print_exc()
logger.error('Failed to get existing routes - %s' % (exc_info()[0]))
Expand All @@ -66,7 +75,6 @@ def sync_routes():
'content-type': 'application/json'
}
data = transform_data_by_ns(get_routes())

for ns in data:
url = os.getenv('KUBE_API_URL') + '/namespaces/%s/routes/sync' % ns
response = requests.post(url, headers=headers, json=data[ns], auth=(
Expand Down

0 comments on commit 0f3bf52

Please sign in to comment.