From 0cb33f2358380831c2d71e216b85d1a2c3e9c0d0 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 11:21:19 -0700 Subject: [PATCH 1/7] fix: starting --- cumulus_lambda_functions/uds_api/misc_api.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cumulus_lambda_functions/uds_api/misc_api.py b/cumulus_lambda_functions/uds_api/misc_api.py index 7ec80141..08ce4ab7 100644 --- a/cumulus_lambda_functions/uds_api/misc_api.py +++ b/cumulus_lambda_functions/uds_api/misc_api.py @@ -50,6 +50,7 @@ async def catalog_list(request: Request, response: Response): }] return stac_browser_expecting_result + @router.get(f'/stac_entry') @router.get(f'/stac_entry/') async def stac_entry(request: Request, response: Response): @@ -79,3 +80,21 @@ async def stac_entry(request: Request, response: Response): redirect_response.set_cookie(key="unity_token", value=request_headers['oidc_access_token'], httponly=False, secure=False, samesite='strict') # missing , domain=base_url redirect_response.set_cookie(key="test1", value=f"{time()}", httponly=False, secure=False, samesite='strict') # missing , domain=base_url return redirect_response + + +@router.get(f'/version') +@router.get(f'/version/') +async def ds_version(request: Request, response: Response): + """ + This is to list all catalogs for STAC Browser. + This doesn't require any authorization token. + :param request: + :param response: + :return: + """ + version_details = { + 'temp': os.path.dirname(__file__), + 'version': 'TODO', + 'built': 'TODO' + } + return version_details \ No newline at end of file From 0f21a5778163684e394030e1fb10d4d395389ad0 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 15:57:12 -0700 Subject: [PATCH 2/7] feat: adding version endpoint terraform (broken?) --- cumulus_lambda_functions/uds_api/misc_api.py | 2 +- tests/integration_tests/test_uds_api.py | 14 ++++++ tf-module/unity-cumulus/api_gateway.tf | 2 + .../api_gateway_01_misc_base_00_version.tf | 47 +++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tf-module/unity-cumulus/api_gateway_01_misc_base_00_version.tf diff --git a/cumulus_lambda_functions/uds_api/misc_api.py b/cumulus_lambda_functions/uds_api/misc_api.py index 08ce4ab7..82b67f3f 100644 --- a/cumulus_lambda_functions/uds_api/misc_api.py +++ b/cumulus_lambda_functions/uds_api/misc_api.py @@ -97,4 +97,4 @@ async def ds_version(request: Request, response: Response): 'version': 'TODO', 'built': 'TODO' } - return version_details \ No newline at end of file + return version_details diff --git a/tests/integration_tests/test_uds_api.py b/tests/integration_tests/test_uds_api.py index 480127cd..f3fd5bec 100644 --- a/tests/integration_tests/test_uds_api.py +++ b/tests/integration_tests/test_uds_api.py @@ -233,6 +233,20 @@ def test_single_granule_get(self): return + def test_version_get(self): + post_url = f'{self.uds_url}misc/version/' + headers = { + 'Authorization': f'Bearer {self.bearer_token}', + } + print(post_url) + query_result = requests.get(url=post_url, + headers=headers, + ) + # self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}') + response_json = json.loads(query_result.text) + print(json.dumps(response_json)) + return + def test_create_new_collection(self): post_url = f'{self.uds_url}collections/' # MCP Dev headers = { diff --git a/tf-module/unity-cumulus/api_gateway.tf b/tf-module/unity-cumulus/api_gateway.tf index f3fd2473..dfd785d7 100644 --- a/tf-module/unity-cumulus/api_gateway.tf +++ b/tf-module/unity-cumulus/api_gateway.tf @@ -54,10 +54,12 @@ resource "aws_api_gateway_deployment" "shared_services_api_gateway_deployment" { aws_api_gateway_integration.misc_catalog_list_lambda_integration, aws_api_gateway_integration.misc_stac_entry_lambda_integration, + aws_api_gateway_integration.misc_version_lambda_integration, aws_api_gateway_integration.stac_browser_lambda_integration, aws_api_gateway_integration.stac_browser_proxy_lambda_integration, + module.uds_all_cors_method.options_integration_object, module.uds_all_any_to_lambda_module.lambda_integration_object, diff --git a/tf-module/unity-cumulus/api_gateway_01_misc_base_00_version.tf b/tf-module/unity-cumulus/api_gateway_01_misc_base_00_version.tf new file mode 100644 index 00000000..a7339dfb --- /dev/null +++ b/tf-module/unity-cumulus/api_gateway_01_misc_base_00_version.tf @@ -0,0 +1,47 @@ +resource "aws_api_gateway_resource" "misc_version_resource" { + rest_api_id = data.aws_api_gateway_rest_api.rest_api.id + parent_id = aws_api_gateway_resource.misc_base_resource.id + path_part = "version" +} + +resource "aws_api_gateway_method" "misc_version_method" { + rest_api_id = data.aws_api_gateway_rest_api.rest_api.id + resource_id = aws_api_gateway_resource.misc_version_resource.id + http_method = "GET" + authorization = "NONE" + request_parameters = { + "method.request.path.proxy" = true + } +} + +resource "aws_api_gateway_method_response" "misc_version_method_response" { + rest_api_id = data.aws_api_gateway_rest_api.rest_api.id + resource_id = aws_api_gateway_resource.misc_version_resource.id + http_method = aws_api_gateway_method.misc_version_method.http_method + status_code = 200 + response_models = { + "application/json" = "Empty" + } + response_parameters = { + "method.response.header.Access-Control-Allow-Origin" = true + } + depends_on = ["aws_api_gateway_method.misc_version_method"] +} + +resource "aws_api_gateway_integration" "misc_version_lambda_integration" { + rest_api_id = data.aws_api_gateway_rest_api.rest_api.id + resource_id = aws_api_gateway_resource.misc_version_resource.id + http_method = aws_api_gateway_method.misc_version_method.http_method + type = "AWS_PROXY" + uri = aws_lambda_function.uds_api_1.invoke_arn + integration_http_method = "POST" + +# cache_key_parameters = ["method.request.path.proxy"] + + timeout_milliseconds = 29000 +# request_parameters = { +# "integration.request.path.proxy" = "method.request.path.proxy" +# } +} + +########################################################################################################################## From 69072daa3f833a6695fdc257a420d2884b94b239 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 15:58:27 -0700 Subject: [PATCH 3/7] fix: add logs --- cumulus_lambda_functions/uds_api/misc_api.py | 3 +++ cumulus_lambda_functions/uds_api/web_service.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cumulus_lambda_functions/uds_api/misc_api.py b/cumulus_lambda_functions/uds_api/misc_api.py index 82b67f3f..f39c7e84 100644 --- a/cumulus_lambda_functions/uds_api/misc_api.py +++ b/cumulus_lambda_functions/uds_api/misc_api.py @@ -31,6 +31,7 @@ async def catalog_list(request: Request, response: Response): :param response: :return: """ + print('inside catalog_list') base_url = os.environ.get(WebServiceConstants.BASE_URL, f'{request.url.scheme}://{request.url.netloc}') base_url = base_url[:-1] if base_url.endswith('/') else base_url base_url = base_url if base_url.startswith('http') else f'https://{base_url}' @@ -85,6 +86,8 @@ async def stac_entry(request: Request, response: Response): @router.get(f'/version') @router.get(f'/version/') async def ds_version(request: Request, response: Response): + print('inside ds_version') + """ This is to list all catalogs for STAC Browser. This doesn't require any authorization token. diff --git a/cumulus_lambda_functions/uds_api/web_service.py b/cumulus_lambda_functions/uds_api/web_service.py index ae77d68d..38a7ce3e 100644 --- a/cumulus_lambda_functions/uds_api/web_service.py +++ b/cumulus_lambda_functions/uds_api/web_service.py @@ -64,7 +64,7 @@ async def get_open_api(request: Request): default_open_api_doc['paths'].pop(k) return app.openapi() - +print('hello about to call mangum') # to make it work with Amazon Lambda, we create a handler object handler = Mangum(app=app) From 7d1687ed149f23281389033cf4e5bd648d4d6c32 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 17:15:52 -0700 Subject: [PATCH 4/7] fix: adding version logic --- ci.cd/create_aws_lambda_zip.sh | 7 +++++++ cumulus_lambda_functions/uds_api/misc_api.py | 19 +++++++++++++------ .../uds_api/web_service.py | 1 - 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ci.cd/create_aws_lambda_zip.sh b/ci.cd/create_aws_lambda_zip.sh index a6029204..d696300e 100644 --- a/ci.cd/create_aws_lambda_zip.sh +++ b/ci.cd/create_aws_lambda_zip.sh @@ -18,6 +18,13 @@ terraform_stac_br_zip_file="${project_root_dir}/$TERRAFORM_STAC_BR_ZIP_NAME" ; # source_dir=`python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'` cd ${source_dir} +built_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +cat < ds_version.json +{ + "version": "$software_version", + "built": "$built_time" +} +EOF rm -rf ${zip_file} && \ zip -r9 ${zip_file} . && \ echo "zipped to ${zip_file}" diff --git a/cumulus_lambda_functions/uds_api/misc_api.py b/cumulus_lambda_functions/uds_api/misc_api.py index f39c7e84..ae1f1e47 100644 --- a/cumulus_lambda_functions/uds_api/misc_api.py +++ b/cumulus_lambda_functions/uds_api/misc_api.py @@ -1,8 +1,10 @@ import json import os +from glob import glob from time import time from typing import Union +from mdps_ds_lib.lib.utils.file_utils import FileUtils from starlette.responses import Response, RedirectResponse from cumulus_lambda_functions.uds_api.fast_api_utils import FastApiUtils @@ -31,7 +33,6 @@ async def catalog_list(request: Request, response: Response): :param response: :return: """ - print('inside catalog_list') base_url = os.environ.get(WebServiceConstants.BASE_URL, f'{request.url.scheme}://{request.url.netloc}') base_url = base_url[:-1] if base_url.endswith('/') else base_url base_url = base_url if base_url.startswith('http') else f'https://{base_url}' @@ -86,8 +87,6 @@ async def stac_entry(request: Request, response: Response): @router.get(f'/version') @router.get(f'/version/') async def ds_version(request: Request, response: Response): - print('inside ds_version') - """ This is to list all catalogs for STAC Browser. This doesn't require any authorization token. @@ -95,9 +94,17 @@ async def ds_version(request: Request, response: Response): :param response: :return: """ + version_details_unknown = { + 'version': 'unknown', + 'built': 'unknown' + } + if not FileUtils.file_exist('/var/task/ds_version.json'): + print(f'missing file : {[k for k in glob("/var/task/*.json")]}') + return version_details_unknown + version_details = FileUtils.read_json('/var/task/ds_version.json') + version_details = { - 'temp': os.path.dirname(__file__), - 'version': 'TODO', - 'built': 'TODO' + **version_details_unknown, + **version_details, } return version_details diff --git a/cumulus_lambda_functions/uds_api/web_service.py b/cumulus_lambda_functions/uds_api/web_service.py index 38a7ce3e..edea8cd2 100644 --- a/cumulus_lambda_functions/uds_api/web_service.py +++ b/cumulus_lambda_functions/uds_api/web_service.py @@ -64,7 +64,6 @@ async def get_open_api(request: Request): default_open_api_doc['paths'].pop(k) return app.openapi() -print('hello about to call mangum') # to make it work with Amazon Lambda, we create a handler object handler = Mangum(app=app) From d8fd4eeb06f5b560bf5161116bec9bb3fabdada4 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 17:26:05 -0700 Subject: [PATCH 5/7] fix: software version used before created --- ci.cd/create_aws_lambda_zip.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/ci.cd/create_aws_lambda_zip.sh b/ci.cd/create_aws_lambda_zip.sh index d696300e..78fc4a9a 100644 --- a/ci.cd/create_aws_lambda_zip.sh +++ b/ci.cd/create_aws_lambda_zip.sh @@ -2,6 +2,20 @@ apt-get update -y && apt-get install zip -y +# github.job +github_branch=${GITHUB_REF##*/} +software_version_trailing="" +main_branch="main" +if [ "$github_branch" = "$main_branch" ]; +then + software_version="" +else + software_version_trailing="-${github_branch}-${GITHUB_RUN_ID}" +fi +software_version=`python3 ${project_root_dir}/setup.py --version` +echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV} +cat ${GITHUB_ENV} + ZIP_NAME='cumulus_lambda_functions_deployment.zip' TERRAFORM_ZIP_NAME='terraform_cumulus_lambda_functions_deployment.zip' TERRAFORM_MARKETPLACE_ZIP_NAME='terraform_marketplace_deployment.zip' @@ -45,16 +59,4 @@ zip -9 ${terraform_ecr_zip_file} * **/* cd $project_root_dir/tf-module/stac_browser zip -9 ${terraform_stac_br_zip_file} * **/* -# github.job -github_branch=${GITHUB_REF##*/} -software_version_trailing="" -main_branch="main" -if [ "$github_branch" = "$main_branch" ]; -then - software_version="" -else - software_version_trailing="-${github_branch}-${GITHUB_RUN_ID}" -fi -software_version=`python3 ${project_root_dir}/setup.py --version` -echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV} -cat ${GITHUB_ENV} + From 6e4311da65d3fb98a656025e3d7b2df51e3ebdcf Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 17:28:36 -0700 Subject: [PATCH 6/7] fix: software version used before created --- ci.cd/create_aws_lambda_zip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci.cd/create_aws_lambda_zip.sh b/ci.cd/create_aws_lambda_zip.sh index 78fc4a9a..bf603f7e 100644 --- a/ci.cd/create_aws_lambda_zip.sh +++ b/ci.cd/create_aws_lambda_zip.sh @@ -14,7 +14,6 @@ else fi software_version=`python3 ${project_root_dir}/setup.py --version` echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV} -cat ${GITHUB_ENV} ZIP_NAME='cumulus_lambda_functions_deployment.zip' TERRAFORM_ZIP_NAME='terraform_cumulus_lambda_functions_deployment.zip' @@ -60,3 +59,4 @@ cd $project_root_dir/tf-module/stac_browser zip -9 ${terraform_stac_br_zip_file} * **/* +cat ${GITHUB_ENV} From 8ed4467449d76b5c80dbdcc2f176356087c0e910 Mon Sep 17 00:00:00 2001 From: Wai Phyo Date: Mon, 14 Apr 2025 17:30:52 -0700 Subject: [PATCH 7/7] fix: software version used before created --- ci.cd/create_aws_lambda_zip.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ci.cd/create_aws_lambda_zip.sh b/ci.cd/create_aws_lambda_zip.sh index bf603f7e..b536fe0d 100644 --- a/ci.cd/create_aws_lambda_zip.sh +++ b/ci.cd/create_aws_lambda_zip.sh @@ -12,8 +12,6 @@ then else software_version_trailing="-${github_branch}-${GITHUB_RUN_ID}" fi -software_version=`python3 ${project_root_dir}/setup.py --version` -echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV} ZIP_NAME='cumulus_lambda_functions_deployment.zip' TERRAFORM_ZIP_NAME='terraform_cumulus_lambda_functions_deployment.zip' @@ -22,6 +20,10 @@ TERRAFORM_ECR_ZIP_NAME='terraform_ecr_deployment.zip' TERRAFORM_STAC_BR_ZIP_NAME='terraform_stac_br_deployment.zip' project_root_dir=${GITHUB_WORKSPACE} + +software_version=`python3 ${project_root_dir}/setup.py --version` +echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV} + zip_file="${project_root_dir}/$ZIP_NAME" ; # save the result file in current working directory terraform_zip_file="${project_root_dir}/$TERRAFORM_ZIP_NAME" ; # save the result file in current working directory terraform_marketplace_zip_file="${project_root_dir}/$TERRAFORM_MARKETPLACE_ZIP_NAME" ; # save the result file in current working directory