From c9dd83fc33a39c8a8a1ab124f74f8792122891fe Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 28 Oct 2024 10:11:17 -0700 Subject: [PATCH 1/4] breaking: using latest uds-lib + update docker --- docker/stage-in-stage-out/dc-003-upload.yaml | 9 ++++++--- requirements.txt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docker/stage-in-stage-out/dc-003-upload.yaml b/docker/stage-in-stage-out/dc-003-upload.yaml index 77d6653b..7f9a95ab 100644 --- a/docker/stage-in-stage-out/dc-003-upload.yaml +++ b/docker/stage-in-stage-out/dc-003-upload.yaml @@ -23,17 +23,20 @@ services: VERIFY_SSL: 'FALSE' DAPA_API: 'https://k3a3qmarxh.execute-api.us-west-2.amazonaws.com/dev' - COLLECTION_ID: 'NEW_COLLECTION_EXAMPLE_L1B___9' + + PROJECT: 'NAME of the project if collection name in Granule STAC purely includes the name. It will be part of URN:NASA:UNITY:::' + VENUE: 'VENUE of the project if collection name in Granule STAC purely includes the name. It will be part of URN:NASA:UNITY:::' STAGING_BUCKET: 'uds-test-cumulus-staging' + DELETE_FILES: 'FALSE' - RESULT_PATH_PREFIX: 'stage_out/sample_dir (Optional:defaulted to stage_out if missing. NOTE: No need to begin or end with "/". )' + RESULT_PATH_PREFIX: 'stage_out/sample_dir (Optional:defaulted to stage_out if missing. NOTE: No need to begin or end with "/". It also accepts empty string now as default value)' GRANULES_SEARCH_DOMAIN: 'UNITY' GRANULES_UPLOAD_TYPE: 'UPLOAD_S3_BY_STAC_CATALOG' UPLOAD_DIR: '/etc/snpp_upload_test_1. or empty string' OUTPUT_DIRECTORY: '/some/directory' CATALOG_FILE: 'empty string or /path/to/stac/catalog file' - LOG_LEVEL: '20' + LOG_LEVEL: '20 NOTE: 10=DEBUG 20=info. 30=error' networks: - internal networks: diff --git a/requirements.txt b/requirements.txt index f7989aea..986ee5f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ jsonschema==4.23.0 jsonschema-specifications==2023.12.1 lark==0.12.0 mangum==0.18.0 -mdps-ds-lib==0.5.1.dev1 +mdps-ds-lib==0.5.1.dev10000 pydantic==2.9.2 pydantic_core==2.23.4 pygeofilter==0.2.4 From d803e28cf348d65609a24049bb557c57f01c40dc Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 28 Oct 2024 12:08:17 -0700 Subject: [PATCH 2/4] feat: use latest uds-lib --- docker/stage-in-stage-out/dc-003-upload.yaml | 1 + requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/stage-in-stage-out/dc-003-upload.yaml b/docker/stage-in-stage-out/dc-003-upload.yaml index 7f9a95ab..d02baca3 100644 --- a/docker/stage-in-stage-out/dc-003-upload.yaml +++ b/docker/stage-in-stage-out/dc-003-upload.yaml @@ -22,6 +22,7 @@ services: COGNITO_URL: 'ask U-CS. ex: https://cognito-idp.us-west-2.amazonaws.com' VERIFY_SSL: 'FALSE' + DRY_RUN: 'TRUE | FALSE . set to TRUE to confirm if all settings are correct bar aws credentials' DAPA_API: 'https://k3a3qmarxh.execute-api.us-west-2.amazonaws.com/dev' PROJECT: 'NAME of the project if collection name in Granule STAC purely includes the name. It will be part of URN:NASA:UNITY:::' diff --git a/requirements.txt b/requirements.txt index 986ee5f1..c0cca764 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ jsonschema==4.23.0 jsonschema-specifications==2023.12.1 lark==0.12.0 mangum==0.18.0 -mdps-ds-lib==0.5.1.dev10000 +mdps-ds-lib==0.5.1.dev010100 pydantic==2.9.2 pydantic_core==2.23.4 pygeofilter==0.2.4 From 76c3d543df9f348c1c1f194274a2f8c8913a6393 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 9 Dec 2024 14:02:11 -0800 Subject: [PATCH 3/4] feat: add A&A test case for collections --- requirements.txt | 2 +- tests/integration_tests/.env.tpl | 2 + tests/integration_tests/test_user_group_aa.py | 470 ++++++++++++++++++ 3 files changed, 473 insertions(+), 1 deletion(-) create mode 100644 tests/integration_tests/test_user_group_aa.py diff --git a/requirements.txt b/requirements.txt index 42e7ec78..c114b770 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ jsonschema==4.23.0 jsonschema-specifications==2023.12.1 lark==0.12.0 mangum==0.18.0 -mdps-ds-lib==1.1.1 +mdps-ds-lib==1.1.1.dev000100 pydantic==2.9.2 pydantic_core==2.23.4 pygeofilter==0.2.4 diff --git a/tests/integration_tests/.env.tpl b/tests/integration_tests/.env.tpl index 5bb2ddfa..fd551a4f 100644 --- a/tests/integration_tests/.env.tpl +++ b/tests/integration_tests/.env.tpl @@ -4,3 +4,5 @@ CLIENT_ID=7a1fglm2d54eoggj13lccivp25 COGNITO_URL=https://cognito-idp.us-west-2.amazonaws.com UNITY_URL=https://k3a3qmarxh.execute-api.us-west-2.amazonaws.com/dev UNITY_STAGE=sbx-uds-dapa +COGNITO_USER_POOL_ID=us-west-2_aaa + diff --git a/tests/integration_tests/test_user_group_aa.py b/tests/integration_tests/test_user_group_aa.py new file mode 100644 index 00000000..009ba65d --- /dev/null +++ b/tests/integration_tests/test_user_group_aa.py @@ -0,0 +1,470 @@ +from unittest import TestCase +import base64 +import json +import os +import tempfile +from datetime import datetime +from sys import argv +from unittest import TestCase + +import requests +from mdps_ds_lib.lib.aws.aws_cognito import AwsCognito +from mdps_ds_lib.lib.cumulus_stac.unity_collection_stac import UnityCollectionStac + +from cumulus_lambda_functions.lib.uds_db.db_constants import DBConstants +from dotenv import load_dotenv +from mdps_ds_lib.lib.aws.aws_s3 import AwsS3 +from mdps_ds_lib.lib.cognito_login.cognito_login import CognitoLogin +from mdps_ds_lib.lib.utils.file_utils import FileUtils +from mdps_ds_lib.lib.utils.time_utils import TimeUtils +from mdps_ds_lib.stage_in_out.upoad_granules_factory import UploadGranulesFactory +from pystac import Catalog, Asset, Link, ItemCollection, Item + + + +class TestUserGroupAA(TestCase): + """ + Steps: + + # Admin points to a:x a:y b:x b:y with CRUD + # MMM points to a:x as CRUD, b:y as R + # NNN points to a:y as R and b:x as CRUD + + # Add wphyo to Admin + # Create 1 collection on all 4 combo + # remove wphyo from Admin + # Add wphyo to MMM + # Try adding a new collection to a:x - success + # Try adding a new collection to a:y - failure + # Try adding a new collection to b:x - failure + # Try adding a new collection to b:y - failure + # Try getting a collecion from a:x - success + # Try getting a collecion from a:y - failure + # Try getting a collecion from b:y - failure + # Try getting a collecion from b:y - success + # Remove wphyo from MMM + # Add wphyo to NNN + # Try adding a new collection to a:x - failure + # Try adding a new collection to a:y - failure + # Try adding a new collection to b:x - success + # Try adding a new collection to b:y - failure + # Try getting a collecion from a:x - failure + # Try getting a collecion from a:y - success + # Try getting a collecion from b:y - success + # Try getting a collecion from b:y - failure + # Remove wphyo from NNN + # Add wphyo to Admin (which is original) + + """ + def setUp(self) -> None: + super().setUp() + load_dotenv() + self._url_prefix = f'{os.environ.get("UNITY_URL")}/{os.environ.get("UNITY_STAGE", "sbx-uds-dapa")}' + self.cognito_login = CognitoLogin() \ + .with_client_id(os.environ.get('CLIENT_ID', '')) \ + .with_cognito_url(os.environ.get('COGNITO_URL', '')) \ + .with_verify_ssl(False) \ + .start(base64.standard_b64decode(os.environ.get('USERNAME')).decode(), + base64.standard_b64decode(os.environ.get('PASSWORD')).decode()) + self.bearer_token = self.cognito_login.token + self.stage = os.environ.get("UNITY_URL").split('/')[-1] + self.uds_url = f'{os.environ.get("UNITY_URL")}/{os.environ.get("UNITY_STAGE", "sbx-uds-dapa")}/' + self.custom_metadata_body = { + 'tag': {'type': 'keyword'}, + 'c_data1': {'type': 'long'}, + 'c_data2': {'type': 'boolean'}, + 'c_data3': {'type': 'keyword'}, + } + self.sample_user = 'wphyo' + self.tenant_a, self.tenant_b = 'AAA', 'BBB' + self.tenant_venue_x, self.tenant_venue_y = 'XXX', 'YYY' + self.group_admin, self.group_m, self.group_n = 'Unity_Viewer', 'MMM', 'NNN' + self.collection_name, self.collection_version = 'UNIT_TEST', '001' + + self.cognito = AwsCognito(os.environ.get("COGNITO_USER_POOL_ID")) + + return + + + + def test_add_admin_group_00(self): + result = self.cognito.add_group(self.group_m) + result = self.cognito.add_group(self.group_n) + result = self.cognito.remove_user_from_group(self.sample_user, self.group_m) + result = self.cognito.remove_user_from_group(self.sample_user, self.group_n) + result = self.cognito.add_user_to_group(self.sample_user, self.group_admin) + return + + def test_add_admin(self): + collection_url = f'{self.uds_url}admin/auth' + print(collection_url) + + s = requests.session() + s.trust_env = False + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:.*"], + "tenant": self.tenant_a, + "venue": self.tenant_venue_x, + "group_name": self.group_admin + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:.*"], + "tenant": self.tenant_a, + "venue": self.tenant_venue_y, + "group_name": self.group_admin + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:.*"], + "tenant": self.tenant_b, + "venue": self.tenant_venue_x, + "group_name": self.group_admin + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:.*"], + "tenant": self.tenant_b, + "venue": self.tenant_venue_y, + "group_name": self.group_admin + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + return + + def test_add_m(self): + collection_url = f'{self.uds_url}admin/auth' + print(collection_url) + + s = requests.session() + s.trust_env = False + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:.*"], + "tenant": self.tenant_a, + "venue": self.tenant_venue_x, + "group_name": self.group_m + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + admin_add_body = { + "actions": ["READ"], + "resources": [f"URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:.*"], + "tenant": self.tenant_b, + "venue": self.tenant_venue_y, + "group_name": self.group_m + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + return + + def test_add_n(self): + collection_url = f'{self.uds_url}admin/auth' + print(collection_url) + + s = requests.session() + s.trust_env = False + + admin_add_body = { + "actions": ["READ"], + "resources": [f"URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:.*"], + "tenant": self.tenant_a, + "venue": self.tenant_venue_y, + "group_name": self.group_n + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + admin_add_body = { + "actions": ["READ", "CREATE"], + "resources": [f"URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:.*"], + "tenant": self.tenant_b, + "venue": self.tenant_venue_x, + "group_name": self.group_n + } + response = s.put(url=collection_url, headers={ + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + }, verify=False, data=json.dumps(admin_add_body)) + self.assertEqual(response.status_code, 200, f'wrong status code: {response.text}') + print(response.content.decode()) + + return + + def test_main_create_collection_all_4_tenant_venue(self): + post_url = f'{self.uds_url}collections/' # MCP Dev + headers = { + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + } + print(post_url) + dapa_collection = UnityCollectionStac() \ + .with_graule_id_regex("^test_file.*$") \ + .with_granule_id_extraction_regex("(^test_file.*)(\\.nc|\\.nc\\.cas|\\.cmr\\.xml)") \ + .with_title("test_file01.nc") \ + .with_process('stac') \ + .with_provider('unity') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'unknown_bucket', 'application/json', 'root') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'protected', 'data', 'item') \ + .add_file_type("test_file01.nc.cas", "^test_file.*\\.nc.cas$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.cmr.xml", "^test_file.*\\.nc.cmr.xml$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.stac.json", "^test_file.*\\.nc.stac.json$", 'protected', 'metadata', 'item') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + return + + def test_update_user_group_01(self): + result = self.cognito.remove_user_from_group(self.sample_user, self.group_admin) + result = self.cognito.add_user_to_group(self.sample_user, self.group_m) + return + + def test_add_get_collections_01(self): + post_url = f'{self.uds_url}collections/' # MCP Dev + headers = { + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + } + print(post_url) + dapa_collection = UnityCollectionStac() \ + .with_graule_id_regex("^test_file.*$") \ + .with_granule_id_extraction_regex("(^test_file.*)(\\.nc|\\.nc\\.cas|\\.cmr\\.xml)") \ + .with_title("test_file01.nc") \ + .with_process('stac') \ + .with_provider('unity') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'unknown_bucket', 'application/json', 'root') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'protected', 'data', 'item') \ + .add_file_type("test_file01.nc.cas", "^test_file.*\\.nc.cas$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.cmr.xml", "^test_file.*\\.nc.cmr.xml$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.stac.json", "^test_file.*\\.nc.stac.json$", 'protected', 'metadata', 'item') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + return + + def test_update_user_group_02(self): + result = self.cognito.remove_user_from_group(self.sample_user, self.group_m) + result = self.cognito.add_user_to_group(self.sample_user, self.group_n) + return + + def test_add_get_collections_02(self): + post_url = f'{self.uds_url}collections/' # MCP Dev + headers = { + 'Authorization': f'Bearer {self.bearer_token}', + 'Content-Type': 'application/json', + } + print(post_url) + dapa_collection = UnityCollectionStac() \ + .with_graule_id_regex("^test_file.*$") \ + .with_granule_id_extraction_regex("(^test_file.*)(\\.nc|\\.nc\\.cas|\\.cmr\\.xml)") \ + .with_title("test_file01.nc") \ + .with_process('stac') \ + .with_provider('unity') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'unknown_bucket', 'application/json', 'root') \ + .add_file_type("test_file01.nc", "^test_file.*\\.nc$", 'protected', 'data', 'item') \ + .add_file_type("test_file01.nc.cas", "^test_file.*\\.nc.cas$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.cmr.xml", "^test_file.*\\.nc.cmr.xml$", 'protected', 'metadata', 'item') \ + .add_file_type("test_file01.nc.stac.json", "^test_file.*\\.nc.stac.json$", 'protected', 'metadata', 'item') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 202, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + dapa_collection.with_id(temp_collection_id) + stac_collection = dapa_collection.start() + print(json.dumps(stac_collection)) + query_result = requests.post(url=post_url, + headers=headers, + json=stac_collection, + ) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_a}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_x}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + + temp_collection_id = f'URN:NASA:UNITY:{self.tenant_b}:{self.tenant_venue_y}:{self.collection_name}___{self.collection_version}' + query_result = requests.get(url=f'{post_url}{temp_collection_id}/', headers=headers) + self.assertEqual(query_result.status_code, 403, f'wrong status code. {query_result.text}') + print(json.loads(query_result.text)) + return + + def test_update_user_group_03(self): + result = self.cognito.remove_user_from_group(self.sample_user, self.group_n) + result = self.cognito.add_user_to_group(self.sample_user, self.group_admin) + result = self.cognito.delete_group(self.group_m) + result = self.cognito.delete_group(self.group_n) + return From b20026292ee6c99b0ae4ce3a02f92b2f1645b3a7 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Thu, 12 Dec 2024 13:47:13 -0600 Subject: [PATCH 4/4] feat: optionally ignore perc. defaulted not to ignore --- cumulus_lambda_functions/lib/uds_db/granules_db_index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cumulus_lambda_functions/lib/uds_db/granules_db_index.py b/cumulus_lambda_functions/lib/uds_db/granules_db_index.py index f993f16e..619de582 100644 --- a/cumulus_lambda_functions/lib/uds_db/granules_db_index.py +++ b/cumulus_lambda_functions/lib/uds_db/granules_db_index.py @@ -24,6 +24,7 @@ def __init__(self): base_url=os.getenv('ES_URL'), port=int(os.getenv('ES_PORT', '443')) ) + self.__include_percolator = os.getenv('INCLUDE_PERCOLATOR', 'TRUE') == 'TRUE' # self.__default_fields = { # "granule_id": {"type": "keyword"}, # "collection_id": {"type": "keyword"}, @@ -130,6 +131,8 @@ def create_new_index(self, tenant, tenant_venue, es_mapping: dict): self.__es.create_alias(new_index_name, read_alias_name) self.__es.swap_index_for_alias(write_alias_name, current_index_name, new_index_name) + if not self.__include_percolator: + return write_perc_alias_name = f'{DBConstants.granules_write_alias_prefix}_{tenant}_{tenant_venue}_perc'.lower().strip() read_perc_alias_name = f'{DBConstants.granules_read_alias_prefix}_{tenant}_{tenant_venue}_perc'.lower().strip() current_perc_alias = self.__es.get_alias(write_perc_alias_name)