2727from pystac import Collection
2828from pystac import Item
2929from pystac import ItemCollection
30+ from pystac import StacIO
3031from pystac import STACValidationError
3132from pystac_client import Client
3233from requests import Request
@@ -298,6 +299,16 @@ def is_geojson_type(maybe_type: Optional[str]) -> bool:
298299 )
299300
300301
302+ def get_catalog (data_dict : Dict [str , Any ], r_session : Session ) -> Catalog :
303+ stac_io = StacIO .default ()
304+ if r_session .headers and r_session .headers .get ("Authorization" ):
305+ stac_io .headers = r_session .headers # noqa, type: ignore
306+ stac_io .headers ["Accept-Encoding" ] = "*"
307+ catalog = Catalog .from_dict (data_dict )
308+ catalog ._stac_io = stac_io
309+ return catalog
310+
311+
301312# def is_json_or_geojson_type(maybe_type: Optional[str]) -> bool:
302313# return maybe_type and (is_json_type(maybe_type) or is_geojson_type(maybe_type))
303314
@@ -381,9 +392,8 @@ def retrieve(
381392 additional : Optional [str ] = "" ,
382393 content_type : Optional [str ] = None ,
383394) -> Tuple [int , Optional [Dict [str , Any ]], Optional [Mapping [str , str ]]]:
384- resp = r_session .send (
385- Request (method .value , url , headers = headers , params = params , json = body ).prepare ()
386- )
395+ request = Request (method .value , url , headers = headers , params = params , json = body )
396+ resp = r_session .send (r_session .prepare_request (request ))
387397
388398 # todo: handle connection exception, etc.
389399 # todo: handle timeout
@@ -537,6 +547,7 @@ def validate_api(
537547 validate_pagination : bool ,
538548 query_config : QueryConfig ,
539549 transaction_collection : Optional [str ],
550+ headers : Optional [Dict [str , str ]],
540551) -> Tuple [Warnings , Errors ]:
541552 warnings = Warnings ()
542553 errors = Errors ()
@@ -548,6 +559,9 @@ def validate_api(
548559 if auth_query_parameter and (xs := auth_query_parameter .split ("=" , 1 )):
549560 r_session .params = {xs [0 ]: xs [1 ]}
550561
562+ if headers :
563+ r_session .headers .update (headers )
564+
551565 _ , landing_page_body , landing_page_headers = retrieve (
552566 Method .GET , root_url , errors , Context .CORE , r_session
553567 )
@@ -704,7 +718,7 @@ def validate_api(
704718
705719 if not errors :
706720 try :
707- catalog = Client .open (root_url )
721+ catalog = Client .open (root_url , headers = headers )
708722 catalog .validate ()
709723 for child in catalog .get_children ():
710724 child .validate ()
@@ -811,7 +825,8 @@ def validate_core(
811825 # this validates, among other things, that the child and item link relations reference
812826 # valid STAC Catalogs, Collections, and/or Items
813827 try :
814- list (take (1000 , Catalog .from_dict (root_body ).get_all_items ()))
828+ catalog = get_catalog (root_body , r_session )
829+ list (take (1000 , catalog .get_all_items ()))
815830 except pystac .errors .STACTypeError as e :
816831 errors += (
817832 f"[{ Context .CORE } ] Error while traversing Catalog child/item links to find Items: { e } "
@@ -839,14 +854,15 @@ def validate_browseable(
839854 # check that at least a few of the items that can be reached from child/item link relations
840855 # can be found through search
841856 try :
842- for item in take (10 , Catalog .from_dict (root_body ).get_all_items ()):
857+ catalog = get_catalog (root_body , r_session )
858+ for item in take (10 , catalog .get_all_items ()):
843859 if link := link_by_rel (root_body .get ("links" ), "search" ):
844860 _ , body , _ = retrieve (
845861 Method .GET ,
846862 link ["href" ],
847863 errors ,
848864 Context .BROWSEABLE ,
849- params = {"ids" : item .id , "collections" : item .collection },
865+ params = {"ids" : item .id , "collections" : item .collection_id },
850866 r_session = r_session ,
851867 )
852868 if body and len (body .get ("features" , [])) != 1 :
0 commit comments