stac-validator 3.3.2__tar.gz → 3.4.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.3.2 → stac_validator-3.4.0}/PKG-INFO +20 -19
- {stac_validator-3.3.2 → stac_validator-3.4.0}/README.md +16 -15
- {stac_validator-3.3.2 → stac_validator-3.4.0}/setup.py +5 -5
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator/stac_validator.py +35 -4
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator/utilities.py +8 -5
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator/validate.py +42 -14
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/PKG-INFO +21 -20
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/SOURCES.txt +1 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_assets.py +2 -3
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_core.py +36 -0
- stac_validator-3.4.0/tests/test_validate_collections.py +55 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_validate_dict.py +2 -4
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_validate_item_collection.py +1 -2
- {stac_validator-3.3.2 → stac_validator-3.4.0}/LICENSE +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/pyproject.toml +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/setup.cfg +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator/__init__.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/dependency_links.txt +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/entry_points.txt +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/requires.txt +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/stac_validator.egg-info/top_level.txt +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_custom.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_default.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_extensions.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_links.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_recursion.py +0 -0
- {stac_validator-3.3.2 → stac_validator-3.4.0}/tests/test_sys_exit.py +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac_validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.4.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
|
|
7
|
-
Author-email:
|
|
8
|
-
License:
|
|
7
|
+
Author-email: jonathan.d.healy@gmail.com
|
|
8
|
+
License: Apache-2.0
|
|
9
9
|
Keywords: STAC validation raster
|
|
10
10
|
Classifier: Intended Audience :: Information Technology
|
|
11
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
|
-
Classifier: License :: OSI Approved ::
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
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
|
|
@@ -28,10 +28,7 @@ Requires-Dist: types-setuptools; extra == "dev"
|
|
|
28
28
|
|
|
29
29
|
[read the docs](https://stac-validator.readthedocs.io/en/latest/)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
35
32
|
|
|
36
33
|
```bash
|
|
37
34
|
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
|
|
@@ -56,10 +53,9 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
56
53
|
|
|
57
54
|
## Requirements
|
|
58
55
|
|
|
59
|
-
- Python 3.
|
|
56
|
+
- Python 3.8+
|
|
60
57
|
- Requests
|
|
61
58
|
- Click
|
|
62
|
-
- Pytest
|
|
63
59
|
- Jsonschema
|
|
64
60
|
|
|
65
61
|
Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.
|
|
@@ -85,7 +81,6 @@ or for local development
|
|
|
85
81
|
pip install -e '.[dev]'
|
|
86
82
|
```
|
|
87
83
|
|
|
88
|
-
|
|
89
84
|
The [Makefile](./Makefile) has convenience commands if Make is installed.
|
|
90
85
|
|
|
91
86
|
```bash
|
|
@@ -106,7 +101,8 @@ make help
|
|
|
106
101
|
| 1.0.0-rc.3 |
|
|
107
102
|
| 1.0.0-rc.4 |
|
|
108
103
|
| 1.0.0 |
|
|
109
|
-
|
|
104
|
+
| 1.1.0-beta.1 |
|
|
105
|
+
| 1.1.0 |
|
|
110
106
|
|
|
111
107
|
---
|
|
112
108
|
|
|
@@ -131,6 +127,7 @@ Options:
|
|
|
131
127
|
-m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this
|
|
132
128
|
argument to get full recursion. Ignored if
|
|
133
129
|
`recursive == False`.
|
|
130
|
+
--collections Validate /collections response.
|
|
134
131
|
--item-collection Validate item collection response. Can be combined
|
|
135
132
|
with --pages. Defaults to one page.
|
|
136
133
|
-p, --pages INTEGER Maximum number of pages to validate via --item-
|
|
@@ -170,7 +167,9 @@ docker run stac-validator https://raw.githubusercontent.com/stac-extensions/proj
|
|
|
170
167
|
```
|
|
171
168
|
|
|
172
169
|
## AWS (CDK)
|
|
170
|
+
|
|
173
171
|
An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
|
|
172
|
+
|
|
174
173
|
```bash
|
|
175
174
|
cd cdk-deployment
|
|
176
175
|
cdk diff
|
|
@@ -225,29 +224,29 @@ print(stac.message)
|
|
|
225
224
|
```
|
|
226
225
|
|
|
227
226
|
**Dictionary**
|
|
228
|
-
|
|
227
|
+
|
|
229
228
|
```python
|
|
230
229
|
from stac_validator import stac_validator
|
|
231
|
-
|
|
230
|
+
|
|
232
231
|
stac = stac_validator.StacValidate()
|
|
233
232
|
stac.validate_dict(dictionary)
|
|
234
233
|
print(stac.message)
|
|
235
234
|
```
|
|
236
235
|
|
|
237
236
|
**Item Collection**
|
|
238
|
-
|
|
237
|
+
|
|
239
238
|
```python
|
|
240
239
|
from stac_validator import stac_validator
|
|
241
|
-
|
|
240
|
+
|
|
242
241
|
stac = stac_validator.StacValidate()
|
|
243
242
|
stac.validate_item_collection_dict(item_collection_dict)
|
|
244
243
|
print(stac.message)
|
|
245
244
|
```
|
|
245
|
+
|
|
246
246
|
---
|
|
247
247
|
|
|
248
248
|
# Testing
|
|
249
249
|
|
|
250
|
-
|
|
251
250
|
```bash
|
|
252
251
|
make test
|
|
253
252
|
# or
|
|
@@ -257,6 +256,7 @@ pytest -v
|
|
|
257
256
|
See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
|
|
258
257
|
|
|
259
258
|
---
|
|
259
|
+
|
|
260
260
|
# Additional Examples
|
|
261
261
|
|
|
262
262
|
**--core**
|
|
@@ -316,7 +316,7 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
316
316
|
}
|
|
317
317
|
]
|
|
318
318
|
```
|
|
319
|
-
|
|
319
|
+
|
|
320
320
|
**--recursive**
|
|
321
321
|
|
|
322
322
|
```bash
|
|
@@ -348,6 +348,7 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
348
348
|
}
|
|
349
349
|
]
|
|
350
350
|
```
|
|
351
|
+
|
|
351
352
|
**--item-collection**
|
|
352
353
|
|
|
353
354
|
```bash
|
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[read the docs](https://stac-validator.readthedocs.io/en/latest/)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
11
8
|
|
|
12
9
|
```bash
|
|
13
10
|
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
|
|
@@ -32,10 +29,9 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
32
29
|
|
|
33
30
|
## Requirements
|
|
34
31
|
|
|
35
|
-
- Python 3.
|
|
32
|
+
- Python 3.8+
|
|
36
33
|
- Requests
|
|
37
34
|
- Click
|
|
38
|
-
- Pytest
|
|
39
35
|
- Jsonschema
|
|
40
36
|
|
|
41
37
|
Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.
|
|
@@ -61,7 +57,6 @@ or for local development
|
|
|
61
57
|
pip install -e '.[dev]'
|
|
62
58
|
```
|
|
63
59
|
|
|
64
|
-
|
|
65
60
|
The [Makefile](./Makefile) has convenience commands if Make is installed.
|
|
66
61
|
|
|
67
62
|
```bash
|
|
@@ -82,7 +77,8 @@ make help
|
|
|
82
77
|
| 1.0.0-rc.3 |
|
|
83
78
|
| 1.0.0-rc.4 |
|
|
84
79
|
| 1.0.0 |
|
|
85
|
-
|
|
80
|
+
| 1.1.0-beta.1 |
|
|
81
|
+
| 1.1.0 |
|
|
86
82
|
|
|
87
83
|
---
|
|
88
84
|
|
|
@@ -107,6 +103,7 @@ Options:
|
|
|
107
103
|
-m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this
|
|
108
104
|
argument to get full recursion. Ignored if
|
|
109
105
|
`recursive == False`.
|
|
106
|
+
--collections Validate /collections response.
|
|
110
107
|
--item-collection Validate item collection response. Can be combined
|
|
111
108
|
with --pages. Defaults to one page.
|
|
112
109
|
-p, --pages INTEGER Maximum number of pages to validate via --item-
|
|
@@ -146,7 +143,9 @@ docker run stac-validator https://raw.githubusercontent.com/stac-extensions/proj
|
|
|
146
143
|
```
|
|
147
144
|
|
|
148
145
|
## AWS (CDK)
|
|
146
|
+
|
|
149
147
|
An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
|
|
148
|
+
|
|
150
149
|
```bash
|
|
151
150
|
cd cdk-deployment
|
|
152
151
|
cdk diff
|
|
@@ -201,29 +200,29 @@ print(stac.message)
|
|
|
201
200
|
```
|
|
202
201
|
|
|
203
202
|
**Dictionary**
|
|
204
|
-
|
|
203
|
+
|
|
205
204
|
```python
|
|
206
205
|
from stac_validator import stac_validator
|
|
207
|
-
|
|
206
|
+
|
|
208
207
|
stac = stac_validator.StacValidate()
|
|
209
208
|
stac.validate_dict(dictionary)
|
|
210
209
|
print(stac.message)
|
|
211
210
|
```
|
|
212
211
|
|
|
213
212
|
**Item Collection**
|
|
214
|
-
|
|
213
|
+
|
|
215
214
|
```python
|
|
216
215
|
from stac_validator import stac_validator
|
|
217
|
-
|
|
216
|
+
|
|
218
217
|
stac = stac_validator.StacValidate()
|
|
219
218
|
stac.validate_item_collection_dict(item_collection_dict)
|
|
220
219
|
print(stac.message)
|
|
221
220
|
```
|
|
221
|
+
|
|
222
222
|
---
|
|
223
223
|
|
|
224
224
|
# Testing
|
|
225
225
|
|
|
226
|
-
|
|
227
226
|
```bash
|
|
228
227
|
make test
|
|
229
228
|
# or
|
|
@@ -233,6 +232,7 @@ pytest -v
|
|
|
233
232
|
See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
|
|
234
233
|
|
|
235
234
|
---
|
|
235
|
+
|
|
236
236
|
# Additional Examples
|
|
237
237
|
|
|
238
238
|
**--core**
|
|
@@ -292,7 +292,7 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
292
292
|
}
|
|
293
293
|
]
|
|
294
294
|
```
|
|
295
|
-
|
|
295
|
+
|
|
296
296
|
**--recursive**
|
|
297
297
|
|
|
298
298
|
```bash
|
|
@@ -324,8 +324,9 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
324
324
|
}
|
|
325
325
|
]
|
|
326
326
|
```
|
|
327
|
+
|
|
327
328
|
**--item-collection**
|
|
328
329
|
|
|
329
330
|
```bash
|
|
330
331
|
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
331
|
-
```
|
|
332
|
+
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from setuptools import setup
|
|
4
4
|
|
|
5
|
-
__version__ = "3.
|
|
5
|
+
__version__ = "3.4.0"
|
|
6
6
|
|
|
7
7
|
with open("README.md", "r") as fh:
|
|
8
8
|
long_description = fh.read()
|
|
@@ -11,14 +11,14 @@ setup(
|
|
|
11
11
|
name="stac_validator",
|
|
12
12
|
version=__version__,
|
|
13
13
|
author="James Banting, Jonathan Healy",
|
|
14
|
-
author_email="
|
|
14
|
+
author_email="jonathan.d.healy@gmail.com",
|
|
15
15
|
description="A package to validate STAC files",
|
|
16
|
-
license="
|
|
16
|
+
license="Apache-2.0",
|
|
17
17
|
classifiers=[
|
|
18
18
|
"Intended Audience :: Information Technology",
|
|
19
19
|
"Intended Audience :: Science/Research",
|
|
20
|
-
"License :: OSI Approved ::
|
|
21
|
-
"Programming Language :: Python :: 3.
|
|
20
|
+
"License :: OSI Approved :: Apache Software License",
|
|
21
|
+
"Programming Language :: Python :: 3.8",
|
|
22
22
|
"Topic :: Scientific/Engineering :: GIS",
|
|
23
23
|
],
|
|
24
24
|
keywords="STAC validation raster",
|
|
@@ -18,12 +18,12 @@ def print_update_message(version: str) -> None:
|
|
|
18
18
|
None
|
|
19
19
|
"""
|
|
20
20
|
click.secho()
|
|
21
|
-
if version != "1.
|
|
21
|
+
if version != "1.1.0":
|
|
22
22
|
click.secho(
|
|
23
|
-
f"Please upgrade from version {version} to version 1.
|
|
23
|
+
f"Please upgrade from version {version} to version 1.1.0!", fg="red"
|
|
24
24
|
)
|
|
25
25
|
else:
|
|
26
|
-
click.secho("Thanks for using STAC version 1.
|
|
26
|
+
click.secho("Thanks for using STAC version 1.1.0!", fg="green")
|
|
27
27
|
click.secho()
|
|
28
28
|
|
|
29
29
|
|
|
@@ -46,6 +46,25 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
46
46
|
click.secho(f"valid_items: {valid_count}")
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
def collections_summary(message: List[Dict[str, Any]]) -> None:
|
|
50
|
+
"""Prints a summary of the validation results for an item collection response.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
message (List[Dict[str, Any]]): The validation results for the item collection.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
None
|
|
57
|
+
"""
|
|
58
|
+
valid_count = 0
|
|
59
|
+
for collection in message:
|
|
60
|
+
if "valid_stac" in collection and collection["valid_stac"] is True:
|
|
61
|
+
valid_count = valid_count + 1
|
|
62
|
+
click.secho()
|
|
63
|
+
click.secho("--collections summary", bold=True)
|
|
64
|
+
click.secho(f"collections_validated: {len(message)}")
|
|
65
|
+
click.secho(f"valid_collections: {valid_count}")
|
|
66
|
+
|
|
67
|
+
|
|
49
68
|
@click.command()
|
|
50
69
|
@click.argument("stac_file")
|
|
51
70
|
@click.option(
|
|
@@ -80,6 +99,11 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
80
99
|
type=int,
|
|
81
100
|
help="Maximum depth to traverse when recursing. Omit this argument to get full recursion. Ignored if `recursive == False`.",
|
|
82
101
|
)
|
|
102
|
+
@click.option(
|
|
103
|
+
"--collections",
|
|
104
|
+
is_flag=True,
|
|
105
|
+
help="Validate /collections response.",
|
|
106
|
+
)
|
|
83
107
|
@click.option(
|
|
84
108
|
"--item-collection",
|
|
85
109
|
is_flag=True,
|
|
@@ -102,6 +126,7 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
102
126
|
)
|
|
103
127
|
def main(
|
|
104
128
|
stac_file: str,
|
|
129
|
+
collections: bool,
|
|
105
130
|
item_collection: bool,
|
|
106
131
|
pages: int,
|
|
107
132
|
recursive: bool,
|
|
@@ -120,6 +145,7 @@ def main(
|
|
|
120
145
|
|
|
121
146
|
Args:
|
|
122
147
|
stac_file (str): Path to the STAC file to be validated.
|
|
148
|
+
collections (bool): Validate response from /collections endpoint.
|
|
123
149
|
item_collection (bool): Whether to validate item collection responses.
|
|
124
150
|
pages (int): Maximum number of pages to validate via `item_collection`.
|
|
125
151
|
recursive (bool): Whether to recursively validate all related STAC objects.
|
|
@@ -143,6 +169,7 @@ def main(
|
|
|
143
169
|
valid = True
|
|
144
170
|
stac = StacValidate(
|
|
145
171
|
stac_file=stac_file,
|
|
172
|
+
collections=collections,
|
|
146
173
|
item_collection=item_collection,
|
|
147
174
|
pages=pages,
|
|
148
175
|
recursive=recursive,
|
|
@@ -155,8 +182,10 @@ def main(
|
|
|
155
182
|
verbose=verbose,
|
|
156
183
|
log=log_file,
|
|
157
184
|
)
|
|
158
|
-
if not item_collection:
|
|
185
|
+
if not item_collection and not collections:
|
|
159
186
|
valid = stac.run()
|
|
187
|
+
elif collections:
|
|
188
|
+
stac.validate_collections()
|
|
160
189
|
else:
|
|
161
190
|
stac.validate_item_collection()
|
|
162
191
|
|
|
@@ -169,6 +198,8 @@ def main(
|
|
|
169
198
|
|
|
170
199
|
if item_collection:
|
|
171
200
|
item_collection_summary(message)
|
|
201
|
+
elif collections:
|
|
202
|
+
collections_summary(message)
|
|
172
203
|
|
|
173
204
|
sys.exit(0 if valid else 1)
|
|
174
205
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import json
|
|
3
3
|
import ssl
|
|
4
|
+
from typing import Dict
|
|
4
5
|
from urllib.parse import urlparse
|
|
5
6
|
from urllib.request import urlopen
|
|
6
7
|
|
|
@@ -13,6 +14,8 @@ NEW_VERSIONS = [
|
|
|
13
14
|
"1.0.0-rc.3",
|
|
14
15
|
"1.0.0-rc.4",
|
|
15
16
|
"1.0.0",
|
|
17
|
+
"1.1.0-beta.1",
|
|
18
|
+
"1.1.0",
|
|
16
19
|
]
|
|
17
20
|
|
|
18
21
|
|
|
@@ -44,7 +47,7 @@ def is_valid_url(url: str) -> bool:
|
|
|
44
47
|
return urlparse(url).scheme in ["http", "https"]
|
|
45
48
|
|
|
46
49
|
|
|
47
|
-
def get_stac_type(stac_content:
|
|
50
|
+
def get_stac_type(stac_content: Dict) -> str:
|
|
48
51
|
"""Determine the type of a STAC resource.
|
|
49
52
|
|
|
50
53
|
Given a dictionary representing a STAC resource, this function determines the
|
|
@@ -74,7 +77,7 @@ def get_stac_type(stac_content: dict) -> str:
|
|
|
74
77
|
return str(e)
|
|
75
78
|
|
|
76
79
|
|
|
77
|
-
def fetch_and_parse_file(input_path: str) ->
|
|
80
|
+
def fetch_and_parse_file(input_path: str) -> Dict:
|
|
78
81
|
"""Fetches and parses a JSON file from a URL or local file.
|
|
79
82
|
|
|
80
83
|
Given a URL or local file path to a JSON file, this function fetches the file,
|
|
@@ -107,7 +110,7 @@ def fetch_and_parse_file(input_path: str) -> dict:
|
|
|
107
110
|
|
|
108
111
|
|
|
109
112
|
@functools.lru_cache(maxsize=48)
|
|
110
|
-
def fetch_and_parse_schema(input_path: str) ->
|
|
113
|
+
def fetch_and_parse_schema(input_path: str) -> Dict:
|
|
111
114
|
"""Fetches and parses a JSON schema file from a URL or local file using a cache.
|
|
112
115
|
|
|
113
116
|
Given a URL or local file path to a JSON schema file, this function fetches the file
|
|
@@ -147,8 +150,8 @@ def set_schema_addr(version: str, stac_type: str) -> str:
|
|
|
147
150
|
|
|
148
151
|
|
|
149
152
|
def link_request(
|
|
150
|
-
link:
|
|
151
|
-
initial_message:
|
|
153
|
+
link: Dict,
|
|
154
|
+
initial_message: Dict,
|
|
152
155
|
) -> None:
|
|
153
156
|
"""Makes a request to a URL and appends it to the relevant field of the initial message.
|
|
154
157
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
3
|
from json.decoder import JSONDecodeError
|
|
4
|
-
from typing import Optional
|
|
4
|
+
from typing import Dict, List, Optional
|
|
5
5
|
from urllib.error import HTTPError, URLError
|
|
6
6
|
|
|
7
7
|
import click # type: ignore
|
|
@@ -25,6 +25,7 @@ class StacValidate:
|
|
|
25
25
|
|
|
26
26
|
Attributes:
|
|
27
27
|
stac_file (str): The path or URL to the STAC object to be validated.
|
|
28
|
+
collections (bool): Validate response from a /collections endpoint.
|
|
28
29
|
item_collection (bool): Whether the STAC object to be validated is an item collection.
|
|
29
30
|
pages (int): The maximum number of pages to validate if `item_collection` is True.
|
|
30
31
|
recursive (bool): Whether to recursively validate related STAC objects.
|
|
@@ -45,6 +46,7 @@ class StacValidate:
|
|
|
45
46
|
def __init__(
|
|
46
47
|
self,
|
|
47
48
|
stac_file: Optional[str] = None,
|
|
49
|
+
collections: bool = False,
|
|
48
50
|
item_collection: bool = False,
|
|
49
51
|
pages: Optional[int] = None,
|
|
50
52
|
recursive: bool = False,
|
|
@@ -58,9 +60,10 @@ class StacValidate:
|
|
|
58
60
|
log: str = "",
|
|
59
61
|
):
|
|
60
62
|
self.stac_file = stac_file
|
|
63
|
+
self.collections = collections
|
|
61
64
|
self.item_collection = item_collection
|
|
62
65
|
self.pages = pages
|
|
63
|
-
self.message:
|
|
66
|
+
self.message: List = []
|
|
64
67
|
self.schema = custom
|
|
65
68
|
self.links = links
|
|
66
69
|
self.assets = assets
|
|
@@ -68,7 +71,7 @@ class StacValidate:
|
|
|
68
71
|
self.max_depth = max_depth
|
|
69
72
|
self.extensions = extensions
|
|
70
73
|
self.core = core
|
|
71
|
-
self.stac_content:
|
|
74
|
+
self.stac_content: Dict = {}
|
|
72
75
|
self.version = ""
|
|
73
76
|
self.depth: int = 0
|
|
74
77
|
self.skip_val = False
|
|
@@ -76,7 +79,7 @@ class StacValidate:
|
|
|
76
79
|
self.valid = False
|
|
77
80
|
self.log = log
|
|
78
81
|
|
|
79
|
-
def create_err_msg(self, err_type: str, err_msg: str) ->
|
|
82
|
+
def create_err_msg(self, err_type: str, err_msg: str) -> Dict:
|
|
80
83
|
self.valid = False
|
|
81
84
|
return {
|
|
82
85
|
"version": self.version,
|
|
@@ -99,7 +102,7 @@ class StacValidate:
|
|
|
99
102
|
"request_invalid": request_invalid,
|
|
100
103
|
}
|
|
101
104
|
|
|
102
|
-
def create_message(self, stac_type: str, val_type: str) ->
|
|
105
|
+
def create_message(self, stac_type: str, val_type: str) -> Dict:
|
|
103
106
|
return {
|
|
104
107
|
"version": self.version,
|
|
105
108
|
"path": self.stac_file,
|
|
@@ -109,7 +112,7 @@ class StacValidate:
|
|
|
109
112
|
"validation_method": val_type,
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
def assets_validator(self) ->
|
|
115
|
+
def assets_validator(self) -> Dict:
|
|
113
116
|
"""Validate assets.
|
|
114
117
|
|
|
115
118
|
Returns:
|
|
@@ -122,7 +125,7 @@ class StacValidate:
|
|
|
122
125
|
link_request(asset, initial_message)
|
|
123
126
|
return initial_message
|
|
124
127
|
|
|
125
|
-
def links_validator(self) ->
|
|
128
|
+
def links_validator(self) -> Dict:
|
|
126
129
|
"""Validate links.
|
|
127
130
|
|
|
128
131
|
Returns:
|
|
@@ -143,7 +146,7 @@ class StacValidate:
|
|
|
143
146
|
|
|
144
147
|
return initial_message
|
|
145
148
|
|
|
146
|
-
def extensions_validator(self, stac_type: str) ->
|
|
149
|
+
def extensions_validator(self, stac_type: str) -> Dict:
|
|
147
150
|
"""Validate the STAC extensions according to their corresponding JSON schemas.
|
|
148
151
|
|
|
149
152
|
Args:
|
|
@@ -253,7 +256,7 @@ class StacValidate:
|
|
|
253
256
|
self.schema = set_schema_addr(self.version, stac_type)
|
|
254
257
|
self.custom_validator()
|
|
255
258
|
|
|
256
|
-
def default_validator(self, stac_type: str) ->
|
|
259
|
+
def default_validator(self, stac_type: str) -> Dict:
|
|
257
260
|
"""Validate the STAC catalog or item against the core schema and its extensions.
|
|
258
261
|
|
|
259
262
|
Args:
|
|
@@ -379,7 +382,7 @@ class StacValidate:
|
|
|
379
382
|
self.stac_content = stac_content
|
|
380
383
|
return self.run()
|
|
381
384
|
|
|
382
|
-
def validate_item_collection_dict(self, item_collection:
|
|
385
|
+
def validate_item_collection_dict(self, item_collection: Dict) -> None:
|
|
383
386
|
"""Validate the contents of an item collection.
|
|
384
387
|
|
|
385
388
|
Args:
|
|
@@ -392,6 +395,27 @@ class StacValidate:
|
|
|
392
395
|
self.schema = ""
|
|
393
396
|
self.validate_dict(item)
|
|
394
397
|
|
|
398
|
+
def validate_collections(self) -> None:
|
|
399
|
+
""" "Validate STAC collections from a /collections endpoint.
|
|
400
|
+
|
|
401
|
+
Raises:
|
|
402
|
+
URLError: If there is an issue with the URL used to fetch the item collection.
|
|
403
|
+
JSONDecodeError: If the item collection content cannot be parsed as JSON.
|
|
404
|
+
ValueError: If the item collection does not conform to the STAC specification.
|
|
405
|
+
TypeError: If the item collection content is not a dictionary or JSON object.
|
|
406
|
+
FileNotFoundError: If the item collection file cannot be found.
|
|
407
|
+
ConnectionError: If there is an issue with the internet connection used to fetch the item collection.
|
|
408
|
+
exceptions.SSLError: If there is an issue with the SSL connection used to fetch the item collection.
|
|
409
|
+
OSError: If there is an issue with the file system (e.g., read/write permissions) while trying to write to the log file.
|
|
410
|
+
|
|
411
|
+
Returns:
|
|
412
|
+
None
|
|
413
|
+
"""
|
|
414
|
+
collections = fetch_and_parse_file(str(self.stac_file))
|
|
415
|
+
for collection in collections["collections"]:
|
|
416
|
+
self.schema = ""
|
|
417
|
+
self.validate_dict(collection)
|
|
418
|
+
|
|
395
419
|
def validate_item_collection(self) -> None:
|
|
396
420
|
"""Validate a STAC item collection.
|
|
397
421
|
|
|
@@ -429,9 +453,9 @@ class StacValidate:
|
|
|
429
453
|
break
|
|
430
454
|
except Exception as e:
|
|
431
455
|
message = {}
|
|
432
|
-
message[
|
|
433
|
-
"
|
|
434
|
-
|
|
456
|
+
message["pagination_error"] = (
|
|
457
|
+
f"Validating the item collection failed on page {page}: {str(e)}"
|
|
458
|
+
)
|
|
435
459
|
self.message.append(message)
|
|
436
460
|
|
|
437
461
|
def run(self) -> bool:
|
|
@@ -457,7 +481,11 @@ class StacValidate:
|
|
|
457
481
|
"""
|
|
458
482
|
message = {}
|
|
459
483
|
try:
|
|
460
|
-
if
|
|
484
|
+
if (
|
|
485
|
+
self.stac_file is not None
|
|
486
|
+
and not self.item_collection
|
|
487
|
+
and not self.collections
|
|
488
|
+
):
|
|
461
489
|
self.stac_content = fetch_and_parse_file(self.stac_file)
|
|
462
490
|
|
|
463
491
|
stac_type = get_stac_type(self.stac_content).upper()
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 3.
|
|
2
|
+
Name: stac_validator
|
|
3
|
+
Version: 3.4.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
|
|
7
|
-
Author-email:
|
|
8
|
-
License:
|
|
7
|
+
Author-email: jonathan.d.healy@gmail.com
|
|
8
|
+
License: Apache-2.0
|
|
9
9
|
Keywords: STAC validation raster
|
|
10
10
|
Classifier: Intended Audience :: Information Technology
|
|
11
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
|
-
Classifier: License :: OSI Approved ::
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
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
|
|
@@ -28,10 +28,7 @@ Requires-Dist: types-setuptools; extra == "dev"
|
|
|
28
28
|
|
|
29
29
|
[read the docs](https://stac-validator.readthedocs.io/en/latest/)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
35
32
|
|
|
36
33
|
```bash
|
|
37
34
|
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
|
|
@@ -56,10 +53,9 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
56
53
|
|
|
57
54
|
## Requirements
|
|
58
55
|
|
|
59
|
-
- Python 3.
|
|
56
|
+
- Python 3.8+
|
|
60
57
|
- Requests
|
|
61
58
|
- Click
|
|
62
|
-
- Pytest
|
|
63
59
|
- Jsonschema
|
|
64
60
|
|
|
65
61
|
Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.
|
|
@@ -85,7 +81,6 @@ or for local development
|
|
|
85
81
|
pip install -e '.[dev]'
|
|
86
82
|
```
|
|
87
83
|
|
|
88
|
-
|
|
89
84
|
The [Makefile](./Makefile) has convenience commands if Make is installed.
|
|
90
85
|
|
|
91
86
|
```bash
|
|
@@ -106,7 +101,8 @@ make help
|
|
|
106
101
|
| 1.0.0-rc.3 |
|
|
107
102
|
| 1.0.0-rc.4 |
|
|
108
103
|
| 1.0.0 |
|
|
109
|
-
|
|
104
|
+
| 1.1.0-beta.1 |
|
|
105
|
+
| 1.1.0 |
|
|
110
106
|
|
|
111
107
|
---
|
|
112
108
|
|
|
@@ -131,6 +127,7 @@ Options:
|
|
|
131
127
|
-m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this
|
|
132
128
|
argument to get full recursion. Ignored if
|
|
133
129
|
`recursive == False`.
|
|
130
|
+
--collections Validate /collections response.
|
|
134
131
|
--item-collection Validate item collection response. Can be combined
|
|
135
132
|
with --pages. Defaults to one page.
|
|
136
133
|
-p, --pages INTEGER Maximum number of pages to validate via --item-
|
|
@@ -170,7 +167,9 @@ docker run stac-validator https://raw.githubusercontent.com/stac-extensions/proj
|
|
|
170
167
|
```
|
|
171
168
|
|
|
172
169
|
## AWS (CDK)
|
|
170
|
+
|
|
173
171
|
An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
|
|
172
|
+
|
|
174
173
|
```bash
|
|
175
174
|
cd cdk-deployment
|
|
176
175
|
cdk diff
|
|
@@ -225,29 +224,29 @@ print(stac.message)
|
|
|
225
224
|
```
|
|
226
225
|
|
|
227
226
|
**Dictionary**
|
|
228
|
-
|
|
227
|
+
|
|
229
228
|
```python
|
|
230
229
|
from stac_validator import stac_validator
|
|
231
|
-
|
|
230
|
+
|
|
232
231
|
stac = stac_validator.StacValidate()
|
|
233
232
|
stac.validate_dict(dictionary)
|
|
234
233
|
print(stac.message)
|
|
235
234
|
```
|
|
236
235
|
|
|
237
236
|
**Item Collection**
|
|
238
|
-
|
|
237
|
+
|
|
239
238
|
```python
|
|
240
239
|
from stac_validator import stac_validator
|
|
241
|
-
|
|
240
|
+
|
|
242
241
|
stac = stac_validator.StacValidate()
|
|
243
242
|
stac.validate_item_collection_dict(item_collection_dict)
|
|
244
243
|
print(stac.message)
|
|
245
244
|
```
|
|
245
|
+
|
|
246
246
|
---
|
|
247
247
|
|
|
248
248
|
# Testing
|
|
249
249
|
|
|
250
|
-
|
|
251
250
|
```bash
|
|
252
251
|
make test
|
|
253
252
|
# or
|
|
@@ -257,6 +256,7 @@ pytest -v
|
|
|
257
256
|
See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
|
|
258
257
|
|
|
259
258
|
---
|
|
259
|
+
|
|
260
260
|
# Additional Examples
|
|
261
261
|
|
|
262
262
|
**--core**
|
|
@@ -316,7 +316,7 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
|
|
|
316
316
|
}
|
|
317
317
|
]
|
|
318
318
|
```
|
|
319
|
-
|
|
319
|
+
|
|
320
320
|
**--recursive**
|
|
321
321
|
|
|
322
322
|
```bash
|
|
@@ -348,6 +348,7 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
|
|
|
348
348
|
}
|
|
349
349
|
]
|
|
350
350
|
```
|
|
351
|
+
|
|
351
352
|
**--item-collection**
|
|
352
353
|
|
|
353
354
|
```bash
|
|
@@ -34,10 +34,9 @@ def test_assets_v090():
|
|
|
34
34
|
"s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND8.tif",
|
|
35
35
|
],
|
|
36
36
|
"format_invalid": [],
|
|
37
|
-
"request_valid": [
|
|
38
|
-
"https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg"
|
|
39
|
-
],
|
|
37
|
+
"request_valid": [],
|
|
40
38
|
"request_invalid": [
|
|
39
|
+
"https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg",
|
|
41
40
|
"s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.xml",
|
|
42
41
|
"s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND5.tif",
|
|
43
42
|
"s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.tif",
|
|
@@ -174,3 +174,39 @@ def test_core_item_local_v100():
|
|
|
174
174
|
"validation_method": "core",
|
|
175
175
|
}
|
|
176
176
|
]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_core_collection_local_v110():
|
|
180
|
+
stac_file = "tests/test_data/v110/collection.json"
|
|
181
|
+
stac = stac_validator.StacValidate(stac_file, core=True)
|
|
182
|
+
stac.run()
|
|
183
|
+
assert stac.message == [
|
|
184
|
+
{
|
|
185
|
+
"version": "1.1.0",
|
|
186
|
+
"path": "tests/test_data/v110/collection.json",
|
|
187
|
+
"schema": [
|
|
188
|
+
"https://schemas.stacspec.org/v1.1.0/collection-spec/json-schema/collection.json"
|
|
189
|
+
],
|
|
190
|
+
"valid_stac": True,
|
|
191
|
+
"asset_type": "COLLECTION",
|
|
192
|
+
"validation_method": "core",
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def test_core_item_local_v110():
|
|
198
|
+
stac_file = "tests/test_data/v110/simple-item.json"
|
|
199
|
+
stac = stac_validator.StacValidate(stac_file, core=True)
|
|
200
|
+
stac.run()
|
|
201
|
+
assert stac.message == [
|
|
202
|
+
{
|
|
203
|
+
"version": "1.1.0",
|
|
204
|
+
"path": "tests/test_data/v110/simple-item.json",
|
|
205
|
+
"schema": [
|
|
206
|
+
"https://schemas.stacspec.org/v1.1.0/item-spec/json-schema/item.json"
|
|
207
|
+
],
|
|
208
|
+
"valid_stac": True,
|
|
209
|
+
"asset_type": "ITEM",
|
|
210
|
+
"validation_method": "core",
|
|
211
|
+
}
|
|
212
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Description: Test stac-validator on --collections (/collections validation).
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from stac_validator import stac_validator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_validate_collections_remote():
|
|
10
|
+
stac_file = "https://earth-search.aws.element84.com/v0/collections"
|
|
11
|
+
stac = stac_validator.StacValidate(stac_file, collections=True)
|
|
12
|
+
stac.validate_collections()
|
|
13
|
+
|
|
14
|
+
assert stac.message == [
|
|
15
|
+
{
|
|
16
|
+
"version": "1.0.0-beta.2",
|
|
17
|
+
"path": "https://earth-search.aws.element84.com/v0/collections",
|
|
18
|
+
"schema": [
|
|
19
|
+
"https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
|
|
20
|
+
],
|
|
21
|
+
"valid_stac": True,
|
|
22
|
+
"asset_type": "COLLECTION",
|
|
23
|
+
"validation_method": "default",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"version": "1.0.0-beta.2",
|
|
27
|
+
"path": "https://earth-search.aws.element84.com/v0/collections",
|
|
28
|
+
"schema": [
|
|
29
|
+
"https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
|
|
30
|
+
],
|
|
31
|
+
"valid_stac": True,
|
|
32
|
+
"asset_type": "COLLECTION",
|
|
33
|
+
"validation_method": "default",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"version": "1.0.0-beta.2",
|
|
37
|
+
"path": "https://earth-search.aws.element84.com/v0/collections",
|
|
38
|
+
"schema": [
|
|
39
|
+
"https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
|
|
40
|
+
],
|
|
41
|
+
"valid_stac": True,
|
|
42
|
+
"asset_type": "COLLECTION",
|
|
43
|
+
"validation_method": "default",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"version": "1.0.0-beta.2",
|
|
47
|
+
"path": "https://earth-search.aws.element84.com/v0/collections",
|
|
48
|
+
"schema": [
|
|
49
|
+
"https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
|
|
50
|
+
],
|
|
51
|
+
"valid_stac": True,
|
|
52
|
+
"asset_type": "COLLECTION",
|
|
53
|
+
"validation_method": "default",
|
|
54
|
+
},
|
|
55
|
+
]
|
|
@@ -56,8 +56,7 @@ def test_correct_validate_dict_return_method():
|
|
|
56
56
|
stac = stac_validator.StacValidate()
|
|
57
57
|
with open("tests/test_data/1rc2/extensions-collection/collection.json", "r") as f:
|
|
58
58
|
good_stac = json.load(f)
|
|
59
|
-
|
|
60
|
-
return True
|
|
59
|
+
assert stac.validate_dict(good_stac)
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
def test_incorrect_validate_dict_return_method():
|
|
@@ -65,5 +64,4 @@ def test_incorrect_validate_dict_return_method():
|
|
|
65
64
|
with open("tests/test_data/1rc2/extensions-collection/collection.json", "r") as f:
|
|
66
65
|
good_stac = json.load(f)
|
|
67
66
|
bad_stac = good_stac.pop("type", None)
|
|
68
|
-
|
|
69
|
-
return True
|
|
67
|
+
assert stac.validate_dict(bad_stac) is False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|