stac-validator 3.4.0__tar.gz → 3.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_validator-3.4.0 → stac_validator-3.6.0}/PKG-INFO +84 -31
- {stac_validator-3.4.0 → stac_validator-3.6.0}/README.md +82 -24
- {stac_validator-3.4.0 → stac_validator-3.6.0}/setup.py +7 -5
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator/stac_validator.py +32 -1
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator/utilities.py +96 -14
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator/validate.py +278 -208
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator.egg-info/PKG-INFO +85 -32
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator.egg-info/SOURCES.txt +1 -12
- stac_validator-3.6.0/stac_validator.egg-info/requires.txt +9 -0
- stac_validator-3.4.0/stac_validator.egg-info/requires.txt +0 -7
- stac_validator-3.4.0/tests/test_assets.py +0 -85
- stac_validator-3.4.0/tests/test_core.py +0 -212
- stac_validator-3.4.0/tests/test_custom.py +0 -207
- stac_validator-3.4.0/tests/test_default.py +0 -160
- stac_validator-3.4.0/tests/test_extensions.py +0 -215
- stac_validator-3.4.0/tests/test_links.py +0 -80
- stac_validator-3.4.0/tests/test_recursion.py +0 -355
- stac_validator-3.4.0/tests/test_sys_exit.py +0 -32
- stac_validator-3.4.0/tests/test_validate_collections.py +0 -55
- stac_validator-3.4.0/tests/test_validate_dict.py +0 -67
- stac_validator-3.4.0/tests/test_validate_item_collection.py +0 -663
- {stac_validator-3.4.0 → stac_validator-3.6.0}/LICENSE +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/pyproject.toml +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/setup.cfg +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator/__init__.py +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator.egg-info/dependency_links.txt +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator.egg-info/entry_points.txt +0 -0
- {stac_validator-3.4.0 → stac_validator-3.6.0}/stac_validator.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac_validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.6.0
|
|
4
4
|
Summary: A package to validate STAC files
|
|
5
5
|
Home-page: https://github.com/stac-utils/stac-validator
|
|
6
6
|
Author: James Banting, Jonathan Healy
|
|
@@ -14,13 +14,8 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
14
14
|
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
15
15
|
Requires-Python: >=3.8
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Requires-Dist: requests>=2.19.1
|
|
19
|
-
Requires-Dist: jsonschema>=3.2.0
|
|
20
|
-
Requires-Dist: click>=8.0.0
|
|
21
17
|
Provides-Extra: dev
|
|
22
|
-
|
|
23
|
-
Requires-Dist: types-setuptools; extra == "dev"
|
|
18
|
+
License-File: LICENSE
|
|
24
19
|
|
|
25
20
|
# SpatioTemporal Asset Catalog (STAC) Validator
|
|
26
21
|
|
|
@@ -115,30 +110,38 @@ stac-validator --help
|
|
|
115
110
|
Usage: stac-validator [OPTIONS] STAC_FILE
|
|
116
111
|
|
|
117
112
|
Options:
|
|
118
|
-
--core
|
|
119
|
-
|
|
120
|
-
--
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
--
|
|
137
|
-
--
|
|
138
|
-
|
|
139
|
-
--
|
|
140
|
-
|
|
141
|
-
|
|
113
|
+
--core Validate core stac object only without
|
|
114
|
+
extensions.
|
|
115
|
+
--extensions Validate extensions only.
|
|
116
|
+
--links Additionally validate links. Only works with
|
|
117
|
+
default mode.
|
|
118
|
+
--assets Additionally validate assets. Only works
|
|
119
|
+
with default mode.
|
|
120
|
+
-c, --custom TEXT Validate against a custom schema (local
|
|
121
|
+
filepath or remote schema).
|
|
122
|
+
-s, --schema-map <TEXT TEXT>...
|
|
123
|
+
Schema path to replaced by (local) schema
|
|
124
|
+
path during validation. Can be used multiple
|
|
125
|
+
times.
|
|
126
|
+
-r, --recursive Recursively validate all related stac
|
|
127
|
+
objects.
|
|
128
|
+
-m, --max-depth INTEGER Maximum depth to traverse when recursing.
|
|
129
|
+
Omit this argument to get full recursion.
|
|
130
|
+
Ignored if `recursive == False`.
|
|
131
|
+
--collections Validate /collections response.
|
|
132
|
+
--item-collection Validate item collection response. Can be
|
|
133
|
+
combined with --pages. Defaults to one page.
|
|
134
|
+
--no-assets-urls Disables the opening of href links when
|
|
135
|
+
validating assets (enabled by default).
|
|
136
|
+
--header <TEXT TEXT>... HTTP header to include in the requests. Can
|
|
137
|
+
be used multiple times.
|
|
138
|
+
-p, --pages INTEGER Maximum number of pages to validate via
|
|
139
|
+
--item-collection. Defaults to one page.
|
|
140
|
+
-v, --verbose Enables verbose output for recursive mode.
|
|
141
|
+
--no_output Do not print output to console.
|
|
142
|
+
--log_file TEXT Save full recursive output to log file
|
|
143
|
+
(local filepath).
|
|
144
|
+
--help Show this message and exit.```
|
|
142
145
|
|
|
143
146
|
---
|
|
144
147
|
|
|
@@ -354,3 +357,53 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
354
357
|
```bash
|
|
355
358
|
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
356
359
|
```
|
|
360
|
+
|
|
361
|
+
**--header**
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
stac-validator https://stac-catalog.eu/collections/sentinel-s2-l2a/items --header x-api-key $MY_API_KEY --header foo bar
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**--schema-map**
|
|
368
|
+
Schema map allows stac-validator to replace a schema in a STAC json by a schema from another URL or local schema file.
|
|
369
|
+
This is especially useful when developing a schema and testing validation against your local copy of the schema.
|
|
370
|
+
|
|
371
|
+
``` bash
|
|
372
|
+
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions --schema-map https://stac-extensions.github.io/projection/v1.0.0/schema.json stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --extensions --schema-map https://stac-extensions.github.io/projection/v1.0.0/schema.json "tests/test_data/schema/v1.0.0/projection.json"
|
|
373
|
+
[
|
|
374
|
+
{
|
|
375
|
+
"version": "1.0.0",
|
|
376
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json",
|
|
377
|
+
"schema": [
|
|
378
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
379
|
+
"tests/test_data/schema/v1.0.0/projection.json",
|
|
380
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
381
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
382
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
|
|
383
|
+
],
|
|
384
|
+
"valid_stac": true,
|
|
385
|
+
"asset_type": "ITEM",
|
|
386
|
+
"validation_method": "extensions"
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
This option is also capable of replacing URLs to subschemas:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
stac-validator tests/test_data/v100/extended-item-local.json --custom tests/test_data/schema/v1.0.0/item_with_unreachable_url.json --schema-map https://geojson-wrong-url.org/schema/Feature.json https://geojson.org/schema/Feature.json --schema-map https://geojson-wrong-url.org/schema/Geometry.json https://geojson.org/schema/Geometry.json
|
|
395
|
+
[
|
|
396
|
+
{
|
|
397
|
+
"version": "1.0.0",
|
|
398
|
+
"path": "tests/test_data/v100/extended-item-local.json",
|
|
399
|
+
"schema": [
|
|
400
|
+
"tests/test_data/schema/v1.0.0/item_with_unreachable_url.json"
|
|
401
|
+
],
|
|
402
|
+
"valid_stac": true,
|
|
403
|
+
"asset_type": "ITEM",
|
|
404
|
+
"validation_method": "custom"
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
|
|
@@ -91,30 +91,38 @@ stac-validator --help
|
|
|
91
91
|
Usage: stac-validator [OPTIONS] STAC_FILE
|
|
92
92
|
|
|
93
93
|
Options:
|
|
94
|
-
--core
|
|
95
|
-
|
|
96
|
-
--
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
--
|
|
113
|
-
--
|
|
114
|
-
|
|
115
|
-
--
|
|
116
|
-
|
|
117
|
-
|
|
94
|
+
--core Validate core stac object only without
|
|
95
|
+
extensions.
|
|
96
|
+
--extensions Validate extensions only.
|
|
97
|
+
--links Additionally validate links. Only works with
|
|
98
|
+
default mode.
|
|
99
|
+
--assets Additionally validate assets. Only works
|
|
100
|
+
with default mode.
|
|
101
|
+
-c, --custom TEXT Validate against a custom schema (local
|
|
102
|
+
filepath or remote schema).
|
|
103
|
+
-s, --schema-map <TEXT TEXT>...
|
|
104
|
+
Schema path to replaced by (local) schema
|
|
105
|
+
path during validation. Can be used multiple
|
|
106
|
+
times.
|
|
107
|
+
-r, --recursive Recursively validate all related stac
|
|
108
|
+
objects.
|
|
109
|
+
-m, --max-depth INTEGER Maximum depth to traverse when recursing.
|
|
110
|
+
Omit this argument to get full recursion.
|
|
111
|
+
Ignored if `recursive == False`.
|
|
112
|
+
--collections Validate /collections response.
|
|
113
|
+
--item-collection Validate item collection response. Can be
|
|
114
|
+
combined with --pages. Defaults to one page.
|
|
115
|
+
--no-assets-urls Disables the opening of href links when
|
|
116
|
+
validating assets (enabled by default).
|
|
117
|
+
--header <TEXT TEXT>... HTTP header to include in the requests. Can
|
|
118
|
+
be used multiple times.
|
|
119
|
+
-p, --pages INTEGER Maximum number of pages to validate via
|
|
120
|
+
--item-collection. Defaults to one page.
|
|
121
|
+
-v, --verbose Enables verbose output for recursive mode.
|
|
122
|
+
--no_output Do not print output to console.
|
|
123
|
+
--log_file TEXT Save full recursive output to log file
|
|
124
|
+
(local filepath).
|
|
125
|
+
--help Show this message and exit.```
|
|
118
126
|
|
|
119
127
|
---
|
|
120
128
|
|
|
@@ -330,3 +338,53 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
330
338
|
```bash
|
|
331
339
|
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
332
340
|
```
|
|
341
|
+
|
|
342
|
+
**--header**
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
stac-validator https://stac-catalog.eu/collections/sentinel-s2-l2a/items --header x-api-key $MY_API_KEY --header foo bar
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**--schema-map**
|
|
349
|
+
Schema map allows stac-validator to replace a schema in a STAC json by a schema from another URL or local schema file.
|
|
350
|
+
This is especially useful when developing a schema and testing validation against your local copy of the schema.
|
|
351
|
+
|
|
352
|
+
``` bash
|
|
353
|
+
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions --schema-map https://stac-extensions.github.io/projection/v1.0.0/schema.json stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --extensions --schema-map https://stac-extensions.github.io/projection/v1.0.0/schema.json "tests/test_data/schema/v1.0.0/projection.json"
|
|
354
|
+
[
|
|
355
|
+
{
|
|
356
|
+
"version": "1.0.0",
|
|
357
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json",
|
|
358
|
+
"schema": [
|
|
359
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
360
|
+
"tests/test_data/schema/v1.0.0/projection.json",
|
|
361
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
362
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
363
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
|
|
364
|
+
],
|
|
365
|
+
"valid_stac": true,
|
|
366
|
+
"asset_type": "ITEM",
|
|
367
|
+
"validation_method": "extensions"
|
|
368
|
+
}
|
|
369
|
+
]
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
This option is also capable of replacing URLs to subschemas:
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
stac-validator tests/test_data/v100/extended-item-local.json --custom tests/test_data/schema/v1.0.0/item_with_unreachable_url.json --schema-map https://geojson-wrong-url.org/schema/Feature.json https://geojson.org/schema/Feature.json --schema-map https://geojson-wrong-url.org/schema/Geometry.json https://geojson.org/schema/Geometry.json
|
|
376
|
+
[
|
|
377
|
+
{
|
|
378
|
+
"version": "1.0.0",
|
|
379
|
+
"path": "tests/test_data/v100/extended-item-local.json",
|
|
380
|
+
"schema": [
|
|
381
|
+
"tests/test_data/schema/v1.0.0/item_with_unreachable_url.json"
|
|
382
|
+
],
|
|
383
|
+
"valid_stac": true,
|
|
384
|
+
"asset_type": "ITEM",
|
|
385
|
+
"validation_method": "custom"
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from setuptools import setup
|
|
4
4
|
|
|
5
|
-
__version__ = "3.
|
|
5
|
+
__version__ = "3.6.0"
|
|
6
6
|
|
|
7
7
|
with open("README.md", "r") as fh:
|
|
8
8
|
long_description = fh.read()
|
|
@@ -26,13 +26,15 @@ setup(
|
|
|
26
26
|
long_description_content_type="text/markdown",
|
|
27
27
|
url="https://github.com/stac-utils/stac-validator",
|
|
28
28
|
install_requires=[
|
|
29
|
-
"requests>=2.
|
|
30
|
-
"jsonschema>=
|
|
31
|
-
"click>=8.
|
|
29
|
+
"requests>=2.32.3",
|
|
30
|
+
"jsonschema>=4.23.0",
|
|
31
|
+
"click>=8.1.8",
|
|
32
|
+
"referencing>=0.35.1",
|
|
32
33
|
],
|
|
33
34
|
extras_require={
|
|
34
35
|
"dev": [
|
|
35
36
|
"pytest",
|
|
37
|
+
"requests-mock",
|
|
36
38
|
"types-setuptools",
|
|
37
39
|
],
|
|
38
40
|
},
|
|
@@ -41,5 +43,5 @@ setup(
|
|
|
41
43
|
"console_scripts": ["stac-validator = stac_validator.stac_validator:main"]
|
|
42
44
|
},
|
|
43
45
|
python_requires=">=3.8",
|
|
44
|
-
tests_require=["pytest"],
|
|
46
|
+
tests_require=["pytest", "requests-mock"],
|
|
45
47
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import sys
|
|
3
|
-
from typing import Any, Dict, List
|
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
4
4
|
|
|
5
5
|
import click # type: ignore
|
|
6
6
|
|
|
@@ -87,6 +87,13 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
87
87
|
default="",
|
|
88
88
|
help="Validate against a custom schema (local filepath or remote schema).",
|
|
89
89
|
)
|
|
90
|
+
@click.option(
|
|
91
|
+
"--schema-map",
|
|
92
|
+
"-s",
|
|
93
|
+
type=(str, str),
|
|
94
|
+
multiple=True,
|
|
95
|
+
help="Schema path to replaced by (local) schema path during validation. Can be used multiple times.",
|
|
96
|
+
)
|
|
90
97
|
@click.option(
|
|
91
98
|
"--recursive",
|
|
92
99
|
"-r",
|
|
@@ -109,6 +116,17 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
109
116
|
is_flag=True,
|
|
110
117
|
help="Validate item collection response. Can be combined with --pages. Defaults to one page.",
|
|
111
118
|
)
|
|
119
|
+
@click.option(
|
|
120
|
+
"--no-assets-urls",
|
|
121
|
+
is_flag=True,
|
|
122
|
+
help="Disables the opening of href links when validating assets (enabled by default).",
|
|
123
|
+
)
|
|
124
|
+
@click.option(
|
|
125
|
+
"--header",
|
|
126
|
+
type=(str, str),
|
|
127
|
+
multiple=True,
|
|
128
|
+
help="HTTP header to include in the requests. Can be used multiple times.",
|
|
129
|
+
)
|
|
112
130
|
@click.option(
|
|
113
131
|
"--pages",
|
|
114
132
|
"-p",
|
|
@@ -128,6 +146,8 @@ def main(
|
|
|
128
146
|
stac_file: str,
|
|
129
147
|
collections: bool,
|
|
130
148
|
item_collection: bool,
|
|
149
|
+
no_assets_urls: bool,
|
|
150
|
+
header: list,
|
|
131
151
|
pages: int,
|
|
132
152
|
recursive: bool,
|
|
133
153
|
max_depth: int,
|
|
@@ -136,6 +156,7 @@ def main(
|
|
|
136
156
|
links: bool,
|
|
137
157
|
assets: bool,
|
|
138
158
|
custom: str,
|
|
159
|
+
schema_map: List[Tuple],
|
|
139
160
|
verbose: bool,
|
|
140
161
|
no_output: bool,
|
|
141
162
|
log_file: str,
|
|
@@ -147,6 +168,8 @@ def main(
|
|
|
147
168
|
stac_file (str): Path to the STAC file to be validated.
|
|
148
169
|
collections (bool): Validate response from /collections endpoint.
|
|
149
170
|
item_collection (bool): Whether to validate item collection responses.
|
|
171
|
+
no_assets_urls (bool): Whether to open href links when validating assets (enabled by default).
|
|
172
|
+
headers (dict): HTTP headers to include in the requests.
|
|
150
173
|
pages (int): Maximum number of pages to validate via `item_collection`.
|
|
151
174
|
recursive (bool): Whether to recursively validate all related STAC objects.
|
|
152
175
|
max_depth (int): Maximum depth to traverse when recursing.
|
|
@@ -155,6 +178,7 @@ def main(
|
|
|
155
178
|
links (bool): Whether to additionally validate links. Only works with default mode.
|
|
156
179
|
assets (bool): Whether to additionally validate assets. Only works with default mode.
|
|
157
180
|
custom (str): Path to a custom schema file to validate against.
|
|
181
|
+
schema_map (list(tuple)): List of tuples each having two elememts. First element is the schema path to be replaced by the path in the second element.
|
|
158
182
|
verbose (bool): Whether to enable verbose output for recursive mode.
|
|
159
183
|
no_output (bool): Whether to print output to console.
|
|
160
184
|
log_file (str): Path to a log file to save full recursive output.
|
|
@@ -167,6 +191,10 @@ def main(
|
|
|
167
191
|
or 1 if it is invalid.
|
|
168
192
|
"""
|
|
169
193
|
valid = True
|
|
194
|
+
if schema_map == ():
|
|
195
|
+
schema_map_dict: Optional[Dict[str, str]] = None
|
|
196
|
+
else:
|
|
197
|
+
schema_map_dict = dict(schema_map)
|
|
170
198
|
stac = StacValidate(
|
|
171
199
|
stac_file=stac_file,
|
|
172
200
|
collections=collections,
|
|
@@ -177,8 +205,11 @@ def main(
|
|
|
177
205
|
core=core,
|
|
178
206
|
links=links,
|
|
179
207
|
assets=assets,
|
|
208
|
+
assets_open_urls=not no_assets_urls,
|
|
209
|
+
headers=dict(header),
|
|
180
210
|
extensions=extensions,
|
|
181
211
|
custom=custom,
|
|
212
|
+
schema_map=schema_map_dict,
|
|
182
213
|
verbose=verbose,
|
|
183
214
|
log=log_file,
|
|
184
215
|
)
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import json
|
|
3
3
|
import ssl
|
|
4
|
-
from typing import Dict
|
|
4
|
+
from typing import Dict, Optional
|
|
5
5
|
from urllib.parse import urlparse
|
|
6
|
-
from urllib.request import urlopen
|
|
6
|
+
from urllib.request import Request, urlopen
|
|
7
7
|
|
|
8
8
|
import requests # type: ignore
|
|
9
|
+
from jsonschema import Draft202012Validator
|
|
10
|
+
from referencing import Registry, Resource
|
|
11
|
+
from referencing.jsonschema import DRAFT202012
|
|
12
|
+
from referencing.typing import URI
|
|
9
13
|
|
|
10
14
|
NEW_VERSIONS = [
|
|
11
15
|
"1.0.0-beta.2",
|
|
@@ -77,7 +81,7 @@ def get_stac_type(stac_content: Dict) -> str:
|
|
|
77
81
|
return str(e)
|
|
78
82
|
|
|
79
83
|
|
|
80
|
-
def fetch_and_parse_file(input_path: str) -> Dict:
|
|
84
|
+
def fetch_and_parse_file(input_path: str, headers: Optional[Dict] = None) -> Dict:
|
|
81
85
|
"""Fetches and parses a JSON file from a URL or local file.
|
|
82
86
|
|
|
83
87
|
Given a URL or local file path to a JSON file, this function fetches the file,
|
|
@@ -87,6 +91,7 @@ def fetch_and_parse_file(input_path: str) -> Dict:
|
|
|
87
91
|
|
|
88
92
|
Args:
|
|
89
93
|
input_path: A string representing the URL or local file path to the JSON file.
|
|
94
|
+
headers: For URLs: HTTP headers to include in the request
|
|
90
95
|
|
|
91
96
|
Returns:
|
|
92
97
|
A dictionary containing the parsed contents of the JSON file.
|
|
@@ -97,7 +102,7 @@ def fetch_and_parse_file(input_path: str) -> Dict:
|
|
|
97
102
|
"""
|
|
98
103
|
try:
|
|
99
104
|
if is_url(input_path):
|
|
100
|
-
resp = requests.get(input_path)
|
|
105
|
+
resp = requests.get(input_path, headers=headers)
|
|
101
106
|
resp.raise_for_status()
|
|
102
107
|
data = resp.json()
|
|
103
108
|
else:
|
|
@@ -150,8 +155,7 @@ def set_schema_addr(version: str, stac_type: str) -> str:
|
|
|
150
155
|
|
|
151
156
|
|
|
152
157
|
def link_request(
|
|
153
|
-
link: Dict,
|
|
154
|
-
initial_message: Dict,
|
|
158
|
+
link: Dict, initial_message: Dict, open_urls: bool = True, headers: Dict = {}
|
|
155
159
|
) -> None:
|
|
156
160
|
"""Makes a request to a URL and appends it to the relevant field of the initial message.
|
|
157
161
|
|
|
@@ -159,6 +163,8 @@ def link_request(
|
|
|
159
163
|
link: A dictionary containing a "href" key which is a string representing a URL.
|
|
160
164
|
initial_message: A dictionary containing lists for "request_valid", "request_invalid",
|
|
161
165
|
"format_valid", and "format_invalid" URLs.
|
|
166
|
+
open_urls: Whether to open link href URL
|
|
167
|
+
headers: HTTP headers to include in the request
|
|
162
168
|
|
|
163
169
|
Returns:
|
|
164
170
|
None
|
|
@@ -166,17 +172,93 @@ def link_request(
|
|
|
166
172
|
"""
|
|
167
173
|
if is_url(link["href"]):
|
|
168
174
|
try:
|
|
169
|
-
if
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
if open_urls:
|
|
176
|
+
request = Request(link["href"], headers=headers)
|
|
177
|
+
if "s3" in link["href"]:
|
|
178
|
+
context = ssl._create_unverified_context()
|
|
179
|
+
response = urlopen(request, context=context)
|
|
180
|
+
else:
|
|
181
|
+
response = urlopen(request)
|
|
182
|
+
status_code = response.getcode()
|
|
183
|
+
if status_code == 200:
|
|
184
|
+
initial_message["request_valid"].append(link["href"])
|
|
177
185
|
except Exception:
|
|
178
186
|
initial_message["request_invalid"].append(link["href"])
|
|
179
187
|
initial_message["format_valid"].append(link["href"])
|
|
180
188
|
else:
|
|
181
189
|
initial_message["request_invalid"].append(link["href"])
|
|
182
190
|
initial_message["format_invalid"].append(link["href"])
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def cached_retrieve(uri: URI, schema_map: Optional[Dict] = None) -> Resource[Dict]:
|
|
194
|
+
"""
|
|
195
|
+
Retrieve and cache a remote schema.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
uri (str): The URI of the schema.
|
|
199
|
+
schema_map_keys: Override schema location to validate against local versions of a schema
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
dict: The parsed JSON dict of the schema.
|
|
203
|
+
|
|
204
|
+
Raises:
|
|
205
|
+
requests.RequestException: If the request to fetch the schema fails.
|
|
206
|
+
Exception: For any other unexpected errors.
|
|
207
|
+
"""
|
|
208
|
+
return Resource.from_contents(
|
|
209
|
+
fetch_schema_with_override(uri, schema_map=schema_map)
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def fetch_schema_with_override(
|
|
214
|
+
schema_path: str, schema_map: Optional[Dict] = None
|
|
215
|
+
) -> Dict:
|
|
216
|
+
"""
|
|
217
|
+
Retrieve and cache a remote schema.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
schema_path (str): Path or URI of the schema.
|
|
221
|
+
schema_map (dict): Override schema location to validate against local versions of a schema
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
dict: The parsed JSON dict of the schema.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
if schema_map:
|
|
228
|
+
if schema_path in schema_map:
|
|
229
|
+
schema_path = schema_map[schema_path]
|
|
230
|
+
|
|
231
|
+
# Load the schema
|
|
232
|
+
return fetch_and_parse_schema(schema_path)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def validate_with_ref_resolver(
|
|
236
|
+
schema_path: str, content: Dict, schema_map: Optional[Dict] = None
|
|
237
|
+
) -> None:
|
|
238
|
+
"""
|
|
239
|
+
Validate a JSON document against a JSON Schema with dynamic reference resolution.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
schema_path (str): Path or URI of the JSON Schema.
|
|
243
|
+
content (dict): JSON content to validate.
|
|
244
|
+
schema_map (dict): Override schema location to validate against local versions of a schema
|
|
245
|
+
|
|
246
|
+
Raises:
|
|
247
|
+
jsonschema.exceptions.ValidationError: If validation fails.
|
|
248
|
+
requests.RequestException: If fetching a remote schema fails.
|
|
249
|
+
FileNotFoundError: If a local schema file is not found.
|
|
250
|
+
Exception: If any other error occurs during validation.
|
|
251
|
+
"""
|
|
252
|
+
schema = fetch_schema_with_override(schema_path, schema_map=schema_map)
|
|
253
|
+
# Set up the resource and registry for schema resolution
|
|
254
|
+
cached_retrieve_with_schema_map = functools.partial(
|
|
255
|
+
cached_retrieve, schema_map=schema_map
|
|
256
|
+
)
|
|
257
|
+
resource: Resource = Resource(contents=schema, specification=DRAFT202012) # type: ignore
|
|
258
|
+
registry: Registry = Registry(retrieve=cached_retrieve_with_schema_map).with_resource( # type: ignore
|
|
259
|
+
uri=schema_path, resource=resource
|
|
260
|
+
) # type: ignore
|
|
261
|
+
|
|
262
|
+
# Validate the content against the schema
|
|
263
|
+
validator = Draft202012Validator(schema, registry=registry)
|
|
264
|
+
validator.validate(content)
|