@@ -331,6 +331,8 @@ def stac_validate(
331
331
errors : Errors ,
332
332
context : Context ,
333
333
method : Method = Method .GET ,
334
+ open_assets_urls : bool = True ,
335
+ headers : dict = {},
334
336
) -> None :
335
337
if not body :
336
338
errors += f"[{ context } ] : { method } { url } body was empty when running stac-validate and stac-check"
@@ -350,8 +352,9 @@ def stac_validate(
350
352
errors += f"[{ context } ] : { method } { url } '{ body .get ('id' )} ' failed pystac hydration: { e } "
351
353
352
354
if _type in ["Collection" , "Feature" ]:
355
+ logger .debug (f"stac-validator validation: { url } " )
353
356
if not (
354
- stac_validator := StacValidate (links = True , assets = True )
357
+ stac_validator := StacValidate (links = True , assets = True , assets_open_urls = open_assets_urls , headers = headers )
355
358
).validate_dict (body ):
356
359
errors += f"[{ context } ] : { method } { url } failed stac-validator validation: { stac_validator .message } "
357
360
@@ -548,6 +551,7 @@ def validate_api(
548
551
query_config : QueryConfig ,
549
552
transaction_collection : Optional [str ],
550
553
headers : Optional [Dict [str , str ]],
554
+ open_assets_urls : bool = True ,
551
555
) -> Tuple [Warnings , Errors ]:
552
556
warnings = Warnings ()
553
557
errors = Errors ()
@@ -598,13 +602,13 @@ def validate_api(
598
602
599
603
if "collections" in ccs_to_validate :
600
604
logger .info ("Validating STAC API - Collections conformance class." )
601
- validate_collections (landing_page_body , collection , errors , warnings , r_session )
605
+ validate_collections (landing_page_body , collection , errors , warnings , r_session , open_assets_urls )
602
606
603
607
conforms_to = landing_page_body .get ("conformsTo" , [])
604
608
605
609
if "features" in ccs_to_validate :
606
610
logger .info ("Validating STAC API - Features conformance class." )
607
- validate_collections (landing_page_body , collection , errors , warnings , r_session )
611
+ validate_collections (landing_page_body , collection , errors , warnings , r_session , open_assets_urls )
608
612
validate_features (
609
613
landing_page_body ,
610
614
conforms_to ,
@@ -613,7 +617,8 @@ def validate_api(
613
617
warnings ,
614
618
errors ,
615
619
r_session ,
616
- validate_pagination = validate_pagination ,
620
+ validate_pagination ,
621
+ open_assets_urls ,
617
622
)
618
623
619
624
if "transaction" in ccs_to_validate :
@@ -664,6 +669,7 @@ def validate_api(
664
669
conformance_classes = ccs_to_validate ,
665
670
r_session = r_session ,
666
671
validate_pagination = validate_pagination ,
672
+ open_assets_urls = open_assets_urls ,
667
673
)
668
674
669
675
if "item-search#fields" in ccs_to_validate :
@@ -963,6 +969,7 @@ def validate_collections(
963
969
errors : Errors ,
964
970
warnings : Warnings ,
965
971
r_session : Session ,
972
+ open_assets_urls : bool = True ,
966
973
) -> None :
967
974
if not (data_link := link_by_rel (root_body ["links" ], "data" )):
968
975
errors += f"[{ Context .COLLECTIONS } ] /: Link[rel=data] must href /collections"
@@ -1019,7 +1026,7 @@ def validate_collections(
1019
1026
)
1020
1027
else :
1021
1028
for body in collections_list :
1022
- stac_validate (collections_url , body , errors , Context .COLLECTIONS )
1029
+ stac_validate (collections_url , body , errors , Context .COLLECTIONS , Method . GET , open_assets_urls , r_session . headers )
1023
1030
1024
1031
collection_url = f"{ data_link ['href' ]} /{ collection } "
1025
1032
_ , body , resp_headers = retrieve (
@@ -1047,7 +1054,7 @@ def validate_collections(
1047
1054
if not link_by_rel (body .get ("links" , []), "parent" ):
1048
1055
errors += f"[{ Context .COLLECTIONS } ] : { collection_url } does not have parent link"
1049
1056
1050
- stac_validate (collection_url , body , errors , Context .COLLECTIONS )
1057
+ stac_validate (collection_url , body , errors , Context .COLLECTIONS , Method . GET , open_assets_urls , r_session . headers )
1051
1058
stac_check (collection_url , errors , warnings , Context .COLLECTIONS )
1052
1059
1053
1060
# todo: collection pagination
@@ -1062,6 +1069,7 @@ def validate_features(
1062
1069
errors : Errors ,
1063
1070
r_session : Session ,
1064
1071
validate_pagination : bool ,
1072
+ open_assets_urls : bool = True ,
1065
1073
) -> None :
1066
1074
if not geometry :
1067
1075
errors += f"[{ Context .FEATURES } ] Geometry parameter required for running Features validations."
@@ -1132,7 +1140,7 @@ def validate_features(
1132
1140
if not body :
1133
1141
errors += f"[{ Context .FEATURES } ] GET { collection_items_url } returned an empty body"
1134
1142
else :
1135
- stac_validate (collection_items_url , body , errors , Context .FEATURES )
1143
+ stac_validate (collection_items_url , body , errors , Context .FEATURES , Method . GET , open_assets_urls , r_session . headers )
1136
1144
1137
1145
item_url = link_by_rel (body .get ("features" , [])[0 ]["links" ], "self" )[
1138
1146
"href"
@@ -1147,7 +1155,7 @@ def validate_features(
1147
1155
r_session = r_session ,
1148
1156
)
1149
1157
1150
- stac_validate (item_url , body , errors , Context .FEATURES )
1158
+ stac_validate (item_url , body , errors , Context .FEATURES , Method . GET , open_assets_urls , r_session . headers )
1151
1159
stac_check (item_url , errors , warnings , Context .FEATURES )
1152
1160
1153
1161
# Validate Features non-existent item
@@ -1195,7 +1203,7 @@ def validate_features(
1195
1203
if not link_by_rel (body .get ("links" , []), "root" ):
1196
1204
errors += f"[{ Context .FEATURES } ] GET { collection_items_url } does not have root link"
1197
1205
1198
- stac_validate (collection_items_url , body , errors , Context .FEATURES )
1206
+ stac_validate (collection_items_url , body , errors , Context .FEATURES , Method . GET , open_assets_urls , r_session . headers )
1199
1207
1200
1208
item = next (iter (body .get ("features" , [])), None )
1201
1209
@@ -1233,7 +1241,7 @@ def validate_features(
1233
1241
if not link_by_rel (body .get ("links" , []), "parent" ):
1234
1242
errors += f"[{ Context .FEATURES } ] GET { item_url } does not have parent link"
1235
1243
1236
- stac_validate (item_url , body , errors , Context .FEATURES )
1244
+ stac_validate (item_url , body , errors , Context .FEATURES , Method . GET , open_assets_urls , r_session . headers )
1237
1245
stac_check (item_url , errors , warnings , Context .FEATURES )
1238
1246
1239
1247
if validate_pagination :
@@ -1270,6 +1278,7 @@ def validate_item_search(
1270
1278
conformance_classes : List [str ],
1271
1279
r_session : Session ,
1272
1280
validate_pagination : bool ,
1281
+ open_assets_urls : bool = True ,
1273
1282
) -> None :
1274
1283
links = root_body .get ("links" )
1275
1284
@@ -1317,7 +1326,7 @@ def validate_item_search(
1317
1326
)
1318
1327
1319
1328
if body :
1320
- stac_validate (search_url , body , errors , Context .ITEM_SEARCH )
1329
+ stac_validate (search_url , body , errors , Context .ITEM_SEARCH , open_assets_urls , r_session . headers )
1321
1330
1322
1331
validate_item_search_limit (search_url , methods , errors , r_session )
1323
1332
validate_item_search_bbox_xor_intersects (search_url , methods , errors , r_session )
0 commit comments