eodash_catalog 0.0.15__py3-none-any.whl → 0.0.17__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.

Potentially problematic release.


This version of eodash_catalog might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2024-present Daniel Santillan <daniel.santillan@eox.at>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.0.15"
4
+ __version__ = "0.0.17"
@@ -4,7 +4,7 @@ import os
4
4
  import sys
5
5
  import uuid
6
6
  from collections.abc import Callable
7
- from datetime import datetime, timedelta
7
+ from datetime import datetime, timedelta, timezone
8
8
  from itertools import groupby
9
9
  from operator import itemgetter
10
10
 
@@ -27,6 +27,7 @@ from eodash_catalog.utils import (
27
27
  create_geojson_from_bbox,
28
28
  create_geojson_point,
29
29
  generate_veda_cog_link,
30
+ replace_with_env_variables,
30
31
  retrieveExtentFromWMSWMTS,
31
32
  )
32
33
 
@@ -293,7 +294,7 @@ def handle_collection_only(
293
294
  catalog, collection_config["Name"], collection_config, catalog_config, endpoint_config
294
295
  )
295
296
  times = get_collection_times_from_config(endpoint_config)
296
- if len(times) > 0 and not endpoint_config.get("Disable_Items"):
297
+ if len(times) > 0:
297
298
  for t in times:
298
299
  item = Item(
299
300
  id=t,
@@ -473,7 +474,7 @@ def handle_SH_endpoint(
473
474
  catalog: Catalog,
474
475
  options: Options,
475
476
  ) -> Collection:
476
- token = get_SH_token()
477
+ token = get_SH_token(endpoint_config)
477
478
  headers = {"Authorization": f"Bearer {token}"}
478
479
  endpoint_config["EndPoint"] = "https://services.sentinel-hub.com/api/v1/catalog/1.0.0/"
479
480
  # Overwrite collection id with type, such as ZARR or BYOC
@@ -509,8 +510,21 @@ def handle_WMS_endpoint(
509
510
  version=endpoint_config.get("Version", "1.1.1"),
510
511
  wmts=wmts,
511
512
  )
513
+ # optionally filter time results
514
+ if query := endpoint_config.get("Query"):
515
+ datetime_query = [times[0], times[-1]]
516
+ if start := query.get("Start"):
517
+ datetime_query[0] = parser.isoparse(start).replace(tzinfo=timezone.utc)
518
+ if end := query.get("End"):
519
+ datetime_query[1] = parser.isoparse(end).replace(tzinfo=timezone.utc)
520
+ # filter times based on query Start/End
521
+ times = [
522
+ datetime_str
523
+ for datetime_str in times
524
+ if datetime_query[0] <= parser.isoparse(datetime_str) < datetime_query[1]
525
+ ]
512
526
  # Create an item per time to allow visualization in stac clients
513
- if len(times) > 0 and not endpoint_config.get("Disable_Items"):
527
+ if len(times) > 0:
514
528
  for t in times:
515
529
  item = Item(
516
530
  id=t,
@@ -551,7 +565,7 @@ def generate_veda_tiles_link(endpoint_config: dict, item: str | None) -> str:
551
565
  if "NoData" in endpoint_config:
552
566
  no_data = "&no_data={}".format(endpoint_config["NoData"])
553
567
  item = f"&item={item}" if item else ""
554
- target_url = f"https://openveda.cloud/stac/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{collection}{item}{assets}{color_formula}{no_data}"
568
+ target_url = f"https://openveda.cloud/api/raster/stac/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{collection}{item}{assets}{color_formula}{no_data}"
555
569
  return target_url
556
570
 
557
571
 
@@ -567,6 +581,10 @@ def add_visualization_info(
567
581
  instanceId = os.getenv("SH_INSTANCE_ID")
568
582
  if "InstanceId" in endpoint_config:
569
583
  instanceId = endpoint_config["InstanceId"]
584
+ if env_id := endpoint_config.get("CustomSHEnvId"):
585
+ # special handling for custom environment
586
+ # (will take SH_INSTANCE_ID_{env_id}) as ENV VAR
587
+ instanceId = os.getenv(f"SH_INSTANCE_ID_{env_id}")
570
588
  extra_fields: dict[str, list[str] | dict[str, str]] = {
571
589
  "wms:layers": [endpoint_config["LayerId"]],
572
590
  "role": ["data"],
@@ -604,10 +622,13 @@ def add_visualization_info(
604
622
  media_type = "image/jpeg"
605
623
  if "MediaType" in endpoint_config:
606
624
  media_type = endpoint_config["MediaType"]
625
+ endpoint_url = endpoint_config["EndPoint"]
626
+ # custom replacing of all ENV VARS present as template in URL as {VAR}
627
+ endpoint_url = replace_with_env_variables(endpoint_url)
607
628
  stac_object.add_link(
608
629
  Link(
609
630
  rel="wms",
610
- target=endpoint_config["EndPoint"],
631
+ target=endpoint_url,
611
632
  media_type=media_type,
612
633
  title=collection_config["Name"],
613
634
  extra_fields=extra_fields,
@@ -4,12 +4,18 @@ from oauthlib.oauth2 import BackendApplicationClient
4
4
  from requests_oauthlib import OAuth2Session
5
5
 
6
6
  SH_TOKEN_URL = "https://services.sentinel-hub.com/oauth/token"
7
+ _token_cache: dict[str, str] = {}
7
8
 
8
9
 
9
- def get_SH_token() -> str:
10
+ def get_SH_token(endpoint_config: dict) -> str:
10
11
  # Your client credentials
11
- client_id = os.getenv("SH_CLIENT_ID")
12
- client_secret = os.getenv("SH_CLIENT_SECRET")
12
+ client_id = os.getenv("SH_CLIENT_ID", "")
13
+ client_secret = os.getenv("SH_CLIENT_SECRET", "")
14
+ if env_id := endpoint_config.get("CustomSHEnvId"):
15
+ client_id = os.getenv(f"SH_CLIENT_ID_{env_id}", "")
16
+ client_secret = os.getenv(f"SH_CLIENT_SECRET_{env_id}", "")
17
+ if client_id in _token_cache:
18
+ return _token_cache[client_id]
13
19
  # Create a session
14
20
  client = BackendApplicationClient(client_id=client_id)
15
21
  oauth = OAuth2Session(client=client)
@@ -18,5 +24,7 @@ def get_SH_token() -> str:
18
24
  token_url=SH_TOKEN_URL,
19
25
  client_secret=client_secret,
20
26
  )
27
+ access_token = token["access_token"]
28
+ _token_cache[client_id] = access_token
21
29
 
22
- return token["access_token"]
30
+ return access_token
eodash_catalog/utils.py CHANGED
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import re
2
3
  import threading
3
4
  import uuid
@@ -221,7 +222,7 @@ def generate_veda_cog_link(endpoint_config: dict, file_url: str | None) -> str:
221
222
 
222
223
  file_url = f"url={file_url}&" if file_url else ""
223
224
 
224
- target_url = f"https://openveda.cloud/cog/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{file_url}resampling_method=nearest{bidx}{colormap}{colormap_name}{rescale}"
225
+ target_url = f"https://openveda.cloud/api/raster/cog/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{file_url}resampling_method=nearest{bidx}{colormap}{colormap_name}{rescale}"
225
226
  return target_url
226
227
 
227
228
 
@@ -252,3 +253,18 @@ def add_single_item_if_collection_empty(collection: Collection) -> None:
252
253
  end_datetime=datetime.now(),
253
254
  )
254
255
  collection.add_item(item)
256
+
257
+
258
+ def replace_with_env_variables(s: str) -> str:
259
+ # Define the regex pattern to find text within curly brackets
260
+ pattern = r"\{(\w+)\}"
261
+
262
+ # Define the replacement function
263
+ def replacer(match):
264
+ # Extract the variable name from the match
265
+ var_name = match.group(1)
266
+ # Get the environment variable value, if it doesn't exist, keep the original placeholder
267
+ return os.getenv(var_name, match.group(0))
268
+
269
+ # Use re.sub with the replacement function
270
+ return re.sub(pattern, replacer, s)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: eodash_catalog
3
- Version: 0.0.15
3
+ Version: 0.0.17
4
4
  Summary: This package is intended to help create a compatible STAC catalog for the eodash dashboard client. It supports configuration of multiple endpoint types for information extraction.
5
5
  Project-URL: Documentation, https://github.com/eodash/eodash_catalog#readme
6
6
  Project-URL: Issues, https://github.com/eodash/eodash_catalog/issues
@@ -31,7 +31,7 @@ Requires-Dist: pyyaml<7
31
31
  Requires-Dist: redis<4
32
32
  Requires-Dist: requests-oauthlib<1.3.2
33
33
  Requires-Dist: requests<3
34
- Requires-Dist: setuptools<68
34
+ Requires-Dist: setuptools<71
35
35
  Requires-Dist: spdx-lookup<=0.3.3
36
36
  Requires-Dist: structlog<22.0
37
37
  Requires-Dist: swiftspec==0.0.2
@@ -0,0 +1,14 @@
1
+ eodash_catalog/__about__.py,sha256=uMeWZM9Lctkvy8uGfWbPMcPv8IzBMt6rC3w9hmLXsKI,138
2
+ eodash_catalog/__init__.py,sha256=_W_9emPYf6FUqc0P8L2SmADx6hGSd7PlQV3yRmCk5uM,115
3
+ eodash_catalog/duration.py,sha256=B6XOZfvNU7SuqpxuVtT1kNKODoOQJXDI6mocvA_U1ik,10816
4
+ eodash_catalog/endpoints.py,sha256=hL9rxeGcBpRr6wj6lcKxX7NtkLjP1auzwnt7zJjYVUo,33714
5
+ eodash_catalog/generate_indicators.py,sha256=DlbgMuNVPGdg8roYO7raXIeTmsMRpsyN71DYnRATATI,18790
6
+ eodash_catalog/sh_endpoint.py,sha256=F99LpYT-MGhPiwdSSysm3xBTjaQBXRUkieh-q-vhTvE,1012
7
+ eodash_catalog/stac_handling.py,sha256=BKFFhM2JhrBnEd6EbEESAIUcFncDaAb5N4aHx0uZBv4,18197
8
+ eodash_catalog/thumbnails.py,sha256=31Wk38oNQDxfhSUbMLBpHuZFhsR8v_7luYr65XQtDf0,2213
9
+ eodash_catalog/utils.py,sha256=44V-Pm9tl70nWahMPE4vl-9FzZbRkMVRQPdINdG_8F8,8975
10
+ eodash_catalog-0.0.17.dist-info/METADATA,sha256=PsfxySNapzSDipxns08iDq7vBcDw7M0ZTzmwYtswSwM,3203
11
+ eodash_catalog-0.0.17.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
+ eodash_catalog-0.0.17.dist-info/entry_points.txt,sha256=kuUQrDG1PtYd8kPjf5XM6H_NtQd9Ozwl0jjiGtAvZSM,87
13
+ eodash_catalog-0.0.17.dist-info/licenses/LICENSE.txt,sha256=oJCW5zQxnFD-J0hGz6Zh5Lkpdk1oAndmWhseTmV224E,1107
14
+ eodash_catalog-0.0.17.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- eodash_catalog/__about__.py,sha256=IVDENoZTPvh5evYDrfWrEHJJnzkDZ1pH3Gf9Il5ZGjg,138
2
- eodash_catalog/__init__.py,sha256=_W_9emPYf6FUqc0P8L2SmADx6hGSd7PlQV3yRmCk5uM,115
3
- eodash_catalog/duration.py,sha256=B6XOZfvNU7SuqpxuVtT1kNKODoOQJXDI6mocvA_U1ik,10816
4
- eodash_catalog/endpoints.py,sha256=UQtrhtxl5jNd_5SXBQrtRopLphX4mkro7tcpnOY3Ny8,32723
5
- eodash_catalog/generate_indicators.py,sha256=DlbgMuNVPGdg8roYO7raXIeTmsMRpsyN71DYnRATATI,18790
6
- eodash_catalog/sh_endpoint.py,sha256=vELooJwk269v1DNnOzb32vil96vL_SRCio8UBlx10N0,618
7
- eodash_catalog/stac_handling.py,sha256=BKFFhM2JhrBnEd6EbEESAIUcFncDaAb5N4aHx0uZBv4,18197
8
- eodash_catalog/thumbnails.py,sha256=31Wk38oNQDxfhSUbMLBpHuZFhsR8v_7luYr65XQtDf0,2213
9
- eodash_catalog/utils.py,sha256=FZIn3iwMNjdaGAlbaIHPffYkAhlIHpNU2vkMJmEcYRQ,8427
10
- eodash_catalog-0.0.15.dist-info/METADATA,sha256=AKHmY9ssYxP9hqIxVy4WY0w8VETzC7K_8aaCkjc8ZzQ,3203
11
- eodash_catalog-0.0.15.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
- eodash_catalog-0.0.15.dist-info/entry_points.txt,sha256=kuUQrDG1PtYd8kPjf5XM6H_NtQd9Ozwl0jjiGtAvZSM,87
13
- eodash_catalog-0.0.15.dist-info/licenses/LICENSE.txt,sha256=oJCW5zQxnFD-J0hGz6Zh5Lkpdk1oAndmWhseTmV224E,1107
14
- eodash_catalog-0.0.15.dist-info/RECORD,,