Skip to content

Commit

Permalink
Merge pull request #71 from bcgov/dev
Browse files Browse the repository at this point in the history
Fix potential issue with plugins being applied
  • Loading branch information
ikethecoder authored Nov 24, 2022
2 parents f271ac4 + aa81b7e commit 0030664
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion microservices/gatewayApi/clients/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ def record_gateway_event(event_id, action, result, namespace, message="", blob="
'name': 'N/A',
'message': message,
'refId': '',
'namespace': namespace
'namespace': namespace,
'context': {
'message': 'GatewayConfig {action} {result} : {message}',
'params': {
'result': result,
'message': message,
'action': action
}
},
'filterKey1': 'namespace:%s' % namespace
}

if not blob == "" and not blob == None:
Expand Down
8 changes: 7 additions & 1 deletion microservices/gatewayApi/v1/routes/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def write_config(namespace: str) -> object:

# Validate that the every object is tagged with the namespace
try:
validate_base_entities(gw_config)
validate_tags(gw_config, selectTag)
except Exception as ex:
traceback.print_exc()
Expand Down Expand Up @@ -391,7 +392,12 @@ def cleanup(dir_path):
except OSError as e:
log.error("Error: %s : %s" % (dir_path, e.strerror))


def validate_base_entities(yaml):
traversables = ['__plugin_configs', 'services', 'upstreams', 'certificates', 'caCertificates']
for k in yaml:
if k not in traversables:
raise Exception("Invalid base entity %s" % k)

def validate_tags(yaml, required_tag):
# throw an exception if there are invalid tags
errors = []
Expand Down
6 changes: 6 additions & 0 deletions microservices/gatewayApi/v2/routes/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def write_config(namespace: str) -> object:

# Validate that the every object is tagged with the namespace
try:
validate_base_entities(gw_config)
validate_tags(gw_config, selectTag)
except Exception as ex:
traceback.print_exc()
Expand Down Expand Up @@ -395,6 +396,11 @@ def cleanup(dir_path):
except OSError as e:
log.error("Error: %s : %s" % (dir_path, e.strerror))

def validate_base_entities(yaml):
traversables = ['__plugin_configs', 'services', 'upstreams', 'certificates', 'caCertificates']
for k in yaml:
if k not in traversables:
raise Exception("Invalid base entity %s" % k)

def validate_tags(yaml, required_tag):
# throw an exception if there are invalid tags
Expand Down

0 comments on commit 0030664

Please sign in to comment.