@@ -21,6 +21,7 @@ def __init__(self, cumulus_base: str, cumulus_token: str):
2121 super ().__init__ (cumulus_base , cumulus_token )
2222 self ._conditions .append ('status=completed' )
2323 self ._item_transformer = ItemTransformer ()
24+ self .__collection_id = None
2425
2526 def with_filter (self , filter_key , filter_values : list ):
2627 if len (filter_values ) < 1 :
@@ -34,6 +35,7 @@ def with_filter(self, filter_key, filter_values: list):
3435
3536 def with_collection_id (self , collection_id : str ):
3637 self ._conditions .append (f'{ self .__collection_id_key } ={ collection_id } ' )
38+ self .__collection_id = collection_id
3739 return self
3840
3941 def with_bbox (self ):
@@ -130,6 +132,48 @@ def query_direct_to_private_api(self, private_api_prefix: str, transform=True):
130132 return {'server_error' : f'error while invoking:{ str (e )} ' }
131133 return {'results' : stac_list }
132134
135+ def delete_entry (self , private_api_prefix : str , granule_id : str ):
136+ payload = {
137+ 'httpMethod' : 'DELETE' ,
138+ 'resource' : '/{proxy+}' ,
139+ 'path' : f'/{ self .__granules_key } /{ self .__collection_id } /{ granule_id } ' ,
140+ 'queryStringParameters' : {** {k [0 ]: k [1 ] for k in [k1 .split ('=' ) for k1 in self ._conditions ]}},
141+ # 'queryStringParameters': {'limit': '30'},
142+ 'headers' : {
143+ 'Content-Type' : 'application/json' ,
144+ },
145+ # 'body': json.dumps({"action": "removeFromCmr"})
146+ }
147+ LOGGER .debug (f'payload: { payload } ' )
148+ try :
149+ query_result = self ._invoke_api (payload , private_api_prefix )
150+ """
151+ {'statusCode': 200, 'body': '{"meta":{"name":"cumulus-api","stack":"am-uds-dev-cumulus","table":"granule","limit":3,"page":1,"count":0},"results":[]}', 'headers': {'x-powered-by': 'Express', 'access-control-allow-origin': '*', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'content-type': 'application/json; charset=utf-8', 'content-length': '120', 'etag': 'W/"78-YdHqDNIH4LuOJMR39jGNA/23yOQ"', 'date': 'Tue, 07 Jun 2022 22:30:44 GMT', 'connection': 'close'}, 'isBase64Encoded': False}
152+ """
153+ if query_result ['statusCode' ] >= 500 :
154+ LOGGER .error (f'server error status code: { query_result .statusCode } . details: { query_result } ' )
155+ return {'server_error' : query_result }
156+ if query_result ['statusCode' ] >= 400 :
157+ LOGGER .error (f'client error status code: { query_result .statusCode } . details: { query_result } ' )
158+ return {'client_error' : query_result }
159+ query_result = json .loads (query_result ['body' ])
160+ LOGGER .info (f'json query_result: { query_result } ' )
161+ """
162+ {
163+ "detail": "Record deleted"
164+ }
165+ """
166+ if 'detail' not in query_result :
167+ LOGGER .error (f'missing key: detail. invalid response json: { query_result } ' )
168+ return {'server_error' : f'missing key: detail. invalid response json: { query_result } ' }
169+ if query_result ['detail' ] != 'Record deleted' :
170+ LOGGER .error (f'Wrong Message: { query_result } ' )
171+ return {'server_error' : f'Wrong Message: { query_result } ' }
172+ except Exception as e :
173+ LOGGER .exception ('error while invoking' )
174+ return {'server_error' : f'error while invoking:{ str (e )} ' }
175+ return {}
176+
133177 def query (self , transform = True ):
134178 conditions_str = '&' .join (self ._conditions )
135179 LOGGER .info (f'cumulus_base: { self .cumulus_base } ' )
0 commit comments