1+ import json
2+ import os
13from copy import deepcopy
24
5+ from mdps_ds_lib .lib .aws .aws_lambda import AwsLambda
36from pystac import Link
7+ from starlette .datastructures import URL
48
59from cumulus_lambda_functions .daac_archiver .daac_archiver_logic import DaacArchiverLogic
610from cumulus_lambda_functions .granules_to_es .granules_index_mapping import GranulesIndexMapping
1721
1822class GranulesDapaQueryEs :
1923 def __init__ (self , collection_id , limit , offset , input_datetime , filter_input , pagination_link_obj : PaginationLinksGenerator , base_url ):
24+ self .__collection_cnm_lambda_name = os .environ .get ('COLLECTION_CREATION_LAMBDA_NAME' , '' ).strip ()
2025 self .__pagination_link_obj = pagination_link_obj
2126 self .__input_datetime = input_datetime
2227 self .__collection_id = collection_id
@@ -149,6 +154,64 @@ def get_single_granule(self, granule_id):
149154 self .__restructure_each_granule_result (each_granules_query_result_stripped )
150155 return each_granules_query_result_stripped
151156
157+ def delete_facade (self , current_url : URL , bearer_token : str ):
158+ actual_path = current_url .path
159+ actual_path = actual_path if actual_path .endswith ('/' ) else f'{ actual_path } /'
160+ actual_path = f'{ actual_path } actual'
161+ LOGGER .info (f'sanity_check' )
162+
163+ actual_event = {
164+ 'resource' : actual_path ,
165+ 'path' : actual_path ,
166+ 'httpMethod' : 'DELETE' ,
167+ 'headers' : {
168+ 'Accept' : '*/*' , 'Accept-Encoding' : 'gzip, deflate' , 'Authorization' : bearer_token ,
169+ 'Host' : current_url .hostname , 'User-Agent' : 'python-requests/2.28.2' ,
170+ 'X-Amzn-Trace-Id' : 'Root=1-64a66e90-6fa8b7a64449014639d4f5b4' , 'X-Forwarded-For' : '44.236.15.58' ,
171+ 'X-Forwarded-Port' : '443' , 'X-Forwarded-Proto' : 'https' },
172+ 'multiValueHeaders' : {
173+ 'Accept' : ['*/*' ], 'Accept-Encoding' : ['gzip, deflate' ], 'Authorization' : [bearer_token ],
174+ 'Host' : [current_url .hostname ], 'User-Agent' : ['python-requests/2.28.2' ],
175+ 'X-Amzn-Trace-Id' : ['Root=1-64a66e90-6fa8b7a64449014639d4f5b4' ],
176+ 'X-Forwarded-For' : ['127.0.0.1' ], 'X-Forwarded-Port' : ['443' ], 'X-Forwarded-Proto' : ['https' ]
177+ },
178+ 'queryStringParameters' : {},
179+ 'multiValueQueryStringParameters' : {},
180+ 'pathParameters' : {},
181+ 'stageVariables' : None ,
182+ 'requestContext' : {
183+ 'resourceId' : '' ,
184+ 'authorizer' : {'principalId' : '' , 'integrationLatency' : 0 },
185+ 'resourcePath' : actual_path , 'httpMethod' : 'PUT' ,
186+ 'extendedRequestId' : '' , 'requestTime' : '' ,
187+ 'path' : actual_path , 'accountId' : '' ,
188+ 'protocol' : 'HTTP/1.1' , 'stage' : '' , 'domainPrefix' : '' , 'requestTimeEpoch' : 0 ,
189+ 'requestId' : '' ,
190+ 'identity' : {
191+ 'cognitoIdentityPoolId' : None , 'accountId' : None , 'cognitoIdentityId' : None , 'caller' : None ,
192+ 'sourceIp' : '127.0.0.1' , 'principalOrgId' : None , 'accessKey' : None ,
193+ 'cognitoAuthenticationType' : None ,
194+ 'cognitoAuthenticationProvider' : None , 'userArn' : None , 'userAgent' : 'python-requests/2.28.2' ,
195+ 'user' : None
196+ },
197+ 'domainName' : current_url .hostname , 'apiId' : ''
198+ },
199+ 'body' : json .dumps ({}),
200+ 'isBase64Encoded' : False
201+ }
202+ LOGGER .info (f'actual_event: { actual_event } ' )
203+ response = AwsLambda ().invoke_function (
204+ function_name = self .__collection_cnm_lambda_name ,
205+ payload = actual_event ,
206+ )
207+ LOGGER .debug (f'async function started: { response } ' )
208+ return {
209+ 'statusCode' : 202 ,
210+ 'body' : {
211+ 'message' : 'processing'
212+ }
213+ }
214+
152215 def start (self ):
153216 try :
154217 granules_query_dsl = self .__generate_es_dsl ()
@@ -164,7 +227,8 @@ def start(self):
164227 self_link = Link (rel = 'self' , target = f'{ self .__base_url } /{ WebServiceConstants .COLLECTIONS } /{ self .__collection_id } /items/{ each_granules_query_result_stripped ["id" ]} ' , media_type = 'application/json' , title = each_granules_query_result_stripped ["id" ]).to_dict (False )
165228 each_granules_query_result_stripped ['links' ].append (self_link )
166229 self .__restructure_each_granule_result (each_granules_query_result_stripped )
167- pagination_link = '' if len (granules_query_result ['hits' ]['hits' ]) < self .__limit else ',' .join (granules_query_result ['hits' ]['hits' ][- 1 ]['sort' ])
230+
231+ pagination_link = '' if len (granules_query_result ['hits' ]['hits' ]) < self .__limit else ',' .join ([k if isinstance (k , str ) else str (k ) for k in granules_query_result ['hits' ]['hits' ][- 1 ]['sort' ]])
168232 return {
169233 'statusCode' : 200 ,
170234 'body' : {
0 commit comments