Skip to content

Commit 7ae0519

Browse files
committed
Refactor iam client into task_handler and make toke url configurable
1 parent 235eea6 commit 7ae0519

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

config-landsat.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ worker:
44
host: https://registration-harvester-api.develop.eoepca.org/flowable-rest
55
tls: true
66
cacert: ./etc/eoepca-ca-chain.pem
7+
iam:
8+
oidc_token_endpoint_url: https://iam-auth.develop.eoepca.org/realms/eoepca/protocol/openid-connect/token
79
topics:
810
landsat_discover_data:
911
module: worker.landsat.tasks

config-sentinel.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ worker:
44
host: https://registration-harvester-api.develop.eoepca.org/flowable-rest
55
tls: true
66
cacert: ./etc/eoepca-ca-chain.pem
7+
iam:
8+
oidc_token_endpoint_url: https://iam-auth.develop.eoepca.org/realms/eoepca/protocol/openid-connect/token
79
topics:
810
sentinel_discover_data:
911
module: worker.sentinel.tasks

config-static-catalog.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ worker:
44
host: https://registration-harvester-api.develop.eoepca.org/flowable-rest
55
tls: true
66
cacert: ./etc/eoepca-ca-chain.pem
7+
iam:
8+
oidc_token_endpoint_url: https://iam-auth.develop.eoepca.org/realms/eoepca/protocol/openid-connect/token
79
topics:
810
stac_publish_catalog:
911
module: worker.stac.tasks

src/worker/common/task_handler.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from worker.common.config import worker_config
2+
from worker.common.iam import IAMClient
3+
from worker.common.secrets import worker_secrets
14
from worker.common.types import ExternalJob, JobResult, JobResultBuilder
25

36

@@ -17,6 +20,20 @@ def __init__(self, handlers_config: dict):
1720
**self.config_all.get("subscription", {}),
1821
}
1922

23+
# IAM client
24+
iam_client_id = worker_secrets.get_secret("iam_client_id", None)
25+
iam_client_secret = worker_secrets.get_secret("iam_client_secret", None)
26+
iam_oidc_token_endpoint_url = "https://iam-auth.develop.eoepca.org/realms/eoepca/protocol/openid-connect/token"
27+
iam_config = worker_config.get_all().get("iam")
28+
if iam_config is not None:
29+
token_url = iam_config.get("oidc_token_endpoint_url")
30+
if token_url is not None:
31+
iam_oidc_token_endpoint_url = token_url
32+
33+
self.iam_client = IAMClient(
34+
token_endpoint_url=iam_oidc_token_endpoint_url, client_id=iam_client_id, client_secret=iam_client_secret
35+
)
36+
2037
def execute(self, job: ExternalJob, result: JobResultBuilder, config: dict) -> JobResult:
2138
raise NotImplementedError
2239

src/worker/stac/tasks.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,12 @@
66
from httpx import HTTPStatusError
77
from pystac import Catalog, Collection, Item, StacIO
88

9-
from worker.common.iam import IAMClient
109
from worker.common.log_utils import configure_logging, log_with_context
11-
from worker.common.secrets import worker_secrets
1210
from worker.common.task_handler import TaskHandler
1311
from worker.common.types import ExternalJob, JobResult, JobResultBuilder
1412

1513
configure_logging()
1614

17-
iam_client_id = worker_secrets.get_secret("iam_client_id", None)
18-
iam_client_secret = worker_secrets.get_secret("iam_client_secret", None)
19-
iam_oidc_token_endpoint_url = "https://iam-auth.apx.develop.eoepca.org/realms/eoepca/protocol/openid-connect/token"
20-
iam_client = IAMClient(
21-
token_endpoint_url=iam_oidc_token_endpoint_url, client_id=iam_client_id, client_secret=iam_client_secret
22-
)
23-
2415

2516
class StacCatalogHandler(TaskHandler):
2617
def execute(self, job: ExternalJob, result: JobResultBuilder, config: dict) -> JobResult:
@@ -140,7 +131,7 @@ def execute(self, job: ExternalJob, result: JobResultBuilder, config: dict) -> J
140131
return result.failure()
141132

142133
# Get token to access protected endpoints of catalog
143-
token = iam_client.get_access_token()
134+
token = self.iam_client.get_access_token()
144135
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
145136

146137
# Publish stac collection
@@ -236,7 +227,7 @@ def execute(self, job: ExternalJob, result: JobResultBuilder, config: dict) -> J
236227
return result.failure()
237228

238229
# Get token to access protected endpoints of catalog
239-
token = iam_client.get_access_token()
230+
token = self.iam_client.get_access_token()
240231
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
241232

242233
# Publish STAC item

0 commit comments

Comments
 (0)