diff --git a/setup.cfg b/setup.cfg index babeb07..1304513 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,6 @@ install_requires = gunicorn httpx itsdangerous - pydantic-settings python-dotenv teuthology @ git+https://github.com/ceph/teuthology#egg=teuthology[test] diff --git a/src/teuthology_api/config.py b/src/teuthology_api/config.py deleted file mode 100644 index e1b9be2..0000000 --- a/src/teuthology_api/config.py +++ /dev/null @@ -1,43 +0,0 @@ -from functools import lru_cache -from pydantic_settings import BaseSettings, SettingsConfigDict -from dotenv import load_dotenv - -load_dotenv() - - -class APISettings(BaseSettings): - """ - Class for API settings. - """ - - deployment: str = "" - pulpito_url: str = "" - paddles_url: str = "" - - gh_client_id: str = "" - gh_client_secret: str = "" - gh_token_url: str = "" - gh_authorization_base_url: str = "" - gh_fetch_membership_url: str = "" - - session_secret_key: str = "" - archive_dir: str = "" - teuthology_path: str = "" - - model_config = SettingsConfigDict( - env_file=".env", env_file_encoding="utf-8", extra="ignore" - ) - # TODO: team names need to be changed below when created - admin_team: str = "ceph" # ceph's github team with *sudo* access to sepia - teuth_team: str = "teuth" # ceph's github team with access to sepia - - -@lru_cache() -def get_api_settings() -> APISettings: - """ - Returns the API settings. - """ - return APISettings() # reads variables from environment - - -settings = get_api_settings() diff --git a/src/teuthology_api/main.py b/src/teuthology_api/main.py index 93e0678..c1d8afb 100644 --- a/src/teuthology_api/main.py +++ b/src/teuthology_api/main.py @@ -2,16 +2,17 @@ import os from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware +from dotenv import load_dotenv from starlette.middleware.sessions import SessionMiddleware -from teuthology_api.config import settings from teuthology_api.routes import suite, kill, login, logout +load_dotenv() -DEPLOYMENT = settings.deployment -SESSION_SECRET_KEY = settings.session_secret_key -PULPITO_URL = settings.pulpito_url -PADDLES_URL = settings.paddles_url +DEPLOYMENT = os.getenv("DEPLOYMENT") +SESSION_SECRET_KEY = os.getenv("SESSION_SECRET_KEY") +PULPITO_URL = os.getenv("PULPITO_URL") +PADDLES_URL = os.getenv("PADDLES_URL") log = logging.getLogger(__name__) app = FastAPI() diff --git a/src/teuthology_api/routes/login.py b/src/teuthology_api/routes/login.py index e1b92d6..c4916a2 100644 --- a/src/teuthology_api/routes/login.py +++ b/src/teuthology_api/routes/login.py @@ -2,16 +2,17 @@ import os from fastapi import APIRouter, HTTPException, Request from fastapi.responses import RedirectResponse +from dotenv import load_dotenv import httpx -from teuthology_api.config import settings +load_dotenv() -GH_CLIENT_ID = settings.gh_client_id -GH_CLIENT_SECRET = settings.gh_client_secret -GH_AUTHORIZATION_BASE_URL = settings.gh_authorization_base_url -GH_TOKEN_URL = settings.gh_token_url -GH_FETCH_MEMBERSHIP_URL = settings.gh_fetch_membership_url -PULPITO_URL = settings.pulpito_url +GH_CLIENT_ID = os.getenv("GH_CLIENT_ID") +GH_CLIENT_SECRET = os.getenv("GH_CLIENT_SECRET") +GH_AUTHORIZATION_BASE_URL = os.getenv("GH_AUTHORIZATION_BASE_URL") +GH_TOKEN_URL = os.getenv("GH_TOKEN_URL") +GH_FETCH_MEMBERSHIP_URL = os.getenv("GH_FETCH_MEMBERSHIP_URL") +PULPITO_URL = os.getenv("PULPITO_URL") log = logging.getLogger(__name__) router = APIRouter( diff --git a/src/teuthology_api/routes/logout.py b/src/teuthology_api/routes/logout.py index 0599f99..cdbe5ca 100644 --- a/src/teuthology_api/routes/logout.py +++ b/src/teuthology_api/routes/logout.py @@ -1,9 +1,9 @@ import logging +import os from fastapi import APIRouter, HTTPException, Request from fastapi.responses import RedirectResponse -from teuthology_api.config import settings -PULPITO_URL = settings.pulpito_url +PULPITO_URL = os.getenv("PULPITO_URL") log = logging.getLogger(__name__) router = APIRouter( diff --git a/src/teuthology_api/services/helpers.py b/src/teuthology_api/services/helpers.py index ef7abc3..a86d22c 100644 --- a/src/teuthology_api/services/helpers.py +++ b/src/teuthology_api/services/helpers.py @@ -5,15 +5,16 @@ from pathlib import Path from fastapi import HTTPException, Request - -from teuthology_api.config import settings +from dotenv import load_dotenv import teuthology import requests # Note: import requests after teuthology from requests.exceptions import HTTPError -PADDLES_URL = settings.paddles_url -ARCHIVE_DIR = settings.archive_dir +load_dotenv() + +PADDLES_URL = os.getenv("PADDLES_URL") +ARCHIVE_DIR = os.getenv("ARCHIVE_DIR") log = logging.getLogger(__name__) diff --git a/src/teuthology_api/services/kill.py b/src/teuthology_api/services/kill.py index e755c6a..4188d23 100644 --- a/src/teuthology_api/services/kill.py +++ b/src/teuthology_api/services/kill.py @@ -1,13 +1,13 @@ import logging +import os import subprocess from fastapi import HTTPException, Request -from teuthology_api.config import settings from teuthology_api.services.helpers import get_username, get_run_details -TEUTHOLOGY_PATH = settings.teuthology_path +TEUTHOLOGY_PATH = os.getenv("TEUTHOLOGY_PATH") log = logging.getLogger(__name__)