Skip to content

Commit a2986b4

Browse files
authored
Merge 35e58fe into b89b044
2 parents b89b044 + 35e58fe commit a2986b4

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

ci.cd/create_aws_lambda_zip.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22

33
apt-get update -y && apt-get install zip -y
44

5+
# github.job
6+
github_branch=${GITHUB_REF##*/}
7+
software_version_trailing=""
8+
main_branch="main"
9+
if [ "$github_branch" = "$main_branch" ];
10+
then
11+
software_version=""
12+
else
13+
software_version_trailing="-${github_branch}-${GITHUB_RUN_ID}"
14+
fi
15+
516
ZIP_NAME='cumulus_lambda_functions_deployment.zip'
617
TERRAFORM_ZIP_NAME='terraform_cumulus_lambda_functions_deployment.zip'
718
TERRAFORM_MARKETPLACE_ZIP_NAME='terraform_marketplace_deployment.zip'
819
TERRAFORM_ECR_ZIP_NAME='terraform_ecr_deployment.zip'
920
TERRAFORM_STAC_BR_ZIP_NAME='terraform_stac_br_deployment.zip'
1021

1122
project_root_dir=${GITHUB_WORKSPACE}
23+
24+
software_version=`python3 ${project_root_dir}/setup.py --version`
25+
echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV}
26+
1227
zip_file="${project_root_dir}/$ZIP_NAME" ; # save the result file in current working directory
1328
terraform_zip_file="${project_root_dir}/$TERRAFORM_ZIP_NAME" ; # save the result file in current working directory
1429
terraform_marketplace_zip_file="${project_root_dir}/$TERRAFORM_MARKETPLACE_ZIP_NAME" ; # save the result file in current working directory
@@ -18,6 +33,13 @@ terraform_stac_br_zip_file="${project_root_dir}/$TERRAFORM_STAC_BR_ZIP_NAME" ; #
1833
source_dir=`python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'`
1934

2035
cd ${source_dir}
36+
built_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
37+
cat <<EOF > ds_version.json
38+
{
39+
"version": "$software_version",
40+
"built": "$built_time"
41+
}
42+
EOF
2143
rm -rf ${zip_file} && \
2244
zip -r9 ${zip_file} . && \
2345
echo "zipped to ${zip_file}"
@@ -38,16 +60,5 @@ zip -9 ${terraform_ecr_zip_file} * **/*
3860
cd $project_root_dir/tf-module/stac_browser
3961
zip -9 ${terraform_stac_br_zip_file} * **/*
4062

41-
# github.job
42-
github_branch=${GITHUB_REF##*/}
43-
software_version_trailing=""
44-
main_branch="main"
45-
if [ "$github_branch" = "$main_branch" ];
46-
then
47-
software_version=""
48-
else
49-
software_version_trailing="-${github_branch}-${GITHUB_RUN_ID}"
50-
fi
51-
software_version=`python3 ${project_root_dir}/setup.py --version`
52-
echo "software_version=${software_version}${software_version_trailing}" >> ${GITHUB_ENV}
63+
5364
cat ${GITHUB_ENV}

cumulus_lambda_functions/uds_api/misc_api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
22
import os
3+
from glob import glob
34
from time import time
45
from typing import Union
56

7+
from mdps_ds_lib.lib.utils.file_utils import FileUtils
68
from starlette.responses import Response, RedirectResponse
79
from cumulus_lambda_functions.uds_api.fast_api_utils import FastApiUtils
810

@@ -50,6 +52,7 @@ async def catalog_list(request: Request, response: Response):
5052
}]
5153
return stac_browser_expecting_result
5254

55+
5356
@router.get(f'/stac_entry')
5457
@router.get(f'/stac_entry/')
5558
async def stac_entry(request: Request, response: Response):
@@ -79,3 +82,29 @@ async def stac_entry(request: Request, response: Response):
7982
redirect_response.set_cookie(key="unity_token", value=request_headers['oidc_access_token'], httponly=False, secure=False, samesite='strict') # missing , domain=base_url
8083
redirect_response.set_cookie(key="test1", value=f"{time()}", httponly=False, secure=False, samesite='strict') # missing , domain=base_url
8184
return redirect_response
85+
86+
87+
@router.get(f'/version')
88+
@router.get(f'/version/')
89+
async def ds_version(request: Request, response: Response):
90+
"""
91+
This is to list all catalogs for STAC Browser.
92+
This doesn't require any authorization token.
93+
:param request:
94+
:param response:
95+
:return:
96+
"""
97+
version_details_unknown = {
98+
'version': 'unknown',
99+
'built': 'unknown'
100+
}
101+
if not FileUtils.file_exist('/var/task/ds_version.json'):
102+
print(f'missing file : {[k for k in glob("/var/task/*.json")]}')
103+
return version_details_unknown
104+
version_details = FileUtils.read_json('/var/task/ds_version.json')
105+
106+
version_details = {
107+
**version_details_unknown,
108+
**version_details,
109+
}
110+
return version_details

cumulus_lambda_functions/uds_api/web_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ async def get_open_api(request: Request):
6464
default_open_api_doc['paths'].pop(k)
6565
return app.openapi()
6666

67-
6867
# to make it work with Amazon Lambda, we create a handler object
6968
handler = Mangum(app=app)
7069

tests/integration_tests/test_uds_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,21 @@ def test_single_granule_get(self):
233233

234234
return
235235

236+
def test_version_get(self):
237+
post_url = f'{self.uds_url}misc/version/'
238+
headers = {
239+
'Authorization': f'Bearer {self.bearer_token}',
240+
}
241+
print(post_url)
242+
query_result = requests.get(url=post_url,
243+
headers=headers,
244+
)
245+
# self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}')
246+
response_json = json.loads(query_result.text)
247+
print(json.dumps(response_json))
248+
return
236249

250+
237251
def test_single_granule_get_wrong_collection(self):
238252
# post_url = f'{self.uds_url}collections/urn:nasa:unity:uds_local_test:DEV1:CHRP_16_DAY_REBIN___10/items/urn:nasa:unity:uds_local_test:DEV1:CHRP_16_DAY_REBIN___10:SNDR.SS1330.CHIRP.20230101T0000.m06.g001.L1_J1.std.v02_48.G.200101070318_REBIN'
239253
post_url = f'{self.uds_url}collections/URN:NASA:UNITY:UDS_LOCAL_TEST_3:DEV:DDD-02___001/items/URN:NASA:UNITY:UDS_LOCAL_TEST_3:DEV:DDD-01___001:test_file10'

tf-module/unity-cumulus/api_gateway.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ resource "aws_api_gateway_deployment" "shared_services_api_gateway_deployment" {
5454

5555
aws_api_gateway_integration.misc_catalog_list_lambda_integration,
5656
aws_api_gateway_integration.misc_stac_entry_lambda_integration,
57+
aws_api_gateway_integration.misc_version_lambda_integration,
5758

5859
aws_api_gateway_integration.stac_browser_lambda_integration,
5960
aws_api_gateway_integration.stac_browser_proxy_lambda_integration,
6061

62+
6163
module.uds_all_cors_method.options_integration_object,
6264
module.uds_all_any_to_lambda_module.lambda_integration_object,
6365

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "aws_api_gateway_resource" "misc_version_resource" {
2+
rest_api_id = data.aws_api_gateway_rest_api.rest_api.id
3+
parent_id = aws_api_gateway_resource.misc_base_resource.id
4+
path_part = "version"
5+
}
6+
7+
resource "aws_api_gateway_method" "misc_version_method" {
8+
rest_api_id = data.aws_api_gateway_rest_api.rest_api.id
9+
resource_id = aws_api_gateway_resource.misc_version_resource.id
10+
http_method = "GET"
11+
authorization = "NONE"
12+
request_parameters = {
13+
"method.request.path.proxy" = true
14+
}
15+
}
16+
17+
resource "aws_api_gateway_method_response" "misc_version_method_response" {
18+
rest_api_id = data.aws_api_gateway_rest_api.rest_api.id
19+
resource_id = aws_api_gateway_resource.misc_version_resource.id
20+
http_method = aws_api_gateway_method.misc_version_method.http_method
21+
status_code = 200
22+
response_models = {
23+
"application/json" = "Empty"
24+
}
25+
response_parameters = {
26+
"method.response.header.Access-Control-Allow-Origin" = true
27+
}
28+
depends_on = ["aws_api_gateway_method.misc_version_method"]
29+
}
30+
31+
resource "aws_api_gateway_integration" "misc_version_lambda_integration" {
32+
rest_api_id = data.aws_api_gateway_rest_api.rest_api.id
33+
resource_id = aws_api_gateway_resource.misc_version_resource.id
34+
http_method = aws_api_gateway_method.misc_version_method.http_method
35+
type = "AWS_PROXY"
36+
uri = aws_lambda_function.uds_api_1.invoke_arn
37+
integration_http_method = "POST"
38+
39+
# cache_key_parameters = ["method.request.path.proxy"]
40+
41+
timeout_milliseconds = 29000
42+
# request_parameters = {
43+
# "integration.request.path.proxy" = "method.request.path.proxy"
44+
# }
45+
}
46+
47+
##########################################################################################################################

0 commit comments

Comments
 (0)