Skip to content

Commit

Permalink
Merge branch 'main' into issue_228
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh authored Nov 11, 2024
2 parents 9f27b99 + b0979c6 commit f2e74a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dmci/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,14 @@ def _check_metadata_id(metadata_id, env_string=None):
return None, None, f"Cannot convert to UUID: {uuid_str}"

# Check that the namespace is correct
if env_string is not None:
if env_string is None: # we are in prod
if ".staging" in md_namespace or ".dev" in md_namespace:
return (
None,
None,
f"Dataset metadata_id namespace is wrong for production: {md_namespace}"
)
else:
env = md_namespace.split(".")[-1]
if env_string != env:
return None, None, f"Dataset metadata_id namespace is wrong: {env}"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_api/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ def testApiApp_CheckMetadataId():
"Dataset metadata_id " "namespace is wrong: " "test",
)

# With namespace but the wrong one for prod environement
assert App._check_metadata_id("test.dev:"+testUUID, env_string=None) == (None, None,
"Dataset metadata_id "
"namespace is wrong "
"for production: "
"test.dev")
assert App._check_metadata_id("test.staging:"+testUUID) == (None, None,
"Dataset metadata_id "
"namespace is wrong "
"for production: "
"test.staging")

# With namespace, defined env_string, but present in call
assert App._check_metadata_id("test.TEST:" + testUUID, env_string="TEST") == (
"test.TEST",
Expand Down

0 comments on commit f2e74a3

Please sign in to comment.