9090
9191PRESIGNED_URL_EXPIRATION_TIME = int (os .environ .get ("RSPY_PRESIGNED_URL_EXPIRATION_TIME" , "1800" )) # 30 minutes
9292CATALOG_BUCKET = os .environ .get ("RSPY_CATALOG_BUCKET" , "rs-cluster-catalog" )
93-
93+ DEFAULT_GEOM = {
94+ "type" : "Polygon" ,
95+ "coordinates" : [[[- 180 , - 90 ], [180 , - 90 ], [180 , 90 ], [- 180 , 90 ], [- 180 , - 90 ]]],
96+ }
97+ DEFAULT_BBOX = (- 180.0 , - 90.0 , 180.0 , 90.0 )
9498# pylint: disable=too-many-lines
9599logger = Logging .default (__name__ )
96100
@@ -697,6 +701,7 @@ async def manage_put_post_request( # pylint: disable=too-many-statements,too-ma
697701 content = await request .json ()
698702 if not self .request_ids ["owner_id" ]:
699703 self .request_ids ["owner_id" ] = get_user (None , self .request_ids ["user_login" ])
704+ # If item is not geolocated, add a default one to comply pgstac format.
700705 if ( # If we are in cluster mode and the user_login is not authorized
701706 # to put/post returns a HTTP_401_UNAUTHORIZED status.
702707 common_settings .CLUSTER_MODE
@@ -768,6 +773,11 @@ async def manage_put_post_request( # pylint: disable=too-many-statements,too-ma
768773 original_published = published ,
769774 original_expires = expires ,
770775 )
776+ # If item doesn't contain a geometry/bbox, just fill with a default one.
777+ if not content .get ("geometry" , None ):
778+ content ["geometry" ] = DEFAULT_GEOM
779+ if not content .get ("bbox" , None ):
780+ content ["bbox" ] = DEFAULT_BBOX
771781 if hasattr (content , "status_code" ):
772782 return content
773783
@@ -885,6 +895,11 @@ async def manage_get_response( # pylint: disable=too-many-locals, too-many-bran
885895 auth_roles = []
886896 user_login = ""
887897
898+ if content .get ("geometry" ) == DEFAULT_GEOM :
899+ content ["geometry" ] = None
900+ if content .get ("bbox" ) == DEFAULT_BBOX :
901+ content ["bbox" ] = None
902+
888903 if common_settings .CLUSTER_MODE : # Get the list of access and the user_login calling the endpoint.
889904 auth_roles = request .state .auth_roles
890905 user_login = request .state .user_login
@@ -1044,7 +1059,7 @@ async def manage_put_post_response(self, request: Request, response: StreamingRe
10441059 user = self .request_ids ["owner_id" ]
10451060 body = [chunk async for chunk in response .body_iterator ]
10461061 response_content = json .loads (b"" .join (body ).decode ()) # type: ignore
1047-
1062+ # Don't display geometry and bbox for default case since it was added just for compliance.
10481063 if request .scope ["path" ] == "/collections" :
10491064 response_content = remove_user_from_collection (response_content , user )
10501065 response_content = self .adapt_object_links (response_content , user )
@@ -1054,6 +1069,10 @@ async def manage_put_post_response(self, request: Request, response: StreamingRe
10541069 ):
10551070 response_content = remove_user_from_feature (response_content , user )
10561071 response_content = self .adapt_object_links (response_content , user )
1072+ if response_content .get ("geometry" ) == DEFAULT_GEOM :
1073+ response_content ["geometry" ] = None
1074+ if response_content .get ("bbox" ) == DEFAULT_BBOX :
1075+ response_content ["bbox" ] = None
10571076 delete_s3_files (self .s3_files_to_be_deleted )
10581077 self .s3_files_to_be_deleted .clear ()
10591078 except RuntimeError as exc :
0 commit comments