rs-client-libraries 0.2__py3-none-any.whl
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.
- config/staging_templates/README.md +17 -0
- config/staging_templates/yaml/additionalParameter.yaml +30 -0
- config/staging_templates/yaml/bbox.yaml +34 -0
- config/staging_templates/yaml/binaryInputValue.yaml +15 -0
- config/staging_templates/yaml/confClasses.yaml +22 -0
- config/staging_templates/yaml/descriptionType.yaml +36 -0
- config/staging_templates/yaml/dpr_openapi_schema.yaml +223 -0
- config/staging_templates/yaml/exception.yaml +31 -0
- config/staging_templates/yaml/execute.yaml +34 -0
- config/staging_templates/yaml/format.yaml +25 -0
- config/staging_templates/yaml/inlineOrRefData.yaml +18 -0
- config/staging_templates/yaml/inputDescription.yaml +32 -0
- config/staging_templates/yaml/inputValue.yaml +17 -0
- config/staging_templates/yaml/inputValueNoObject.yaml +22 -0
- config/staging_templates/yaml/jobControlOptions.yaml +19 -0
- config/staging_templates/yaml/jobList.yaml +27 -0
- config/staging_templates/yaml/landingPage.yaml +28 -0
- config/staging_templates/yaml/link.yaml +31 -0
- config/staging_templates/yaml/metadata.yaml +22 -0
- config/staging_templates/yaml/output.yaml +20 -0
- config/staging_templates/yaml/outputDescription.yaml +22 -0
- config/staging_templates/yaml/process.yaml +23 -0
- config/staging_templates/yaml/processList.yaml +27 -0
- config/staging_templates/yaml/processSummary.yaml +37 -0
- config/staging_templates/yaml/qualifiedInputValue.yaml +22 -0
- config/staging_templates/yaml/reference.yaml +21 -0
- config/staging_templates/yaml/results.yaml +16 -0
- config/staging_templates/yaml/schema.yaml +144 -0
- config/staging_templates/yaml/staging_openapi_schema.yaml +223 -0
- config/staging_templates/yaml/statusCode.yaml +22 -0
- config/staging_templates/yaml/statusInfo.yaml +52 -0
- config/staging_templates/yaml/subscriber.yaml +33 -0
- config/staging_templates/yaml/transmissionMode.yaml +19 -0
- rs_client/__init__.py +18 -0
- rs_client/ogcapi/__init__.py +15 -0
- rs_client/ogcapi/dpr_client.py +231 -0
- rs_client/ogcapi/ogcapi_client.py +282 -0
- rs_client/ogcapi/staging_client.py +178 -0
- rs_client/rs_client.py +277 -0
- rs_client/stac/__init__.py +15 -0
- rs_client/stac/auxip_client.py +70 -0
- rs_client/stac/cadip_client.py +70 -0
- rs_client/stac/catalog_client.py +479 -0
- rs_client/stac/stac_base.py +313 -0
- rs_client_libraries-0.2.dist-info/LICENSE +201 -0
- rs_client_libraries-0.2.dist-info/METADATA +44 -0
- rs_client_libraries-0.2.dist-info/RECORD +62 -0
- rs_client_libraries-0.2.dist-info/WHEEL +4 -0
- rs_common/__init__.py +20 -0
- rs_common/config.py +69 -0
- rs_common/init_opentelemetry.py +250 -0
- rs_common/logging.py +107 -0
- rs_common/prefect_utils.py +407 -0
- rs_common/utils.py +70 -0
- rs_workflows/__init__.py +15 -0
- rs_workflows/auxip_flow.py +70 -0
- rs_workflows/cadip_flow.py +69 -0
- rs_workflows/catalog_flow.py +71 -0
- rs_workflows/dpr_flow.py +272 -0
- rs_workflows/flow_utils.py +127 -0
- rs_workflows/on_demand_processing.py +243 -0
- rs_workflows/staging_flow.py +78 -0
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
"""Launch staging with rs-client-libraries"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import math
|
|
19
|
+
import os
|
|
20
|
+
import os.path as osp
|
|
21
|
+
from collections import defaultdict
|
|
22
|
+
from collections.abc import Sequence
|
|
23
|
+
from typing import Any
|
|
24
|
+
from urllib.parse import urlparse
|
|
25
|
+
|
|
26
|
+
# openapi_core libraries used for endpoints validation
|
|
27
|
+
from openapi_core import OpenAPI # Spec, validate_request, validate_response
|
|
28
|
+
from stac_pydantic.api import Item, ItemCollection
|
|
29
|
+
|
|
30
|
+
from rs_client.ogcapi.ogcapi_client import OgcApiClient, OgcValidationException
|
|
31
|
+
from rs_common.utils import get_href_service
|
|
32
|
+
|
|
33
|
+
PATH_TO_YAML_OPENAPI = osp.realpath(
|
|
34
|
+
osp.join(
|
|
35
|
+
osp.dirname(__file__),
|
|
36
|
+
"../../config",
|
|
37
|
+
"staging_templates",
|
|
38
|
+
"yaml",
|
|
39
|
+
"staging_openapi_schema.yaml",
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
RESOURCE = "staging"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class StagingClient(OgcApiClient):
|
|
46
|
+
"""Implement the OGC API client for the staging."""
|
|
47
|
+
|
|
48
|
+
# Init the OpenAPI instance from config file
|
|
49
|
+
openapi = OpenAPI.from_file_path(PATH_TO_YAML_OPENAPI)
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def href_service(self) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Return the RS-Server staging URL hostname.
|
|
55
|
+
This URL can be overwritten using the RSPY_HOST_STAGING env variable (used e.g. for local mode).
|
|
56
|
+
Otherwise it should just be the RS-Server URL.
|
|
57
|
+
"""
|
|
58
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_STAGING")
|
|
59
|
+
|
|
60
|
+
def run_staging( # pylint: disable=too-many-locals
|
|
61
|
+
self,
|
|
62
|
+
stac_input: dict[Any, Any] | str,
|
|
63
|
+
out_coll_name: str,
|
|
64
|
+
) -> dict[str, dict]:
|
|
65
|
+
"""Method to start the staging process from rs-client - Call the endpoint /processes/staging/execution
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
stac_input (dict | str): it can be:
|
|
69
|
+
- A Python dictionary corresponding to a Feature or a FeatureCollection (that can be for example
|
|
70
|
+
the output of a search for Cadip or Auxip sessions)
|
|
71
|
+
- A json string corresponding to a Feature or a FeatureCollection
|
|
72
|
+
- A string corresponding to a path to a json file containing a Feature or a FeatureCollection
|
|
73
|
+
- A single link that returns a STAC itemCollection: this link should be an url to search a
|
|
74
|
+
itemCollection, for example:
|
|
75
|
+
http://localhost:8002/cadip/search?ids=S1A_20231120061537234567&collections=cadip_sentinel1
|
|
76
|
+
out_coll_name (str): name of the output collection
|
|
77
|
+
Return:
|
|
78
|
+
dict(hostname, job_id (int, str)): Returns the status codes of the staging requests (one per URL hostname) +
|
|
79
|
+
the identifiers
|
|
80
|
+
"""
|
|
81
|
+
stac_input_dict = {}
|
|
82
|
+
|
|
83
|
+
# ----- Case 1: we only load a link (that refers to a STAC itemCollection) in the staging request body
|
|
84
|
+
if isinstance(stac_input, str):
|
|
85
|
+
|
|
86
|
+
# Check that it's an url
|
|
87
|
+
parsed = urlparse(stac_input)
|
|
88
|
+
if parsed.scheme and parsed.netloc and parsed.hostname:
|
|
89
|
+
staging_body = {"inputs": {"collection": out_coll_name, "items": {"href": stac_input}}}
|
|
90
|
+
return {parsed.hostname: super()._run_process(RESOURCE, staging_body)}
|
|
91
|
+
|
|
92
|
+
# ----- Case 2: we directly load a STAC ItemCollection in the staging request body
|
|
93
|
+
# If stac_input is a file, load this file to a dictionary
|
|
94
|
+
if isinstance(stac_input, str):
|
|
95
|
+
# If the input is a valid path to a json_file, load this file
|
|
96
|
+
if os.path.exists(os.path.dirname(stac_input)) and stac_input.endswith(".json"):
|
|
97
|
+
# Read the yaml or json file
|
|
98
|
+
with open(stac_input, encoding="utf-8") as opened:
|
|
99
|
+
stac_file_to_dict = json.loads(opened.read())
|
|
100
|
+
stac_input_dict = stac_file_to_dict
|
|
101
|
+
# If the input string is not a path, try to convert the content of the string to a json dictionary
|
|
102
|
+
else:
|
|
103
|
+
try:
|
|
104
|
+
stac_input_dict = json.loads(stac_input)
|
|
105
|
+
except json.JSONDecodeError as e:
|
|
106
|
+
raise OgcValidationException(
|
|
107
|
+
f"""Invalid input format: {stac_input} - Input data must be either:
|
|
108
|
+
- A Python dictionary corresponding to a Feature or a FeatureCollection
|
|
109
|
+
(that can be for example the output of a search for Cadip or Auxip sessions)
|
|
110
|
+
- A json string corresponding to a Feature or a FeatureCollection
|
|
111
|
+
- A string corresponding to a path to a json file containing a Feature or a
|
|
112
|
+
FeatureCollection
|
|
113
|
+
- A single link that returns a STAC ItemCollection: this link should be an
|
|
114
|
+
url to search an ItemCollection
|
|
115
|
+
""".strip(),
|
|
116
|
+
) from e
|
|
117
|
+
else:
|
|
118
|
+
stac_input_dict = stac_input
|
|
119
|
+
|
|
120
|
+
if "type" not in stac_input_dict:
|
|
121
|
+
raise KeyError("Key 'type' is missing from the staging input data")
|
|
122
|
+
|
|
123
|
+
# Validate input data using Pydantic
|
|
124
|
+
if stac_input_dict["type"] == "Feature":
|
|
125
|
+
stac_items: Sequence[Item] = [Item(**stac_input_dict)]
|
|
126
|
+
else:
|
|
127
|
+
stac_items = ItemCollection(**stac_input_dict).features
|
|
128
|
+
|
|
129
|
+
# Order the items by station url hostname
|
|
130
|
+
hostname_items: dict[str, list[Item]] = defaultdict(list)
|
|
131
|
+
for item in stac_items:
|
|
132
|
+
assets = list(item.assets.values())
|
|
133
|
+
if assets:
|
|
134
|
+
hostname = urlparse(assets[0].href).hostname or ""
|
|
135
|
+
hostname_items[hostname].append(item)
|
|
136
|
+
|
|
137
|
+
# Trigger staging for each domain items
|
|
138
|
+
hostname_triggers: dict[str, dict] = {}
|
|
139
|
+
for hostname, items in hostname_items.items():
|
|
140
|
+
stac_item_collection = ItemCollection(type="FeatureCollection", features=items)
|
|
141
|
+
staging_body = {
|
|
142
|
+
"inputs": {
|
|
143
|
+
"collection": out_coll_name,
|
|
144
|
+
"items": {"value": stac_item_collection.model_dump(mode="json")},
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
hostname_triggers[hostname] = super()._run_process(RESOURCE, staging_body)
|
|
148
|
+
|
|
149
|
+
return hostname_triggers
|
|
150
|
+
|
|
151
|
+
def wait_for_jobs(
|
|
152
|
+
self,
|
|
153
|
+
all_job_status: dict[str, dict],
|
|
154
|
+
logger=None,
|
|
155
|
+
timeout: int | float = math.inf,
|
|
156
|
+
poll_interval: int = 2,
|
|
157
|
+
):
|
|
158
|
+
"""
|
|
159
|
+
Wait for job to finish.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
job_status: Returned by `run_staging`
|
|
163
|
+
logger: To show advancement in logger
|
|
164
|
+
timeout: Job completion timeout in seconds
|
|
165
|
+
poll_interval: When to check again for job completion in seconds
|
|
166
|
+
|
|
167
|
+
Raises:
|
|
168
|
+
RuntimeError in case of error
|
|
169
|
+
"""
|
|
170
|
+
# Call parent method for each hostname
|
|
171
|
+
for hostname, job_status in all_job_status.items():
|
|
172
|
+
super().wait_for_job(
|
|
173
|
+
job_status,
|
|
174
|
+
logger,
|
|
175
|
+
f"Staging from {hostname!r}",
|
|
176
|
+
timeout,
|
|
177
|
+
poll_interval,
|
|
178
|
+
)
|
rs_client/rs_client.py
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
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
|
+
"""RsClient class implementation."""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
import requests
|
|
22
|
+
from cachetools import TTLCache, cached
|
|
23
|
+
|
|
24
|
+
from rs_common import utils
|
|
25
|
+
from rs_common.logging import Logging
|
|
26
|
+
from rs_common.utils import AuthInfo
|
|
27
|
+
|
|
28
|
+
APIKEY_HEADER = "x-api-key"
|
|
29
|
+
|
|
30
|
+
# Timeout in seconds
|
|
31
|
+
TIMEOUT = 30
|
|
32
|
+
|
|
33
|
+
# API Key Manager URL used to get an API Key information.
|
|
34
|
+
# Works only in cluster mode. This endpoint is not exposed outside the cluster.
|
|
35
|
+
RSPY_UAC_CHECK_URL = os.getenv("RSPY_UAC_CHECK_URL", "")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RsClient: # pylint: disable=too-many-instance-attributes
|
|
39
|
+
"""
|
|
40
|
+
Client for interacting with the RS-Server services:
|
|
41
|
+
- rs-server-staging
|
|
42
|
+
- rs-server-cadip
|
|
43
|
+
- rs-server-auxip
|
|
44
|
+
- rs-server-catalog
|
|
45
|
+
|
|
46
|
+
This class provides methods to authenticate and interact with RS-Server,
|
|
47
|
+
manage STAC collections, and handle API requests.
|
|
48
|
+
|
|
49
|
+
Attributes:
|
|
50
|
+
rs_server_href (str | None): RS-Server URL. Pass None for local mode.
|
|
51
|
+
rs_server_api_key (str | None): API key for RS-Server authentication.
|
|
52
|
+
rs_server_oauth2_cookie (str | None): OAuth2 session cookie read from
|
|
53
|
+
the `RSPY_OAUTH2_COOKIE` environment variable.
|
|
54
|
+
owner_id (str | None): Only used in catalog client, see description there
|
|
55
|
+
logger (logging.Logger): Logger instance for logging messages.
|
|
56
|
+
local_mode (bool): Indicates whether the client is running in local mode.
|
|
57
|
+
apikey_headers (dict): API key headers for HTTP requests.
|
|
58
|
+
http_session (requests.Session): HTTP session for handling requests.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__( # pylint: disable=too-many-branches, too-many-arguments, too-many-positional-arguments
|
|
62
|
+
self,
|
|
63
|
+
rs_server_href: str | None,
|
|
64
|
+
rs_server_api_key: str | None = None,
|
|
65
|
+
owner_id: str | None = None,
|
|
66
|
+
logger: logging.Logger | None = None,
|
|
67
|
+
):
|
|
68
|
+
"""
|
|
69
|
+
Initializes an RsClient instance.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
rs_server_href (str | None): The URL of the RS-Server. Pass None for local mode.
|
|
73
|
+
rs_server_api_key (str | None, optional): API key for authentication (default: None).
|
|
74
|
+
owner_id (str | None, optional): ID of the catalog owner (default: None).
|
|
75
|
+
logger (logging.Logger | None, optional): Logger instance (default: None).
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
RuntimeError: If neither an API key nor an OAuth2 cookie is provided for RS-Server authentication.
|
|
79
|
+
"""
|
|
80
|
+
self.rs_server_href: str | None = rs_server_href
|
|
81
|
+
self.rs_server_api_key: str | None = rs_server_api_key
|
|
82
|
+
self.rs_server_oauth2_cookie: str | None = os.getenv("RSPY_OAUTH2_COOKIE")
|
|
83
|
+
self.owner_id: str | None = owner_id or os.getenv("RSPY_HOST_USER")
|
|
84
|
+
self.logger: logging.Logger = logger or Logging.default(__name__)
|
|
85
|
+
|
|
86
|
+
# Remove trailing / character(s) from the URL
|
|
87
|
+
if self.rs_server_href:
|
|
88
|
+
self.rs_server_href = self.rs_server_href.strip().rstrip("/").strip()
|
|
89
|
+
|
|
90
|
+
# We are in local mode if the URL is undefined.
|
|
91
|
+
# Env vars are used instead to determine the different services URL.
|
|
92
|
+
self.local_mode = not bool(self.rs_server_href)
|
|
93
|
+
|
|
94
|
+
# We are in hybrid mode if not on local mode and the API Key Manager check URL is undefined.
|
|
95
|
+
# NOTE: maybe later we could define this hybrid mode in a different way.
|
|
96
|
+
self.hybrid_mode = (not self.local_mode) and (not RSPY_UAC_CHECK_URL)
|
|
97
|
+
|
|
98
|
+
if (not self.local_mode) and (not self.rs_server_api_key) and (not self.rs_server_oauth2_cookie):
|
|
99
|
+
raise RuntimeError("API key or OAuth2 cookie is mandatory for RS-Server authentication")
|
|
100
|
+
|
|
101
|
+
# For HTTP request headers
|
|
102
|
+
self.apikey_headers: dict = (
|
|
103
|
+
{"headers": {APIKEY_HEADER: self.rs_server_api_key}} if self.rs_server_api_key else {}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# HTTP requests session with cookies
|
|
107
|
+
self.http_session = requests.Session()
|
|
108
|
+
if self.rs_server_oauth2_cookie:
|
|
109
|
+
self.http_session.cookies.set("session", self.rs_server_oauth2_cookie)
|
|
110
|
+
|
|
111
|
+
def log_and_raise(self, message: str, original: Exception):
|
|
112
|
+
"""
|
|
113
|
+
Logs an error message and raises a RuntimeError.
|
|
114
|
+
|
|
115
|
+
This method logs the provided error message using the class logger
|
|
116
|
+
and raises a `RuntimeError`, preserving the original exception as the cause.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
message (str): The error message to log.
|
|
120
|
+
original (Exception): The original exception that caused the error.
|
|
121
|
+
|
|
122
|
+
Raises:
|
|
123
|
+
RuntimeError: The logged error message, with the original exception as the cause.
|
|
124
|
+
"""
|
|
125
|
+
self.logger.exception(message)
|
|
126
|
+
raise RuntimeError(message) from original
|
|
127
|
+
|
|
128
|
+
def oauth2_security(self) -> AuthInfo:
|
|
129
|
+
"""
|
|
130
|
+
Returns:
|
|
131
|
+
Authentication information from the user keycloak account, associated to the authentication cookie.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
# In local mode, we have no authentication, so return empty results
|
|
135
|
+
if self.local_mode:
|
|
136
|
+
return AuthInfo(user_login="", iam_roles=[], apikey_config={})
|
|
137
|
+
|
|
138
|
+
# Call the endpoint to retrieve the user information
|
|
139
|
+
response = self.http_session.get(f"{self.rs_server_href}/auth/me")
|
|
140
|
+
if not response.ok:
|
|
141
|
+
raise RuntimeError(f"OAuth2 status code {response.status_code}: {utils.read_response_error(response)}")
|
|
142
|
+
|
|
143
|
+
# Decode the JSON response
|
|
144
|
+
contents = response.json()
|
|
145
|
+
return AuthInfo(
|
|
146
|
+
user_login=contents["user_login"],
|
|
147
|
+
iam_roles=contents["iam_roles"],
|
|
148
|
+
apikey_config={}, # no API key config here
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# The following variable is needed for the tests to pass
|
|
152
|
+
apikey_security_cache: TTLCache = TTLCache(maxsize=sys.maxsize, ttl=120)
|
|
153
|
+
|
|
154
|
+
@cached(cache=apikey_security_cache)
|
|
155
|
+
def apikey_security(self) -> AuthInfo:
|
|
156
|
+
"""
|
|
157
|
+
Check the api key validity. Cache an infinite (sys.maxsize) number of results for 120 seconds.
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
Authentication information from the keycloak account, associated to the api key.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
# In local mode, we have no API key, so return empty results
|
|
164
|
+
if self.local_mode:
|
|
165
|
+
return AuthInfo(user_login="", iam_roles=[], apikey_config={})
|
|
166
|
+
|
|
167
|
+
# Request the API key manager, pass user-defined api key in http header
|
|
168
|
+
self.logger.debug("Call the API key manager")
|
|
169
|
+
response = self.http_session.get(RSPY_UAC_CHECK_URL, **self.apikey_headers, timeout=TIMEOUT)
|
|
170
|
+
if not response.ok:
|
|
171
|
+
raise RuntimeError(
|
|
172
|
+
f"API key manager status code {response.status_code}: {utils.read_response_error(response)}",
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Read the api key info.
|
|
176
|
+
# Note: for now, config is an empty dict.
|
|
177
|
+
contents = response.json()
|
|
178
|
+
return AuthInfo(
|
|
179
|
+
user_login=contents["user_login"],
|
|
180
|
+
iam_roles=contents["iam_roles"],
|
|
181
|
+
apikey_config=contents["config"],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def oauth2_user_login(self) -> str:
|
|
186
|
+
"""Return the user login from the keycloak account, associated to the authentication cookie."""
|
|
187
|
+
return self.oauth2_security().user_login
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def apikey_user_login(self) -> str:
|
|
191
|
+
"""Return the user login from the keycloak account, associated to the api key."""
|
|
192
|
+
return self.apikey_security().user_login
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def oauth2_iam_roles(self) -> list[str]:
|
|
196
|
+
"""
|
|
197
|
+
Return the IAM (Identity and Access Management) roles from the keycloak account,
|
|
198
|
+
associated to the authentication cookie
|
|
199
|
+
"""
|
|
200
|
+
return self.oauth2_security().iam_roles
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def apikey_iam_roles(self) -> list[str]:
|
|
204
|
+
"""
|
|
205
|
+
Return the IAM (Identity and Access Management) roles from the keycloak account,
|
|
206
|
+
associated to the api key.
|
|
207
|
+
"""
|
|
208
|
+
return self.apikey_security().iam_roles
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def apikey_config(self) -> dict:
|
|
212
|
+
"""Return the config from the keycloak account, associated to the api key."""
|
|
213
|
+
return self.apikey_security().apikey_config
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def href_service(self):
|
|
217
|
+
"""Implemented by child classes"""
|
|
218
|
+
|
|
219
|
+
#############################
|
|
220
|
+
# Get child class instances #
|
|
221
|
+
#############################
|
|
222
|
+
|
|
223
|
+
def get_auxip_client(self, **kwargs) -> "AuxipClient": # type: ignore # noqa: F821
|
|
224
|
+
"""
|
|
225
|
+
Return an instance of the child class AuxipClient, with the same attributes as this "self" instance.
|
|
226
|
+
"""
|
|
227
|
+
from rs_client.stac.auxip_client import ( # pylint: disable=import-outside-toplevel,cyclic-import
|
|
228
|
+
AuxipClient,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
return AuxipClient(self.rs_server_href, self.rs_server_api_key, self.logger, **kwargs)
|
|
232
|
+
|
|
233
|
+
def get_cadip_client(self, **kwargs) -> "CadipClient": # type: ignore # noqa: F821
|
|
234
|
+
"""
|
|
235
|
+
Return an instance of the child class CadipClient, with the same attributes as this "self" instance.
|
|
236
|
+
"""
|
|
237
|
+
from rs_client.stac.cadip_client import ( # pylint: disable=import-outside-toplevel,cyclic-import
|
|
238
|
+
CadipClient,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
return CadipClient(self.rs_server_href, self.rs_server_api_key, self.logger, **kwargs)
|
|
242
|
+
|
|
243
|
+
def get_catalog_client(self, **kwargs) -> "CatalogClient": # type: ignore # noqa: F821
|
|
244
|
+
"""
|
|
245
|
+
Return an instance of the child class CatalogClient, with the same attributes as this "self" instance.
|
|
246
|
+
"""
|
|
247
|
+
from rs_client.stac.catalog_client import ( # pylint: disable=import-outside-toplevel,cyclic-import
|
|
248
|
+
CatalogClient,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
return CatalogClient(
|
|
252
|
+
self.rs_server_href,
|
|
253
|
+
self.rs_server_api_key,
|
|
254
|
+
self.owner_id,
|
|
255
|
+
self.logger,
|
|
256
|
+
**kwargs,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
def get_staging_client(self) -> "StagingClient": # type: ignore # noqa: F821
|
|
260
|
+
"""
|
|
261
|
+
Return an instance of the child class StagingClient, with the same attributes as this "self" instance.
|
|
262
|
+
"""
|
|
263
|
+
from rs_client.ogcapi.staging_client import ( # pylint: disable=import-outside-toplevel,cyclic-import
|
|
264
|
+
StagingClient,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
return StagingClient(self.rs_server_href, self.rs_server_api_key, None, self.logger)
|
|
268
|
+
|
|
269
|
+
def get_dpr_client(self) -> "DprClient": # type: ignore # noqa: F821
|
|
270
|
+
"""
|
|
271
|
+
Return an instance of the child class DprClient, with the same attributes as this "self" instance.
|
|
272
|
+
"""
|
|
273
|
+
from rs_client.ogcapi.dpr_client import ( # pylint: disable=import-outside-toplevel,cyclic-import
|
|
274
|
+
DprClient,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
return DprClient(self.rs_server_href, self.rs_server_api_key, None, self.logger)
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
"""stac modules"""
|
|
@@ -0,0 +1,70 @@
|
|
|
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.stac_base import StacBase
|
|
21
|
+
from rs_common.utils import get_href_service
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AuxipClient(StacBase):
|
|
25
|
+
"""
|
|
26
|
+
AuxipClient class implementation.
|
|
27
|
+
|
|
28
|
+
Attributes: see :py:class:`RsClient`
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
|
|
32
|
+
self,
|
|
33
|
+
rs_server_href: str | None,
|
|
34
|
+
rs_server_api_key: str | None,
|
|
35
|
+
logger: logging.Logger | None = None,
|
|
36
|
+
**kwargs: dict[str, Any],
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Initializes an AuxipClient instance.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
rs_server_href (str | None): The URL of the RS-Server. Pass None for local mode.
|
|
43
|
+
rs_server_api_key (str | None): API key for authentication.
|
|
44
|
+
logger (logging.Logger | None, optional): Logger instance (default: None).
|
|
45
|
+
**kwargs: Arbitrary keyword arguments that may include:
|
|
46
|
+
- `headers` (Optional[Dict[str, str]])
|
|
47
|
+
- `parameters` (Optional[Dict[str, Any]])
|
|
48
|
+
- `ignore_conformance` (Optional[bool])
|
|
49
|
+
- `modifier` (Callable[[Collection | Item | ItemCollection | dict[Any, Any]], None] | None)
|
|
50
|
+
- `request_modifier` (Optional[Callable[[Request], Union[Request, None]]])
|
|
51
|
+
- `stac_io` (Optional[StacApiIO])
|
|
52
|
+
- `timeout` (Optional[Timeout])
|
|
53
|
+
"""
|
|
54
|
+
super().__init__(
|
|
55
|
+
rs_server_href,
|
|
56
|
+
rs_server_api_key,
|
|
57
|
+
None,
|
|
58
|
+
logger,
|
|
59
|
+
get_href_service(rs_server_href, "RSPY_HOST_ADGS") + "/auxip/",
|
|
60
|
+
**kwargs,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def href_service(self) -> str:
|
|
65
|
+
"""
|
|
66
|
+
Return the RS-Server ADGS URL hostname.
|
|
67
|
+
This URL can be overwritten using the RSPY_HOST_ADGS env variable (used e.g. for local mode).
|
|
68
|
+
Otherwise it should just be the RS-Server URL.
|
|
69
|
+
"""
|
|
70
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_ADGS") + "/auxip"
|
|
@@ -0,0 +1,70 @@
|
|
|
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.stac_base import StacBase
|
|
21
|
+
from rs_common.utils import get_href_service
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CadipClient(StacBase):
|
|
25
|
+
"""
|
|
26
|
+
CadipClient class implementation.
|
|
27
|
+
|
|
28
|
+
Attributes: see :py:class:`RsClient`
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments
|
|
32
|
+
self,
|
|
33
|
+
rs_server_href: str | None,
|
|
34
|
+
rs_server_api_key: str | None,
|
|
35
|
+
logger: logging.Logger | None = None,
|
|
36
|
+
**kwargs: dict[str, Any],
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Initializes a CadipClient instance.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
rs_server_href (str | None): The URL of the RS-Server. Pass None for local mode.
|
|
43
|
+
rs_server_api_key (str | None): API key for authentication.
|
|
44
|
+
logger (logging.Logger | None, optional): Logger instance (default: None).
|
|
45
|
+
**kwargs: Arbitrary keyword arguments that may include:
|
|
46
|
+
- `headers` (Optional[Dict[str, str]])
|
|
47
|
+
- `parameters` (Optional[Dict[str, Any]])
|
|
48
|
+
- `ignore_conformance` (Optional[bool])
|
|
49
|
+
- `modifier` (Callable[[Collection | Item | ItemCollection | dict[Any, Any]], None] | None)
|
|
50
|
+
- `request_modifier` (Optional[Callable[[Request], Union[Request, None]]])
|
|
51
|
+
- `stac_io` (Optional[StacApiIO])
|
|
52
|
+
- `timeout` (Optional[Timeout])
|
|
53
|
+
"""
|
|
54
|
+
super().__init__(
|
|
55
|
+
rs_server_href,
|
|
56
|
+
rs_server_api_key,
|
|
57
|
+
None,
|
|
58
|
+
logger,
|
|
59
|
+
get_href_service(rs_server_href, "RSPY_HOST_CADIP") + "/cadip/",
|
|
60
|
+
**kwargs,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def href_service(self) -> str:
|
|
65
|
+
"""
|
|
66
|
+
Return the RS-Server CADIP URL hostname.
|
|
67
|
+
This URL can be overwritten using the RSPY_HOST_CADIP env variable (used e.g. for local mode).
|
|
68
|
+
Otherwise it should just be the RS-Server URL.
|
|
69
|
+
"""
|
|
70
|
+
return get_href_service(self.rs_server_href, "RSPY_HOST_CADIP") + "/cadip"
|