stac-validator 3.4.0__tar.gz → 3.5.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.5.0}/PKG-INFO +12 -7
- {stac_validator-3.4.0 → stac_validator-3.5.0}/README.md +10 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/setup.py +7 -5
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator/stac_validator.py +17 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator/utilities.py +111 -14
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator/validate.py +196 -179
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator.egg-info/PKG-INFO +13 -8
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator.egg-info/SOURCES.txt +1 -12
- stac_validator-3.5.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.5.0}/LICENSE +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/pyproject.toml +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/setup.cfg +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator/__init__.py +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator.egg-info/dependency_links.txt +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.0}/stac_validator.egg-info/entry_points.txt +0 -0
- {stac_validator-3.4.0 → stac_validator-3.5.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.5.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
|
|
|
@@ -130,6 +125,10 @@ Options:
|
|
|
130
125
|
--collections Validate /collections response.
|
|
131
126
|
--item-collection Validate item collection response. Can be combined
|
|
132
127
|
with --pages. Defaults to one page.
|
|
128
|
+
--no-assets-urls Disables the opening of href links when validating
|
|
129
|
+
assets (enabled by default).
|
|
130
|
+
--header KEY VALUE HTTP header to include in the requests. Can be used
|
|
131
|
+
multiple times.
|
|
133
132
|
-p, --pages INTEGER Maximum number of pages to validate via --item-
|
|
134
133
|
collection. Defaults to one page.
|
|
135
134
|
-v, --verbose Enables verbose output for recursive mode.
|
|
@@ -354,3 +353,9 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
354
353
|
```bash
|
|
355
354
|
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
356
355
|
```
|
|
356
|
+
|
|
357
|
+
**--header**
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
stac-validator https://stac-catalog.eu/collections/sentinel-s2-l2a/items --header x-api-key $MY_API_KEY --header foo bar
|
|
361
|
+
```
|
|
@@ -106,6 +106,10 @@ Options:
|
|
|
106
106
|
--collections Validate /collections response.
|
|
107
107
|
--item-collection Validate item collection response. Can be combined
|
|
108
108
|
with --pages. Defaults to one page.
|
|
109
|
+
--no-assets-urls Disables the opening of href links when validating
|
|
110
|
+
assets (enabled by default).
|
|
111
|
+
--header KEY VALUE HTTP header to include in the requests. Can be used
|
|
112
|
+
multiple times.
|
|
109
113
|
-p, --pages INTEGER Maximum number of pages to validate via --item-
|
|
110
114
|
collection. Defaults to one page.
|
|
111
115
|
-v, --verbose Enables verbose output for recursive mode.
|
|
@@ -330,3 +334,9 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
330
334
|
```bash
|
|
331
335
|
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
332
336
|
```
|
|
337
|
+
|
|
338
|
+
**--header**
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
stac-validator https://stac-catalog.eu/collections/sentinel-s2-l2a/items --header x-api-key $MY_API_KEY --header foo bar
|
|
342
|
+
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from setuptools import setup
|
|
4
4
|
|
|
5
|
-
__version__ = "3.
|
|
5
|
+
__version__ = "3.5.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
|
)
|
|
@@ -109,6 +109,17 @@ def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
109
109
|
is_flag=True,
|
|
110
110
|
help="Validate item collection response. Can be combined with --pages. Defaults to one page.",
|
|
111
111
|
)
|
|
112
|
+
@click.option(
|
|
113
|
+
"--no-assets-urls",
|
|
114
|
+
is_flag=True,
|
|
115
|
+
help="Disables the opening of href links when validating assets (enabled by default).",
|
|
116
|
+
)
|
|
117
|
+
@click.option(
|
|
118
|
+
"--header",
|
|
119
|
+
type=(str, str),
|
|
120
|
+
multiple=True,
|
|
121
|
+
help="HTTP header to include in the requests. Can be used multiple times.",
|
|
122
|
+
)
|
|
112
123
|
@click.option(
|
|
113
124
|
"--pages",
|
|
114
125
|
"-p",
|
|
@@ -128,6 +139,8 @@ def main(
|
|
|
128
139
|
stac_file: str,
|
|
129
140
|
collections: bool,
|
|
130
141
|
item_collection: bool,
|
|
142
|
+
no_assets_urls: bool,
|
|
143
|
+
header: list,
|
|
131
144
|
pages: int,
|
|
132
145
|
recursive: bool,
|
|
133
146
|
max_depth: int,
|
|
@@ -147,6 +160,8 @@ def main(
|
|
|
147
160
|
stac_file (str): Path to the STAC file to be validated.
|
|
148
161
|
collections (bool): Validate response from /collections endpoint.
|
|
149
162
|
item_collection (bool): Whether to validate item collection responses.
|
|
163
|
+
no_assets_urls (bool): Whether to open href links when validating assets (enabled by default).
|
|
164
|
+
headers (dict): HTTP headers to include in the requests.
|
|
150
165
|
pages (int): Maximum number of pages to validate via `item_collection`.
|
|
151
166
|
recursive (bool): Whether to recursively validate all related STAC objects.
|
|
152
167
|
max_depth (int): Maximum depth to traverse when recursing.
|
|
@@ -177,6 +192,8 @@ def main(
|
|
|
177
192
|
core=core,
|
|
178
193
|
links=links,
|
|
179
194
|
assets=assets,
|
|
195
|
+
assets_open_urls=not no_assets_urls,
|
|
196
|
+
headers=dict(header),
|
|
180
197
|
extensions=extensions,
|
|
181
198
|
custom=custom,
|
|
182
199
|
verbose=verbose,
|
|
@@ -1,11 +1,17 @@
|
|
|
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
|
+
import jsonschema
|
|
8
9
|
import requests # type: ignore
|
|
10
|
+
from jsonschema import Draft202012Validator
|
|
11
|
+
from referencing import Registry, Resource
|
|
12
|
+
from referencing.jsonschema import DRAFT202012
|
|
13
|
+
from referencing.retrieval import to_cached_resource
|
|
14
|
+
from referencing.typing import URI
|
|
9
15
|
|
|
10
16
|
NEW_VERSIONS = [
|
|
11
17
|
"1.0.0-beta.2",
|
|
@@ -77,7 +83,7 @@ def get_stac_type(stac_content: Dict) -> str:
|
|
|
77
83
|
return str(e)
|
|
78
84
|
|
|
79
85
|
|
|
80
|
-
def fetch_and_parse_file(input_path: str) -> Dict:
|
|
86
|
+
def fetch_and_parse_file(input_path: str, headers: Optional[Dict] = None) -> Dict:
|
|
81
87
|
"""Fetches and parses a JSON file from a URL or local file.
|
|
82
88
|
|
|
83
89
|
Given a URL or local file path to a JSON file, this function fetches the file,
|
|
@@ -87,6 +93,7 @@ def fetch_and_parse_file(input_path: str) -> Dict:
|
|
|
87
93
|
|
|
88
94
|
Args:
|
|
89
95
|
input_path: A string representing the URL or local file path to the JSON file.
|
|
96
|
+
headers: For URLs: HTTP headers to include in the request
|
|
90
97
|
|
|
91
98
|
Returns:
|
|
92
99
|
A dictionary containing the parsed contents of the JSON file.
|
|
@@ -97,7 +104,7 @@ def fetch_and_parse_file(input_path: str) -> Dict:
|
|
|
97
104
|
"""
|
|
98
105
|
try:
|
|
99
106
|
if is_url(input_path):
|
|
100
|
-
resp = requests.get(input_path)
|
|
107
|
+
resp = requests.get(input_path, headers=headers)
|
|
101
108
|
resp.raise_for_status()
|
|
102
109
|
data = resp.json()
|
|
103
110
|
else:
|
|
@@ -150,8 +157,7 @@ def set_schema_addr(version: str, stac_type: str) -> str:
|
|
|
150
157
|
|
|
151
158
|
|
|
152
159
|
def link_request(
|
|
153
|
-
link: Dict,
|
|
154
|
-
initial_message: Dict,
|
|
160
|
+
link: Dict, initial_message: Dict, open_urls: bool = True, headers: Dict = {}
|
|
155
161
|
) -> None:
|
|
156
162
|
"""Makes a request to a URL and appends it to the relevant field of the initial message.
|
|
157
163
|
|
|
@@ -159,6 +165,8 @@ def link_request(
|
|
|
159
165
|
link: A dictionary containing a "href" key which is a string representing a URL.
|
|
160
166
|
initial_message: A dictionary containing lists for "request_valid", "request_invalid",
|
|
161
167
|
"format_valid", and "format_invalid" URLs.
|
|
168
|
+
open_urls: Whether to open link href URL
|
|
169
|
+
headers: HTTP headers to include in the request
|
|
162
170
|
|
|
163
171
|
Returns:
|
|
164
172
|
None
|
|
@@ -166,17 +174,106 @@ def link_request(
|
|
|
166
174
|
"""
|
|
167
175
|
if is_url(link["href"]):
|
|
168
176
|
try:
|
|
169
|
-
if
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
if open_urls:
|
|
178
|
+
request = Request(link["href"], headers=headers)
|
|
179
|
+
if "s3" in link["href"]:
|
|
180
|
+
context = ssl._create_unverified_context()
|
|
181
|
+
response = urlopen(request, context=context)
|
|
182
|
+
else:
|
|
183
|
+
response = urlopen(request)
|
|
184
|
+
status_code = response.getcode()
|
|
185
|
+
if status_code == 200:
|
|
186
|
+
initial_message["request_valid"].append(link["href"])
|
|
177
187
|
except Exception:
|
|
178
188
|
initial_message["request_invalid"].append(link["href"])
|
|
179
189
|
initial_message["format_valid"].append(link["href"])
|
|
180
190
|
else:
|
|
181
191
|
initial_message["request_invalid"].append(link["href"])
|
|
182
192
|
initial_message["format_invalid"].append(link["href"])
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def fetch_remote_schema(uri: str) -> dict:
|
|
196
|
+
"""
|
|
197
|
+
Fetch a remote schema from a URI.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
uri (str): The URI of the schema to fetch.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
dict: The fetched schema content as a dictionary.
|
|
204
|
+
|
|
205
|
+
Raises:
|
|
206
|
+
requests.RequestException: If the request to fetch the schema fails.
|
|
207
|
+
"""
|
|
208
|
+
response = requests.get(uri)
|
|
209
|
+
response.raise_for_status()
|
|
210
|
+
return response.json()
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@to_cached_resource() # type: ignore
|
|
214
|
+
def cached_retrieve(uri: URI) -> str:
|
|
215
|
+
"""
|
|
216
|
+
Retrieve and cache a remote schema.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
uri (str): The URI of the schema.
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
str: The raw JSON string of the schema.
|
|
223
|
+
|
|
224
|
+
Raises:
|
|
225
|
+
requests.RequestException: If the request to fetch the schema fails.
|
|
226
|
+
Exception: For any other unexpected errors.
|
|
227
|
+
"""
|
|
228
|
+
try:
|
|
229
|
+
response = requests.get(uri, timeout=10) # Set a timeout for robustness
|
|
230
|
+
response.raise_for_status() # Raise an error for HTTP response codes >= 400
|
|
231
|
+
return response.text
|
|
232
|
+
except requests.exceptions.RequestException as e:
|
|
233
|
+
raise requests.RequestException(
|
|
234
|
+
f"Failed to fetch schema from {uri}: {str(e)}"
|
|
235
|
+
) from e
|
|
236
|
+
except Exception as e:
|
|
237
|
+
raise Exception(
|
|
238
|
+
f"Unexpected error while retrieving schema from {uri}: {str(e)}"
|
|
239
|
+
) from e
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def validate_with_ref_resolver(schema_path: str, content: dict) -> None:
|
|
243
|
+
"""
|
|
244
|
+
Validate a JSON document against a JSON Schema with dynamic reference resolution.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
schema_path (str): Path or URI of the JSON Schema.
|
|
248
|
+
content (dict): JSON content to validate.
|
|
249
|
+
|
|
250
|
+
Raises:
|
|
251
|
+
jsonschema.exceptions.ValidationError: If validation fails.
|
|
252
|
+
requests.RequestException: If fetching a remote schema fails.
|
|
253
|
+
FileNotFoundError: If a local schema file is not found.
|
|
254
|
+
Exception: If any other error occurs during validation.
|
|
255
|
+
"""
|
|
256
|
+
# Load the schema
|
|
257
|
+
if schema_path.startswith("http"):
|
|
258
|
+
schema = fetch_remote_schema(schema_path)
|
|
259
|
+
else:
|
|
260
|
+
try:
|
|
261
|
+
with open(schema_path, "r") as f:
|
|
262
|
+
schema = json.load(f)
|
|
263
|
+
except FileNotFoundError as e:
|
|
264
|
+
raise FileNotFoundError(f"Schema file not found: {schema_path}") from e
|
|
265
|
+
|
|
266
|
+
# Set up the resource and registry for schema resolution
|
|
267
|
+
resource: Resource = Resource(contents=schema, specification=DRAFT202012) # type: ignore
|
|
268
|
+
registry: Registry = Registry(retrieve=cached_retrieve).with_resource( # type: ignore
|
|
269
|
+
uri=schema_path, resource=resource
|
|
270
|
+
) # type: ignore
|
|
271
|
+
|
|
272
|
+
# Validate the content against the schema
|
|
273
|
+
try:
|
|
274
|
+
validator = Draft202012Validator(schema, registry=registry)
|
|
275
|
+
validator.validate(content)
|
|
276
|
+
except jsonschema.exceptions.ValidationError as e:
|
|
277
|
+
raise jsonschema.exceptions.ValidationError(f"{e.message}") from e
|
|
278
|
+
except Exception as e:
|
|
279
|
+
raise Exception(f"Unexpected error during validation: {str(e)}") from e
|