rs-client-libraries 0.2a10__tar.gz → 0.2a12__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.
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/PKG-INFO +10 -10
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/pyproject.toml +13 -13
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_client/__init__.py +1 -1
- rs_client_libraries-0.2a12/rs_client/auxip_client.py +87 -0
- rs_client_libraries-0.2a12/rs_client/cadip_client.py +88 -0
- rs_client_libraries-0.2a10/rs_client/stac_client.py → rs_client_libraries-0.2a12/rs_client/catalog_client.py +108 -183
- rs_client_libraries-0.2a12/rs_client/rs_client.py +308 -0
- rs_client_libraries-0.2a12/rs_client/stac_base.py +313 -0
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_client/staging_client.py +98 -82
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_common/config.py +7 -0
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_common/opentelemetry.py +0 -4
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_common/utils.py +10 -0
- rs_client_libraries-0.2a10/rs_client/auxip_client.py +0 -61
- rs_client_libraries-0.2a10/rs_client/cadip_client.py +0 -142
- rs_client_libraries-0.2a10/rs_client/rs_client.py +0 -439
- rs_client_libraries-0.2a10/rs_common/serialization.py +0 -86
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/LICENSE +0 -0
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/README.adoc +0 -0
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_common/__init__.py +0 -0
- {rs_client_libraries-0.2a10 → rs_client_libraries-0.2a12}/rs_common/logging.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: rs-client-libraries
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2a12
|
|
4
4
|
Summary: Copernicus Sentinel rs-client library and processing workflows.
|
|
5
5
|
Home-page: https://home.rs-python.eu/
|
|
6
6
|
License: Apache-2.0
|
|
@@ -19,17 +19,17 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
20
|
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
-
Requires-Dist: cachetools (>=5.5.
|
|
23
|
-
Requires-Dist: openapi-core (>=0.19.
|
|
24
|
-
Requires-Dist: opentelemetry-distro (>=0.
|
|
25
|
-
Requires-Dist: opentelemetry-exporter-otlp (>=1.
|
|
26
|
-
Requires-Dist: opentelemetry-instrumentation-aws-lambda (>=0.
|
|
27
|
-
Requires-Dist: opentelemetry-test-utils (>=0.
|
|
28
|
-
Requires-Dist: pystac (>=1.12.
|
|
29
|
-
Requires-Dist: pystac-client (>=0.8.
|
|
22
|
+
Requires-Dist: cachetools (>=5.5.2,<6.0.0)
|
|
23
|
+
Requires-Dist: openapi-core (>=0.19.5,<0.20.0)
|
|
24
|
+
Requires-Dist: opentelemetry-distro (>=0.53b0,<0.54)
|
|
25
|
+
Requires-Dist: opentelemetry-exporter-otlp (>=1.32.0,<2.0.0)
|
|
26
|
+
Requires-Dist: opentelemetry-instrumentation-aws-lambda (>=0.53b0,<0.54)
|
|
27
|
+
Requires-Dist: opentelemetry-test-utils (>=0.53b0,<0.54)
|
|
28
|
+
Requires-Dist: pystac (>=1.12.2,<2.0.0)
|
|
29
|
+
Requires-Dist: pystac-client (>=0.8.6,<0.9.0)
|
|
30
30
|
Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
|
|
31
31
|
Requires-Dist: python-logging-loki (>=0.3.1,<0.4.0)
|
|
32
|
-
Requires-Dist: stac-pydantic (>=3.1.
|
|
32
|
+
Requires-Dist: stac-pydantic (>=3.1.5,<4.0.0)
|
|
33
33
|
Project-URL: Documentation, https://home.rs-python.eu/rs-documentation/rs-client-libraries/docs/doc/
|
|
34
34
|
Project-URL: Repository, https://github.com/RS-PYTHON/rs-client-libraries
|
|
35
35
|
Description-Content-Type: text/plain
|
|
@@ -4,7 +4,7 @@ version = "0.0.0" # see: https://github.com/mtkennerly/poetry-dynamic-versioning
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "rs-client-libraries"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2a12"
|
|
8
8
|
description = "Copernicus Sentinel rs-client library and processing workflows."
|
|
9
9
|
license = "Apache-2.0"
|
|
10
10
|
authors = ["ESA under contract with Airbus and CS <ops_coprs@airbus.com>"]
|
|
@@ -36,23 +36,23 @@ include = [
|
|
|
36
36
|
|
|
37
37
|
[tool.poetry.dependencies]
|
|
38
38
|
python = "^3.11"
|
|
39
|
-
opentelemetry-distro = "^0.
|
|
40
|
-
opentelemetry-instrumentation-aws-lambda = "^0.
|
|
41
|
-
opentelemetry-test-utils = "^0.
|
|
42
|
-
opentelemetry-exporter-otlp = "^1.
|
|
39
|
+
opentelemetry-distro = "^0.53b0" # then run 'poetry run opentelemetry-bootstrap -a install'
|
|
40
|
+
opentelemetry-instrumentation-aws-lambda = "^0.53b0"
|
|
41
|
+
opentelemetry-test-utils = "^0.53b0"
|
|
42
|
+
opentelemetry-exporter-otlp = "^1.32.0"
|
|
43
43
|
python-logging-loki = "^0.3.1" # to avoid otl error: No module named 'logging_loki'
|
|
44
|
-
cachetools = "^5.5.
|
|
45
|
-
pystac = "^1.12.
|
|
46
|
-
pystac-client = "^0.8.
|
|
44
|
+
cachetools = "^5.5.2"
|
|
45
|
+
pystac = "^1.12.2"
|
|
46
|
+
pystac-client = "^0.8.6"
|
|
47
47
|
python-dateutil = "^2.9.0.post0"
|
|
48
|
-
stac-pydantic = "^3.1.
|
|
49
|
-
openapi-core = "^0.19.
|
|
48
|
+
stac-pydantic = "^3.1.5"
|
|
49
|
+
openapi-core = "^0.19.5"
|
|
50
50
|
|
|
51
51
|
[tool.poetry.group.dev]
|
|
52
52
|
optional = true
|
|
53
53
|
|
|
54
54
|
[tool.poetry.group.dev.dependencies]
|
|
55
|
-
pytest = "^8.3.
|
|
55
|
+
pytest = "^8.3.5"
|
|
56
56
|
pytest-cov = "^6.0.0"
|
|
57
57
|
pytest-mock = "^3.14.0"
|
|
58
58
|
pytest-error-for-skips = "^2.0.2"
|
|
@@ -67,12 +67,12 @@ sphinx = "^8.1.3"
|
|
|
67
67
|
sphinx-rtd-theme = "^3.0.2"
|
|
68
68
|
flake8 = "^7.1.1"
|
|
69
69
|
flake8-pyproject = "^1.2.3"
|
|
70
|
-
responses = "^0.25.
|
|
70
|
+
responses = "^0.25.7"
|
|
71
71
|
starlette = "^0.45.3"
|
|
72
72
|
|
|
73
73
|
[tool.poetry.group.demo.dependencies] # for hybrid mode
|
|
74
74
|
jupyterlab = "^4.2.1"
|
|
75
|
-
boto3 = "^1.
|
|
75
|
+
boto3 = "^1.37.11"
|
|
76
76
|
papermill = "^2.6.0"
|
|
77
77
|
|
|
78
78
|
[tool.poetry-dynamic-versioning] # needs: poetry self add "poetry-dynamic-versioning[plugin]"
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright 2024 CS Group
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""AuxipClient class implementation."""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from rs_client.stac_base import StacBase
|
|
21
|
+
from rs_common.config import EAuxipStation
|
|
22
|
+
from rs_common.utils import get_href_service
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AuxipClient(StacBase):
|
|
26
|
+
"""
|
|
27
|
+
AuxipClient class implementation.
|
|
28
|
+
|
|
29
|
+
Attributes: see :py:class:`RsClient`
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
|
|
33
|
+
self,
|
|
34
|
+
rs_server_href: str | None,
|
|
35
|
+
rs_server_api_key: str | None,
|
|
36
|
+
owner_id: str | None,
|
|
37
|
+
station: EAuxipStation | str,
|
|
38
|
+
logger: logging.Logger | None = None,
|
|
39
|
+
**kwargs: dict[str, Any],
|
|
40
|
+
):
|
|
41
|
+
"""
|
|
42
|
+
Initializes an AuxipClient instance.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
rs_server_href (str | None): The URL of the RS-Server. Pass None for local mode.
|
|
46
|
+
rs_server_api_key (str | None): API key for authentication.
|
|
47
|
+
owner_id (str | None): ID of the catalog owner.
|
|
48
|
+
station (EAuxipStation | str): The AUXIP station identifier.
|
|
49
|
+
logger (logging.Logger | None, optional): Logger instance (default: None).
|
|
50
|
+
**kwargs: Arbitrary keyword arguments that may include:
|
|
51
|
+
- `headers` (Optional[Dict[str, str]])
|
|
52
|
+
- `parameters` (Optional[Dict[str, Any]])
|
|
53
|
+
- `ignore_conformance` (Optional[bool])
|
|
54
|
+
- `modifier` (Callable[[Collection | Item | ItemCollection | dict[Any, Any]], None] | None)
|
|
55
|
+
- `request_modifier` (Optional[Callable[[Request], Union[Request, None]]])
|
|
56
|
+
- `stac_io` (Optional[StacApiIO])
|
|
57
|
+
- `timeout` (Optional[Timeout])
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
RuntimeError: If the provided station is not a valid AUXIP station.
|
|
61
|
+
"""
|
|
62
|
+
super().__init__(
|
|
63
|
+
rs_server_href,
|
|
64
|
+
rs_server_api_key,
|
|
65
|
+
owner_id,
|
|
66
|
+
logger,
|
|
67
|
+
get_href_service(rs_server_href, "RSPY_HOST_ADGS") + "/auxip/",
|
|
68
|
+
**kwargs,
|
|
69
|
+
)
|
|
70
|
+
try:
|
|
71
|
+
self.station: EAuxipStation = EAuxipStation[station] if isinstance(station, str) else station
|
|
72
|
+
except KeyError as e:
|
|
73
|
+
self.log_and_raise(f"There is no such AUXIP station: {station}", e)
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def href_service(self) -> str:
|
|
77
|
+
"""
|
|
78
|
+
Return the RS-Server ADGS URL hostname.
|
|
79
|
+
This URL can be overwritten using the RSPY_HOST_ADGS env variable (used e.g. for local mode).
|
|
80
|
+
Otherwise it should just be the RS-Server URL.
|
|
81
|
+
"""
|
|
82
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_ADGS") + "/auxip"
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def station_name(self) -> str:
|
|
86
|
+
"""Return the station name."""
|
|
87
|
+
return self.station.value
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Copyright 2024 CS Group
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""CadipClient class implementation."""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from rs_client.stac_base import StacBase
|
|
21
|
+
from rs_common.config import ECadipStation
|
|
22
|
+
from rs_common.utils import get_href_service
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CadipClient(StacBase):
|
|
26
|
+
"""
|
|
27
|
+
CadipClient class implementation.
|
|
28
|
+
|
|
29
|
+
Attributes: see :py:class:`RsClient`
|
|
30
|
+
station (ECadipStation): Cadip station
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
|
|
34
|
+
self,
|
|
35
|
+
rs_server_href: str | None,
|
|
36
|
+
rs_server_api_key: str | None,
|
|
37
|
+
owner_id: str | None,
|
|
38
|
+
station: str,
|
|
39
|
+
logger: logging.Logger | None = None,
|
|
40
|
+
**kwargs: dict[str, Any],
|
|
41
|
+
):
|
|
42
|
+
"""
|
|
43
|
+
Initializes a CadipClient instance.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
rs_server_href (str | None): The URL of the RS-Server. Pass None for local mode.
|
|
47
|
+
rs_server_api_key (str | None): API key for authentication.
|
|
48
|
+
owner_id (str | None): ID of the catalog owner.
|
|
49
|
+
station (EAuxipStation | str): The CADIP station identifier.
|
|
50
|
+
logger (logging.Logger | None, optional): Logger instance (default: None).
|
|
51
|
+
**kwargs: Arbitrary keyword arguments that may include:
|
|
52
|
+
- `headers` (Optional[Dict[str, str]])
|
|
53
|
+
- `parameters` (Optional[Dict[str, Any]])
|
|
54
|
+
- `ignore_conformance` (Optional[bool])
|
|
55
|
+
- `modifier` (Callable[[Collection | Item | ItemCollection | dict[Any, Any]], None] | None)
|
|
56
|
+
- `request_modifier` (Optional[Callable[[Request], Union[Request, None]]])
|
|
57
|
+
- `stac_io` (Optional[StacApiIO])
|
|
58
|
+
- `timeout` (Optional[Timeout])
|
|
59
|
+
|
|
60
|
+
Raises:
|
|
61
|
+
RuntimeError: If the provided station is not a valid CADIP station.
|
|
62
|
+
"""
|
|
63
|
+
super().__init__(
|
|
64
|
+
rs_server_href,
|
|
65
|
+
rs_server_api_key,
|
|
66
|
+
owner_id,
|
|
67
|
+
logger,
|
|
68
|
+
get_href_service(rs_server_href, "RSPY_HOST_CADIP") + "/cadip/",
|
|
69
|
+
**kwargs,
|
|
70
|
+
)
|
|
71
|
+
try:
|
|
72
|
+
self.station: ECadipStation = ECadipStation[station] if isinstance(station, str) else station
|
|
73
|
+
except KeyError as e:
|
|
74
|
+
self.log_and_raise(f"There is no such CADIP station: {station}", e)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def href_service(self) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Return the RS-Server CADIP URL hostname.
|
|
80
|
+
This URL can be overwritten using the RSPY_HOST_CADIP env variable (used e.g. for local mode).
|
|
81
|
+
Otherwise it should just be the RS-Server URL.
|
|
82
|
+
"""
|
|
83
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_CADIP") + "/cadip"
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def station_name(self) -> str:
|
|
87
|
+
"""Return the station name."""
|
|
88
|
+
return self.station.value
|
|
@@ -12,39 +12,26 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
"""Implement the class
|
|
15
|
+
"""Implement the class CatalogClient that inherits from pystact_client Client."""
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import logging
|
|
20
|
-
import
|
|
21
|
-
from functools import lru_cache
|
|
22
|
-
from typing import Any, Callable, Dict, List, Optional, Union
|
|
20
|
+
from collections.abc import Iterator
|
|
23
21
|
|
|
24
22
|
import pystac
|
|
25
|
-
from pystac import
|
|
26
|
-
from pystac.layout import HrefLayoutStrategy
|
|
27
|
-
from pystac_client import Client, Modifiable
|
|
23
|
+
from pystac import Collection, Item, Link, RelType
|
|
28
24
|
from pystac_client.collection_client import CollectionClient
|
|
29
|
-
from pystac_client.item_search import
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
from pystac_client.stac_api_io import StacApiIO, Timeout
|
|
41
|
-
from requests import Request, Response
|
|
42
|
-
|
|
43
|
-
from rs_client.rs_client import APIKEY_HEADER, TIMEOUT, RsClient
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-ancestors
|
|
47
|
-
"""StacClient inherits from both rs_client.RsClient and pystac_client.Client. The goal of this class is to
|
|
25
|
+
from pystac_client.item_search import ItemSearch
|
|
26
|
+
from requests import Response
|
|
27
|
+
|
|
28
|
+
from rs_client.rs_client import TIMEOUT
|
|
29
|
+
from rs_client.stac_base import StacBase
|
|
30
|
+
from rs_common.utils import get_href_service
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CatalogClient(StacBase): # type: ignore # pylint: disable=too-many-ancestors
|
|
34
|
+
"""CatalogClient inherits from both rs_client.RsClient and pystac_client.Client. The goal of this class is to
|
|
48
35
|
allow an user to use RS-Server services more easily than calling REST endpoints directly.
|
|
49
36
|
"""
|
|
50
37
|
|
|
@@ -52,141 +39,113 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
52
39
|
# Initialisation #
|
|
53
40
|
##################
|
|
54
41
|
|
|
55
|
-
#
|
|
56
|
-
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments, super-init-not-called
|
|
42
|
+
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
|
|
57
43
|
self,
|
|
58
|
-
id: str, # pylint: disable=redefined-builtin
|
|
59
|
-
description: str,
|
|
60
|
-
title: Optional[str] = None,
|
|
61
|
-
stac_extensions: Optional[List[str]] = None,
|
|
62
|
-
extra_fields: Optional[Dict[str, Any]] = None,
|
|
63
|
-
href: Optional[str] = None,
|
|
64
|
-
catalog_type: CatalogType = CatalogType.ABSOLUTE_PUBLISHED,
|
|
65
|
-
strategy: Optional[HrefLayoutStrategy] = None,
|
|
66
|
-
*,
|
|
67
|
-
modifier: Optional[Callable[[Modifiable], None]] = None,
|
|
68
|
-
**kwargs: Dict[str, Any],
|
|
69
|
-
):
|
|
70
|
-
"""
|
|
71
|
-
Constructor. Called only by pystac.
|
|
72
|
-
As an user: don't use this directly, call the open(...) class method instead or RsClient.get_stac_client(...).
|
|
73
|
-
"""
|
|
74
|
-
|
|
75
|
-
# Call manually the parent pystac Client constructor.
|
|
76
|
-
# The RsClient constructor will be called manually later.
|
|
77
|
-
Client.__init__(
|
|
78
|
-
self,
|
|
79
|
-
id=id,
|
|
80
|
-
description=description,
|
|
81
|
-
title=title,
|
|
82
|
-
stac_extensions=stac_extensions,
|
|
83
|
-
extra_fields=extra_fields,
|
|
84
|
-
href=href,
|
|
85
|
-
catalog_type=catalog_type,
|
|
86
|
-
strategy=strategy,
|
|
87
|
-
modifier=modifier,
|
|
88
|
-
**kwargs,
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
@classmethod
|
|
92
|
-
def open( # type: ignore # pylint: disable=arguments-renamed, too-many-arguments, too-many-positional-arguments
|
|
93
|
-
cls,
|
|
94
|
-
# RsClient parameters
|
|
95
44
|
rs_server_href: str | None,
|
|
96
45
|
rs_server_api_key: str | None,
|
|
97
|
-
rs_server_oauth2_cookie: str | None,
|
|
98
46
|
owner_id: str | None,
|
|
99
47
|
logger: logging.Logger | None = None,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# Save the API key in the HTTP headers
|
|
112
|
-
if rs_server_api_key:
|
|
113
|
-
if headers is None:
|
|
114
|
-
headers = {}
|
|
115
|
-
headers[APIKEY_HEADER] = rs_server_api_key
|
|
116
|
-
|
|
117
|
-
# Save the OAuth2 authentication cookie in the pystac client cookies
|
|
118
|
-
if rs_server_oauth2_cookie:
|
|
119
|
-
if stac_io is None:
|
|
120
|
-
stac_io = StacApiIO( # This is what is done in pystac_client/client.py::from_file
|
|
121
|
-
headers=headers,
|
|
122
|
-
parameters=parameters,
|
|
123
|
-
request_modifier=request_modifier,
|
|
124
|
-
timeout=timeout,
|
|
125
|
-
)
|
|
126
|
-
stac_io.session.cookies.set("session", rs_server_oauth2_cookie)
|
|
127
|
-
|
|
128
|
-
client: StacClient = super().open( # type: ignore
|
|
129
|
-
cls.__href_catalog(rs_server_href) + "/catalog/",
|
|
130
|
-
headers,
|
|
131
|
-
parameters,
|
|
132
|
-
ignore_conformance,
|
|
133
|
-
modifier,
|
|
134
|
-
request_modifier,
|
|
135
|
-
stac_io,
|
|
136
|
-
timeout,
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
# Manual call to the parent RsClient constructor
|
|
140
|
-
RsClient.__init__(
|
|
141
|
-
client,
|
|
142
|
-
rs_server_href=rs_server_href,
|
|
143
|
-
rs_server_api_key=rs_server_api_key,
|
|
144
|
-
owner_id=owner_id,
|
|
145
|
-
logger=logger,
|
|
48
|
+
**kwargs,
|
|
49
|
+
):
|
|
50
|
+
"""CatalogClient class constructor."""
|
|
51
|
+
super().__init__(
|
|
52
|
+
rs_server_href,
|
|
53
|
+
rs_server_api_key,
|
|
54
|
+
owner_id,
|
|
55
|
+
logger,
|
|
56
|
+
get_href_service(rs_server_href, "RSPY_HOST_CATALOG") + "/catalog/",
|
|
57
|
+
**kwargs,
|
|
146
58
|
)
|
|
147
59
|
|
|
148
|
-
return client
|
|
149
|
-
|
|
150
60
|
##############
|
|
151
61
|
# Properties #
|
|
152
62
|
##############
|
|
153
|
-
|
|
154
63
|
@property
|
|
155
|
-
def
|
|
64
|
+
def href_service(self) -> str:
|
|
156
65
|
"""
|
|
157
|
-
Return the RS-Server
|
|
66
|
+
Return the RS-Server Catalog URL hostname.
|
|
158
67
|
This URL can be overwritten using the RSPY_HOST_CATALOG env variable (used e.g. for local mode).
|
|
159
68
|
Otherwise it should just be the RS-Server URL.
|
|
160
69
|
"""
|
|
161
|
-
return self.__href_catalog(self.rs_server_href)
|
|
162
70
|
|
|
163
|
-
|
|
164
|
-
def __href_catalog(rs_server_href) -> str:
|
|
165
|
-
if from_env := os.getenv("RSPY_HOST_CATALOG", None):
|
|
166
|
-
return from_env.rstrip("/")
|
|
167
|
-
if not rs_server_href:
|
|
168
|
-
raise RuntimeError("RS-Server URL is undefined")
|
|
169
|
-
return rs_server_href.rstrip("/")
|
|
71
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_CATALOG")
|
|
170
72
|
|
|
171
|
-
def full_collection_id(self, owner_id: str | None, collection_id: str):
|
|
73
|
+
def full_collection_id(self, owner_id: str | None, collection_id: str, concat_char: str | None = None) -> str:
|
|
172
74
|
"""
|
|
173
|
-
|
|
75
|
+
Generates a full collection identifier by concatenating the owner ID and collection ID.
|
|
174
76
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
77
|
+
This function constructs a full collection ID by combining the provided `owner_id` (or a
|
|
78
|
+
default owner ID from `self.owner_id`) with `collection_id` using a specified separator.
|
|
79
|
+
|
|
80
|
+
Parameters:
|
|
81
|
+
owner_id (str | None): The owner identifier. If `None`, it defaults to `self.owner_id`.
|
|
82
|
+
collection_id (str): The collection identifier that must always be provided.
|
|
83
|
+
concat_char (str | None, optional): The character used to concatenate `owner_id`
|
|
84
|
+
and `collection_id`. Defaults to ":".
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
str: A string representing the full collection ID, formatted as:
|
|
88
|
+
`"owner_id:collection_id"` by default or using the specified `concat_char`, that may
|
|
89
|
+
be `_`.
|
|
90
|
+
|
|
91
|
+
Raises:
|
|
92
|
+
- **AttributeError**: If `self.owner_id` is not set and `owner_id` is `None`,
|
|
93
|
+
causing an attempt to concatenate a `NoneType` with a string.
|
|
94
|
+
|
|
95
|
+
Notes:
|
|
96
|
+
- This function is useful in scenarios where collections are stored with unique
|
|
97
|
+
identifiers that require owner prefixes for proper scoping.
|
|
178
98
|
"""
|
|
179
|
-
|
|
99
|
+
|
|
100
|
+
if not concat_char:
|
|
101
|
+
concat_char = ":"
|
|
102
|
+
return f"{owner_id or self.owner_id}{concat_char}{collection_id}"
|
|
180
103
|
|
|
181
104
|
################################
|
|
182
105
|
# Specific STAC implementation #
|
|
183
106
|
################################
|
|
184
107
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
108
|
+
# STAC read opperations. These can be done with pystac_client (by calling super StacBase functions)
|
|
109
|
+
|
|
110
|
+
def get_collection( # type: ignore
|
|
111
|
+
self,
|
|
112
|
+
collection_id: str,
|
|
113
|
+
owner_id: str | None = None,
|
|
114
|
+
) -> Collection | CollectionClient:
|
|
115
|
+
"""Get the requested collection"""
|
|
116
|
+
return super().get_collection(self.full_collection_id(owner_id, collection_id, ":"))
|
|
117
|
+
|
|
118
|
+
def get_items(
|
|
119
|
+
self,
|
|
120
|
+
collection_id: str,
|
|
121
|
+
items_ids: str | None = None,
|
|
122
|
+
owner_id: str | None = None,
|
|
123
|
+
) -> Iterator[Item]:
|
|
124
|
+
"""Get all items from a specific collection."""
|
|
125
|
+
return super().get_items(self.full_collection_id(owner_id, collection_id, ":"), items_ids)
|
|
126
|
+
|
|
127
|
+
def get_item(self, collection_id: str, item_id: str, owner_id: str | None = None):
|
|
128
|
+
"""Get an item from a specific collection."""
|
|
129
|
+
return super().get_item(self.full_collection_id(owner_id, collection_id, ":"), item_id)
|
|
130
|
+
|
|
131
|
+
def search( # type: ignore # pylint: disable=too-many-arguments, arguments-differ
|
|
132
|
+
self,
|
|
133
|
+
**kwargs,
|
|
134
|
+
) -> ItemSearch | None:
|
|
135
|
+
"""Search items inside a specific collection."""
|
|
136
|
+
|
|
137
|
+
kwargs["collections"] = [
|
|
138
|
+
self.full_collection_id(kwargs["owner_id"], collection, "_") for collection in kwargs["collections"]
|
|
139
|
+
] # type: ignore
|
|
140
|
+
return super().search(**kwargs) # type: ignore
|
|
141
|
+
|
|
142
|
+
# end of STAC read opperations
|
|
143
|
+
|
|
144
|
+
# STAC write opperations. These can't be done with pystac_client
|
|
145
|
+
# - add_collection
|
|
146
|
+
# - remove_collection
|
|
147
|
+
# - add_item
|
|
148
|
+
# - remove_item
|
|
190
149
|
|
|
191
150
|
def add_collection(
|
|
192
151
|
self,
|
|
@@ -234,7 +193,7 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
234
193
|
)
|
|
235
194
|
|
|
236
195
|
# Update the links
|
|
237
|
-
self.add_child(collection)
|
|
196
|
+
self.ps_client.add_child(collection)
|
|
238
197
|
|
|
239
198
|
# Restore the short collection_id at the root of the collection
|
|
240
199
|
collection.id = short_collection_id
|
|
@@ -244,7 +203,7 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
244
203
|
|
|
245
204
|
# Post the collection to the catalog
|
|
246
205
|
return self.http_session.post(
|
|
247
|
-
f"{self.
|
|
206
|
+
f"{self.href_service}/catalog/collections",
|
|
248
207
|
json=collection.to_dict(),
|
|
249
208
|
**self.apikey_headers,
|
|
250
209
|
timeout=timeout,
|
|
@@ -270,19 +229,20 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
270
229
|
full_collection_id = self.full_collection_id(owner_id, collection_id)
|
|
271
230
|
|
|
272
231
|
# Remove the collection from the "child" links of the local catalog instance
|
|
273
|
-
collection_link = f"{self.self_href.rstrip('/')}/collections/{full_collection_id}"
|
|
274
|
-
self.links = [
|
|
275
|
-
link
|
|
232
|
+
collection_link = f"{self.ps_client.self_href.rstrip('/')}/collections/{full_collection_id}"
|
|
233
|
+
self.ps_client.links = [
|
|
234
|
+
link
|
|
235
|
+
for link in self.ps_client.links
|
|
236
|
+
if not ((link.rel == pystac.RelType.CHILD) and (link.href == collection_link))
|
|
276
237
|
]
|
|
277
238
|
|
|
278
239
|
# We need to clear the cache for this and parent "get_collection" methods
|
|
279
240
|
# because their returned value must be updated.
|
|
280
|
-
self.get_collection.cache_clear()
|
|
281
|
-
Client.get_collection.cache_clear()
|
|
241
|
+
self.ps_client.get_collection.cache_clear()
|
|
282
242
|
|
|
283
243
|
# Remove the collection from the server catalog
|
|
284
244
|
return self.http_session.delete(
|
|
285
|
-
f"{self.
|
|
245
|
+
f"{self.href_service}/catalog/collections/{full_collection_id}",
|
|
286
246
|
**self.apikey_headers,
|
|
287
247
|
timeout=timeout,
|
|
288
248
|
)
|
|
@@ -315,11 +275,11 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
315
275
|
collection = self.get_collection(collection_id, owner_id)
|
|
316
276
|
|
|
317
277
|
# Update the item contents
|
|
318
|
-
collection.add_item(item)
|
|
278
|
+
collection.add_item(item) # type: ignore
|
|
319
279
|
|
|
320
280
|
# Post the item to the catalog
|
|
321
281
|
return self.http_session.post(
|
|
322
|
-
f"{self.
|
|
282
|
+
f"{self.href_service}/catalog/collections/{full_collection_id}/items",
|
|
323
283
|
json=item.to_dict(),
|
|
324
284
|
**self.apikey_headers,
|
|
325
285
|
timeout=timeout,
|
|
@@ -348,44 +308,9 @@ class StacClient(RsClient, Client): # type: ignore # pylint: disable=too-many-a
|
|
|
348
308
|
|
|
349
309
|
# Remove the collection from the server catalog
|
|
350
310
|
return self.http_session.delete(
|
|
351
|
-
f"{self.
|
|
311
|
+
f"{self.href_service}/catalog/collections/{full_collection_id}/items/{item_id}",
|
|
352
312
|
**self.apikey_headers,
|
|
353
313
|
timeout=timeout,
|
|
354
314
|
)
|
|
355
315
|
|
|
356
|
-
|
|
357
|
-
self,
|
|
358
|
-
*,
|
|
359
|
-
collection_id: str,
|
|
360
|
-
owner_id: str | None = None,
|
|
361
|
-
method: Optional[str] = "POST",
|
|
362
|
-
max_items: Optional[int] = None,
|
|
363
|
-
limit: Optional[int] = None,
|
|
364
|
-
ids: Optional[IDsLike] = None,
|
|
365
|
-
bbox: Optional[BBoxLike] = None,
|
|
366
|
-
intersects: Optional[IntersectsLike] = None,
|
|
367
|
-
datetime: Optional[DatetimeLike] = None,
|
|
368
|
-
query: Optional[QueryLike] = None,
|
|
369
|
-
stac_filter: Optional[FilterLike] = None,
|
|
370
|
-
filter_lang: Optional[str] = None,
|
|
371
|
-
sortby: Optional[SortbyLike] = None,
|
|
372
|
-
fields: Optional[FieldsLike] = None,
|
|
373
|
-
) -> ItemSearch:
|
|
374
|
-
"""Search items inside a specific collection."""
|
|
375
|
-
|
|
376
|
-
return Client.search(
|
|
377
|
-
self,
|
|
378
|
-
method=method,
|
|
379
|
-
max_items=max_items,
|
|
380
|
-
limit=limit,
|
|
381
|
-
ids=ids,
|
|
382
|
-
collections=[f"{owner_id}_{collection_id}"],
|
|
383
|
-
bbox=bbox,
|
|
384
|
-
intersects=intersects,
|
|
385
|
-
datetime=datetime,
|
|
386
|
-
query=query,
|
|
387
|
-
filter=stac_filter,
|
|
388
|
-
filter_lang=filter_lang,
|
|
389
|
-
sortby=sortby,
|
|
390
|
-
fields=fields,
|
|
391
|
-
)
|
|
316
|
+
# end of STAC write opperations
|