From 28b7ee9da5e6c1b2b9a4909ae837fcce1f85aeeb Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Thu, 27 Jul 2023 19:05:15 +0300 Subject: [PATCH 1/5] Initial commit --- app/routes/base.py | 8 ++++---- app/routes/models/base.py | 5 ++--- app/routes/script_launch.py | 4 +++- app/settings.py | 9 +++------ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/routes/base.py b/app/routes/base.py index f2f8108..d2c0f18 100644 --- a/app/routes/base.py +++ b/app/routes/base.py @@ -11,10 +11,10 @@ app.add_middleware( CORSMiddleware, - allow_origins=settings.CORS_ALLOW_ORIGINS, - allow_credentials=settings.CORS_ALLOW_CREDENTIALS, - allow_methods=settings.CORS_ALLOW_METHODS, - allow_headers=settings.CORS_ALLOW_HEADERS, + allow_origins=str(settings.CORS_ALLOW_ORIGINS), + allow_credentials=str(settings.CORS_ALLOW_CREDENTIALS), + allow_methods=str(settings.CORS_ALLOW_METHODS), + allow_headers=str(settings.CORS_ALLOW_HEADERS), ) app.include_router(script_router, prefix='', tags=['User']) diff --git a/app/routes/models/base.py b/app/routes/models/base.py index d96d4d5..179ff44 100644 --- a/app/routes/models/base.py +++ b/app/routes/models/base.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class Base(BaseModel): @@ -8,5 +8,4 @@ def __repr__(self) -> str: attrs.append(f"{k}={v}") return "{}({})".format(self.__class__.__name__, ', '.join(attrs)) - class Config: - orm_mode = True + model_config = ConfigDict(from_attributes=True, extra="ignore") diff --git a/app/routes/script_launch.py b/app/routes/script_launch.py index 6051085..5ceee8a 100644 --- a/app/routes/script_launch.py +++ b/app/routes/script_launch.py @@ -24,7 +24,9 @@ class SendOutput(BaseModel): async def run_script( action: str, inp: Input, - user: dict = Depends(UnionAuth(scopes=[] if settings.ALLOWED_SCOPE is None else [settings.ALLOWED_SCOPE])) + user: dict = Depends( + UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [str(settings.ALLOWED_SCOPE)]) + ), ): """runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url""" diff --git a/app/settings.py b/app/settings.py index 99025dd..24177ea 100644 --- a/app/settings.py +++ b/app/settings.py @@ -1,6 +1,7 @@ from functools import lru_cache -from pydantic import AnyUrl, BaseSettings, PostgresDsn +from pydantic import AnyUrl, ConfigDict, PostgresDsn +from pydantic_settings import BaseSettings class Settings(BaseSettings): @@ -13,11 +14,7 @@ class Settings(BaseSettings): CORS_ALLOW_METHODS: list[str] = ['*'] CORS_ALLOW_HEADERS: list[str] = ['*'] - class Config: - """Pydantic BaseSettings config""" - - case_sensitive = True - env_file = ".env" + model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore") @lru_cache From 79db896dddc002dc091ab8511bb5ca165fe7184e Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Thu, 27 Jul 2023 19:08:10 +0300 Subject: [PATCH 2/5] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9f67345..cb1d6b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ fastapi -pydantic[dotenv] +pydantic +pydantic_settings uvicorn gunicorn auth_lib_profcomff[fastapi] From 889ba42a4cd35175279c3d570fe3c4db5e1d404c Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Mon, 31 Jul 2023 21:12:40 +0300 Subject: [PATCH 3/5] Fixing --- app/routes/base.py | 4 ++-- app/routes/models/base.py | 2 +- app/routes/script_launch.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/routes/base.py b/app/routes/base.py index d2c0f18..b016770 100644 --- a/app/routes/base.py +++ b/app/routes/base.py @@ -5,13 +5,13 @@ from ..settings import Settings - + settings = Settings() app = FastAPI() app.add_middleware( CORSMiddleware, - allow_origins=str(settings.CORS_ALLOW_ORIGINS), + allow_origins=settings.CORS_ALLOW_ORIGINS, allow_credentials=str(settings.CORS_ALLOW_CREDENTIALS), allow_methods=str(settings.CORS_ALLOW_METHODS), allow_headers=str(settings.CORS_ALLOW_HEADERS), diff --git a/app/routes/models/base.py b/app/routes/models/base.py index 179ff44..7748216 100644 --- a/app/routes/models/base.py +++ b/app/routes/models/base.py @@ -4,7 +4,7 @@ class Base(BaseModel): def __repr__(self) -> str: attrs = [] - for k, v in self.__class__.schema().items(): + for k, v in self.__class__.model_json_schema().items(): attrs.append(f"{k}={v}") return "{}({})".format(self.__class__.__name__, ', '.join(attrs)) diff --git a/app/routes/script_launch.py b/app/routes/script_launch.py index 5ceee8a..1a2994d 100644 --- a/app/routes/script_launch.py +++ b/app/routes/script_launch.py @@ -25,7 +25,7 @@ async def run_script( action: str, inp: Input, user: dict = Depends( - UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [str(settings.ALLOWED_SCOPE)]) + UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [settings.ALLOWED_SCOPE]) ), ): """runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url""" From 36a84359cb5be7716aaf9280e47e090b2f409571 Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Mon, 31 Jul 2023 21:17:05 +0300 Subject: [PATCH 4/5] Black --- app/routes/base.py | 2 +- app/routes/script_launch.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/routes/base.py b/app/routes/base.py index b016770..b33b2c2 100644 --- a/app/routes/base.py +++ b/app/routes/base.py @@ -5,7 +5,7 @@ from ..settings import Settings - + settings = Settings() app = FastAPI() diff --git a/app/routes/script_launch.py b/app/routes/script_launch.py index 1a2994d..3f0c5c1 100644 --- a/app/routes/script_launch.py +++ b/app/routes/script_launch.py @@ -24,9 +24,7 @@ class SendOutput(BaseModel): async def run_script( action: str, inp: Input, - user: dict = Depends( - UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [settings.ALLOWED_SCOPE]) - ), + user: dict = Depends(UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [settings.ALLOWED_SCOPE])), ): """runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url""" From dd10f5ba9e0c18be81203e687b0c154a02b665e5 Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Mon, 31 Jul 2023 22:41:29 +0300 Subject: [PATCH 5/5] Update script_launch.py --- app/routes/script_launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes/script_launch.py b/app/routes/script_launch.py index 3f0c5c1..981150a 100644 --- a/app/routes/script_launch.py +++ b/app/routes/script_launch.py @@ -24,7 +24,7 @@ class SendOutput(BaseModel): async def run_script( action: str, inp: Input, - user: dict = Depends(UnionAuth(scopes=[] if str(settings.ALLOWED_SCOPE) is None else [settings.ALLOWED_SCOPE])), + user: dict = Depends(UnionAuth(scopes=[] if settings.ALLOWED_SCOPE is None else [settings.ALLOWED_SCOPE])), ): """runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url"""