diff --git a/dmci/api/app.py b/dmci/api/app.py index 0589f57..1f49356 100644 --- a/dmci/api/app.py +++ b/dmci/api/app.py @@ -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}" diff --git a/tests/test_api/test_app.py b/tests/test_api/test_app.py index 56ce727..1c4d71f 100644 --- a/tests/test_api/test_app.py +++ b/tests/test_api/test_app.py @@ -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",