eodash_catalog 0.0.16__tar.gz → 0.0.17__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.

Potentially problematic release.


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

Files changed (34) hide show
  1. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.bumpversion.cfg +1 -1
  2. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/PKG-INFO +1 -1
  3. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/ruff.toml +1 -1
  4. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/__about__.py +1 -1
  5. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/endpoints.py +26 -5
  6. eodash_catalog-0.0.17/src/eodash_catalog/sh_endpoint.py +30 -0
  7. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/utils.py +16 -0
  8. eodash_catalog-0.0.16/src/eodash_catalog/sh_endpoint.py +0 -22
  9. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.github/workflows/ci.yml +0 -0
  10. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.github/workflows/python-publish.yml +0 -0
  11. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.gitignore +0 -0
  12. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.vscode/extensions.json +0 -0
  13. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/.vscode/settings.json +0 -0
  14. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/LICENSE.txt +0 -0
  15. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/README.md +0 -0
  16. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/pyproject.toml +0 -0
  17. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/requirements.txt +0 -0
  18. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/__init__.py +0 -0
  19. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/duration.py +0 -0
  20. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/generate_indicators.py +0 -0
  21. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/stac_handling.py +0 -0
  22. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/src/eodash_catalog/thumbnails.py +0 -0
  23. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/__init__.py +0 -0
  24. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/test-data/regional_forecast.json +0 -0
  25. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/test_generate.py +0 -0
  26. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-catalogs/testing.yaml +0 -0
  27. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-collections/test_CROPOMAT1.yaml +0 -0
  28. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-collections/test_see_solar_energy.yaml +0 -0
  29. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-collections/test_tif_demo_1.yaml +0 -0
  30. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-collections/test_tif_demo_2.yaml +0 -0
  31. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-collections/test_wms_no_time.yaml +0 -0
  32. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-indicators/test_indicator.yaml +0 -0
  33. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-layers/baselayers.yaml +0 -0
  34. {eodash_catalog-0.0.16 → eodash_catalog-0.0.17}/tests/testing-layers/overlays.yaml +0 -0
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 0.0.16
2
+ current_version = 0.0.17
3
3
  commit = True
4
4
  tag = True
5
5
  parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)\.(?P<build>\d+))?
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: eodash_catalog
3
- Version: 0.0.16
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
@@ -5,4 +5,4 @@ target-version = "py312"
5
5
 
6
6
  [lint]
7
7
  select = ["E", "F", "UP", "B", "SIM", "I", "W", "C90", "ASYNC", "A", "C4", "PERF", "RUF"]
8
- ignore = ["B019", "C901"]
8
+ ignore = ["B019", "C901", "UP017"]
@@ -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.16"
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,
@@ -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,
@@ -0,0 +1,30 @@
1
+ import os
2
+
3
+ from oauthlib.oauth2 import BackendApplicationClient
4
+ from requests_oauthlib import OAuth2Session
5
+
6
+ SH_TOKEN_URL = "https://services.sentinel-hub.com/oauth/token"
7
+ _token_cache: dict[str, str] = {}
8
+
9
+
10
+ def get_SH_token(endpoint_config: dict) -> str:
11
+ # Your client credentials
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]
19
+ # Create a session
20
+ client = BackendApplicationClient(client_id=client_id)
21
+ oauth = OAuth2Session(client=client)
22
+ # Get token for the session
23
+ token = oauth.fetch_token(
24
+ token_url=SH_TOKEN_URL,
25
+ client_secret=client_secret,
26
+ )
27
+ access_token = token["access_token"]
28
+ _token_cache[client_id] = access_token
29
+
30
+ return access_token
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import re
2
3
  import threading
3
4
  import uuid
@@ -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,22 +0,0 @@
1
- import os
2
-
3
- from oauthlib.oauth2 import BackendApplicationClient
4
- from requests_oauthlib import OAuth2Session
5
-
6
- SH_TOKEN_URL = "https://services.sentinel-hub.com/oauth/token"
7
-
8
-
9
- def get_SH_token() -> str:
10
- # Your client credentials
11
- client_id = os.getenv("SH_CLIENT_ID")
12
- client_secret = os.getenv("SH_CLIENT_SECRET")
13
- # Create a session
14
- client = BackendApplicationClient(client_id=client_id)
15
- oauth = OAuth2Session(client=client)
16
- # Get token for the session
17
- token = oauth.fetch_token(
18
- token_url=SH_TOKEN_URL,
19
- client_secret=client_secret,
20
- )
21
-
22
- return token["access_token"]