Skip to content

Commit

Permalink
adj logic for qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed Sep 14, 2023
1 parent dfdbc20 commit 571ad48
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions microservices/gatewayApi/v2/routes/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def write_config(namespace: str) -> object:

# If there is a tag with a pipeline qualifier (i.e./ ns.<namespace>.dev)
# then add to tags automatically the tag: ns.<namespace>
tags_transformation(namespace, gw_config)
object_count = tags_transformation(namespace, gw_config)

#
# Enrich the rate-limiting plugin with the appropriate Redis details
Expand All @@ -258,7 +258,7 @@ def write_config(namespace: str) -> object:
# Validate that the every object is tagged with the namespace
try:
validate_base_entities(gw_config, ns_attributes)
all_select_tags = validate_tags(gw_config, selectTag)
validate_tags(gw_config, selectTag)
except Exception as ex:
traceback.print_exc()
log.error("%s - %s" % (namespace, " Tag Validation Errors: %s" % ex))
Expand Down Expand Up @@ -293,9 +293,9 @@ def write_config(namespace: str) -> object:
("Conflicting ns qualifiers (%s != %s)" % (ns_qualifier, nsq))))
ns_qualifier = nsq
log.info("[%s] CHANGING ns_qualifier %s" % (namespace, ns_qualifier))
elif ns_qualifier is not None and len(all_select_tags) != 0:
elif ns_qualifier is not None and object_count > 0:
abort_early(event_id, 'publish', namespace, jsonify(error="Validation Errors:\n%s" %
("Specified qualifier (%s) does not match tags in configuration (%s)" % (ns_qualifier, all_select_tags))))
("Specified qualifier (%s) does not match tags in configuration (%s)" % (ns_qualifier, selectTag))))

if update_routes_check(gw_config):
update_routes_flag = True
Expand Down Expand Up @@ -424,8 +424,6 @@ def validate_tags(yaml, required_tag):
if len(errors) != 0:
raise Exception('\n'.join(errors))

return qualifiers

def traverse(source, errors, yaml, required_tag, qualifiers):
traversables = ['services', 'routes', 'plugins', 'upstreams', 'consumers', 'certificates', 'caCertificates']
for k in yaml:
Expand Down Expand Up @@ -595,10 +593,11 @@ def host_ends_with_one_of_list(a_str, a_list):


def tags_transformation(namespace, yaml):
traverse_tags_transform(yaml, namespace, "ns.%s" % namespace)
return traverse_tags_transform(yaml, namespace, "ns.%s" % namespace)


def traverse_tags_transform(yaml, namespace, required_tag):
object_count = 0
log = app.logger
traversables = ['services', 'routes', 'plugins', 'upstreams', 'consumers', 'certificates', 'caCertificates']
for k in yaml:
Expand All @@ -613,8 +612,9 @@ def traverse_tags_transform(yaml, namespace, required_tag):
log.debug("[%s] Adding base tag %s to %s" % (namespace, required_tag, k))
new_tags.append(required_tag)
item['tags'] = new_tags
traverse_tags_transform(item, namespace, required_tag)

object_count = object_count + 1
object_count = object_count + traverse_tags_transform(item, namespace, required_tag)
return object_count

def traverse_has_ns_qualifier(yaml, required_tag):
log = app.logger
Expand Down

0 comments on commit 571ad48

Please sign in to comment.