Skip to content

Commit 374f79c

Browse files
committed
fix auth
1 parent 1eee800 commit 374f79c

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
lines changed

docker-compose.override.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
- "8501:8501"
1919
environment:
2020
- INFRAHUB_ADDRESS=http://infrahub-server:8000
21+
- INFRAHUB_API_TOKEN=${INFRAHUB_API_TOKEN:-06438eb2-8019-4776-878c-0941b1f1d1ec}
2122
- DEFAULT_BRANCH=main
2223
- GENERATOR_WAIT_TIME=60
2324
volumes:

service_catalog/Home.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from utils import (
1010
DEFAULT_BRANCH,
1111
INFRAHUB_ADDRESS,
12+
INFRAHUB_API_TOKEN,
1213
InfrahubClient,
1314
display_error,
1415
display_logo,
@@ -42,7 +43,10 @@ def main() -> None:
4243
display_logo()
4344

4445
# Initialize API client
45-
client = InfrahubClient(st.session_state.infrahub_url)
46+
client = InfrahubClient(
47+
st.session_state.infrahub_url,
48+
api_token=INFRAHUB_API_TOKEN or None
49+
)
4650

4751
# Page title
4852
st.title("Infrahub Service Catalog")

service_catalog/pages/1_Create_DC.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DEFAULT_BRANCH,
1414
GENERATOR_WAIT_TIME,
1515
INFRAHUB_ADDRESS,
16+
INFRAHUB_API_TOKEN,
1617
InfrahubClient,
1718
display_error,
1819
display_logo,
@@ -598,7 +599,10 @@ def main() -> None:
598599
}
599600

600601
# Initialize API client
601-
client = InfrahubClient(st.session_state.infrahub_url)
602+
client = InfrahubClient(
603+
st.session_state.infrahub_url,
604+
api_token=INFRAHUB_API_TOKEN or None
605+
)
602606

603607
# Execute DC creation workflow
604608
handle_dc_creation(client, form_data)

service_catalog/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
DEFAULT_BRANCH,
88
GENERATOR_WAIT_TIME,
99
INFRAHUB_ADDRESS,
10+
INFRAHUB_API_TOKEN,
1011
STREAMLIT_PORT,
1112
)
1213
from .ui import (
@@ -22,6 +23,7 @@
2223
__all__ = [
2324
"InfrahubClient",
2425
"INFRAHUB_ADDRESS",
26+
"INFRAHUB_API_TOKEN",
2527
"STREAMLIT_PORT",
2628
"DEFAULT_BRANCH",
2729
"GENERATOR_WAIT_TIME",

service_catalog/utils/api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ def __init__(self, message: str, errors: List[Dict[str, Any]]):
3939
class InfrahubClient:
4040
"""Client for interacting with the Infrahub API."""
4141

42-
def __init__(self, base_url: str, timeout: int = 30):
42+
def __init__(self, base_url: str, api_token: Optional[str] = None, timeout: int = 30):
4343
"""Initialize the Infrahub API client.
4444
4545
Args:
4646
base_url: Base URL of the Infrahub instance (e.g., "http://localhost:8000")
47+
api_token: Optional API token for authentication
4748
timeout: Request timeout in seconds (default: 30)
4849
"""
4950
self.base_url = base_url.rstrip("/")
51+
self.api_token = api_token
5052
self.timeout = timeout
5153
self.session = requests.Session()
5254

@@ -409,6 +411,10 @@ def execute_graphql(
409411
url = f"{self.base_url}/graphql"
410412
headers = {"Content-Type": "application/json", "X-INFRAHUB-BRANCH": branch}
411413

414+
# Add authentication if API token is provided
415+
if self.api_token:
416+
headers["X-INFRAHUB-KEY"] = self.api_token
417+
412418
payload: Dict[str, Any] = {"query": query}
413419
if variables:
414420
payload["variables"] = variables

service_catalog/utils/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Load environment variables
77
INFRAHUB_ADDRESS: Final[str] = os.getenv("INFRAHUB_ADDRESS", "http://localhost:8000")
8+
INFRAHUB_API_TOKEN: Final[str] = os.getenv("INFRAHUB_API_TOKEN", "")
89
STREAMLIT_PORT: Final[int] = int(os.getenv("STREAMLIT_PORT", "8501"))
910
DEFAULT_BRANCH: Final[str] = os.getenv("DEFAULT_BRANCH", "main")
1011
GENERATOR_WAIT_TIME: Final[int] = int(os.getenv("GENERATOR_WAIT_TIME", "60"))

0 commit comments

Comments
 (0)