-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
156 lines (123 loc) · 5.57 KB
/
config.py
File metadata and controls
156 lines (123 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Application configuration (env-driven).
This module defines configuration values as **module-level constants** so they can be imported
from anywhere without initialization. Values are read from environment variables with
developer-friendly defaults for local/dev usage.
"""
from __future__ import annotations
import os
from typing import Final
# ---------------------------------------------------------------------------
# HTTP protocol constants (stable surface)
# ---------------------------------------------------------------------------
# Standard HTTP header keys used in requests.
API_KEY_HEADER: Final[str] = "X-API-Key"
AUTHORIZATION_HEADER: Final[str] = "Authorization"
CONTENT_TYPE_HEADER: Final[str] = "Content-Type"
ACCEPT_HEADER: Final[str] = "Accept"
# Standard HTTP content type values.
JSON_CONTENT_TYPE: Final[str] = "application/json"
SSE_CONTENT_TYPE: Final[str] = "text/event-stream"
# Standard HTTP status codes.
HTTP_NOT_FOUND: Final[int] = 404
# ---------------------------------------------------------------------------
# Dashboard consumer backend (SSE credentials stream)
# ---------------------------------------------------------------------------
# Env: DASHBOARD_CONSUMER_BACKEND_URL
#
# Base URL of the Dashboard Consumer Backend service that provides the SSE stream for credentials.
# Example (docker): http://dashboard_backend:28000
DASHBOARD_CONSUMER_BACKEND_URL: Final[str] = (
os.environ.get("DASHBOARD_CONSUMER_BACKEND_URL", "http://dashboard_backend:28000")
.strip()
.rstrip("/")
)
# Env: DASHBOARD_API_KEY
#
# Token/API key used to authenticate requests to the Dashboard Consumer Backend (SSE connection).
# Note: the same value is also used as the EDC connector API key in `edc_connector/edc_config.py`.
DASHBOARD_API_KEY: Final[str] = os.environ.get("DASHBOARD_API_KEY", "dashboard-api-key")
# ---------------------------------------------------------------------------
# EDC connector location & identity
# ---------------------------------------------------------------------------
# Env: CONNECTOR_SCHEME
#
# Protocol scheme used for connector URLs.
CONNECTOR_SCHEME: Final[str] = (
os.environ.get("CONNECTOR_SCHEME", "https").strip().lower()
)
# Env: DASHBOARD_CONNECTOR_HOST
#
# Hostname where the dashboard connector is reachable.
DASHBOARD_CONNECTOR_HOST: Final[str] = os.environ.get(
"DASHBOARD_CONNECTOR_HOST", "certh.dashboard.datacellar.iti.gr"
).strip()
# Env: DASHBOARD_PARTICIPANT_ID
#
# Unique participant identifier for this EDC connector instance (also used as connector id).
DASHBOARD_PARTICIPANT_ID: Final[str] = os.environ.get(
"DASHBOARD_PARTICIPANT_ID", "certh"
).strip()
# ---------------------------------------------------------------------------
# EDC connector ports
# ---------------------------------------------------------------------------
_management_port_raw = os.environ.get("DASHBOARD_CONNECTOR_MANAGEMENT_PORT")
try:
DASHBOARD_CONNECTOR_MANAGEMENT_PORT: Final[int] = (
29193 if _management_port_raw is None else int(_management_port_raw)
)
except ValueError as exc:
raise ValueError(
f"Invalid integer for env var 'DASHBOARD_CONNECTOR_MANAGEMENT_PORT': {_management_port_raw!r}"
) from exc
_control_port_raw = os.environ.get("DASHBOARD_CONNECTOR_CONTROL_PORT")
try:
DASHBOARD_CONNECTOR_CONTROL_PORT: Final[int] = (
29192 if _control_port_raw is None else int(_control_port_raw)
)
except ValueError as exc:
raise ValueError(
f"Invalid integer for env var 'DASHBOARD_CONNECTOR_CONTROL_PORT': {_control_port_raw!r}"
) from exc
_public_port_raw = os.environ.get("DASHBOARD_CONNECTOR_PUBLIC_PORT")
try:
DASHBOARD_CONNECTOR_PUBLIC_PORT: Final[int] = (
29291 if _public_port_raw is None else int(_public_port_raw)
)
except ValueError as exc:
raise ValueError(
f"Invalid integer for env var 'DASHBOARD_CONNECTOR_PUBLIC_PORT': {_public_port_raw!r}"
) from exc
_protocol_port_raw = os.environ.get("DASHBOARD_CONNECTOR_PROTOCOL_PORT")
try:
DASHBOARD_CONNECTOR_PROTOCOL_PORT: Final[int] = (
29194 if _protocol_port_raw is None else int(_protocol_port_raw)
)
except ValueError as exc:
raise ValueError(
f"Invalid integer for env var 'DASHBOARD_CONNECTOR_PROTOCOL_PORT': {_protocol_port_raw!r}"
) from exc
# ---------------------------------------------------------------------------
# Derived/handy connector URLs (constants; safe to import)
# ---------------------------------------------------------------------------
DASHBOARD_CONNECTOR_PROTOCOL_URL: Final[str] = (
f"{CONNECTOR_SCHEME}://{DASHBOARD_CONNECTOR_HOST}:{DASHBOARD_CONNECTOR_PROTOCOL_PORT}/protocol"
)
DASHBOARD_CONNECTOR_MANAGEMENT_URL: Final[str] = (
f"{CONNECTOR_SCHEME}://{DASHBOARD_CONNECTOR_HOST}:{DASHBOARD_CONNECTOR_MANAGEMENT_PORT}"
)
DASHBOARD_CONNECTOR_CONTROL_URL: Final[str] = (
f"{CONNECTOR_SCHEME}://{DASHBOARD_CONNECTOR_HOST}:{DASHBOARD_CONNECTOR_CONTROL_PORT}"
)
DASHBOARD_CONNECTOR_PUBLIC_URL: Final[str] = (
f"{CONNECTOR_SCHEME}://{DASHBOARD_CONNECTOR_HOST}:{DASHBOARD_CONNECTOR_PUBLIC_PORT}"
)
# ---------------------------------------------------------------------------
# SSE parsing & timeouts
# ---------------------------------------------------------------------------
# Used to strip the SSE "data: " prefix during parsing.
SSE_DATA_PREFIX_LENGTH: Final[int] = len("data: ")
# The maximum duration (in seconds) to wait for credentials to arrive via the SSE stream.
CREDENTIALS_TIMEOUT_SECONDS: Final[int] = 60
# The interval (in seconds) at which to poll for received credentials while waiting.
SSE_POLL_INTERVAL_SECONDS: Final[int] = 1