From 760573750dff5d6fbc8b6451bd1d219b4eda88f5 Mon Sep 17 00:00:00 2001 From: crudnicky Date: Sun, 17 Oct 2021 16:26:24 -0700 Subject: [PATCH 1/4] wip --- Dockerfile | 2 +- README.md | 1 + app/main.py | 9 ++------- app/routers/__init__.py | 0 app/routers/projects.py | 11 +++++++++++ config/unlimiter.config.yaml | 21 +++++++++++++++++++++ 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 app/routers/__init__.py create mode 100644 app/routers/projects.py create mode 100644 config/unlimiter.config.yaml diff --git a/Dockerfile b/Dockerfile index dcf4d9e..9af6da2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ WORKDIR /usr/src/core-services-api RUN mkdir -p /root/.unlimiter -COPY ./.unlimiter/config.yaml /root/.unlimiter/config.yaml +COPY ./config/unlimiter.config.yaml /root/.unlimiter/config.yaml COPY --from=requirements-stage /tmp/requirements.txt /usr/src/core-services-api/requirements.txt diff --git a/README.md b/README.md index 7e14ee7..46b0fae 100644 --- a/README.md +++ b/README.md @@ -47,3 +47,4 @@ in the project root and _[follow the directions for authentication and configura |---|---| | `bash index.sh` | This command builds and starts the Core Services API inside a Docker container.| + diff --git a/app/main.py b/app/main.py index 41c3984..801374a 100644 --- a/app/main.py +++ b/app/main.py @@ -1,11 +1,6 @@ from fastapi import FastAPI - -from unlimiter.data.api import BenchlingV2APIConnection +from .routers import projects app = FastAPI() -@app.get('/') -async def root(): - with BenchlingV2APIConnection() as benchling: - projects = benchling.projects.list_projects() - return projects \ No newline at end of file +app.include_router(projects.router) \ No newline at end of file diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/routers/projects.py b/app/routers/projects.py new file mode 100644 index 0000000..7279683 --- /dev/null +++ b/app/routers/projects.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter +from unlimiter.data.api import BenchlingV2APIConnection + + +router = APIRouter() + +@router.get('/projects') +async def get_all_projects(): + with BenchlingV2APIConnection() as benchling: + projects = benchling.projects.list_projects() + return projects \ No newline at end of file diff --git a/config/unlimiter.config.yaml b/config/unlimiter.config.yaml new file mode 100644 index 0000000..5bf5364 --- /dev/null +++ b/config/unlimiter.config.yaml @@ -0,0 +1,21 @@ +asana_v1: + dev: + url: https://app.asana.com/api/1.0 + auth: + method: bearer + token: +benchling_v2: + dev: + url: https://abscidev.benchling.com/api/v2 + auth: + method: basic + username: sk_NILsCCOZZFVWWLLRr5NRd73KUATCz + password: '' +benchling_warehouse: + dev: + scheme: postgresql + url: postgres-warehouse.abscidev.benchling.com:5432/warehouse + auth: + method: basic + username: + password: \ No newline at end of file From 050b0735de065e0862f4cb88268120146092307b Mon Sep 17 00:00:00 2001 From: Chris Rudnicky Date: Sun, 17 Oct 2021 20:33:19 -0700 Subject: [PATCH 2/4] feat(architecture): add controller, routes, and servies. reconfigure docker files --- .gitignore | 2 +- Dockerfile | 2 +- {app => api/controller}/__init__.py | 0 api/controller/loupe_controller.py | 12 ++++++++++++ api/main.py | 16 ++++++++++++++++ api/routes/loupe.py | 12 ++++++++++++ app/main.py | 6 ------ app/routers/__init__.py | 0 app/routers/projects.py | 11 ----------- config/api_settings.py | 7 +++++++ docker-compose.yaml | 2 +- 11 files changed, 50 insertions(+), 20 deletions(-) rename {app => api/controller}/__init__.py (100%) create mode 100644 api/controller/loupe_controller.py create mode 100644 api/main.py create mode 100644 api/routes/loupe.py delete mode 100644 app/main.py delete mode 100644 app/routers/__init__.py delete mode 100644 app/routers/projects.py create mode 100644 config/api_settings.py diff --git a/.gitignore b/.gitignore index c9607a3..9303f20 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ bin/ **/__pycache__/ -.unlimiter/ \ No newline at end of file +**/unlimiter.* diff --git a/Dockerfile b/Dockerfile index 9af6da2..43dedb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ WORKDIR /usr/src/core-services-api RUN mkdir -p /root/.unlimiter -COPY ./config/unlimiter.config.yaml /root/.unlimiter/config.yaml +COPY /config/unlimiter.config.yaml /root/.unlimiter/config.yaml COPY --from=requirements-stage /tmp/requirements.txt /usr/src/core-services-api/requirements.txt diff --git a/app/__init__.py b/api/controller/__init__.py similarity index 100% rename from app/__init__.py rename to api/controller/__init__.py diff --git a/api/controller/loupe_controller.py b/api/controller/loupe_controller.py new file mode 100644 index 0000000..306695b --- /dev/null +++ b/api/controller/loupe_controller.py @@ -0,0 +1,12 @@ +from api.lib.services import benchling_service + +class LoupeController: + def __init__(self): + pass + + + @classmethod + def get_all_projects(self): + result = benchling_service.get_all_projects() + return result + \ No newline at end of file diff --git a/api/main.py b/api/main.py new file mode 100644 index 0000000..71fdd41 --- /dev/null +++ b/api/main.py @@ -0,0 +1,16 @@ +from functools import lru_cache +from fastapi import FastAPI +from .routes import loupe +from starlette.middleware.cors import CORSMiddleware + +app = FastAPI() + +app.add_middleware( + CORSMiddleware, + allow_origins= ['http://localhost:3000'], + allow_credentials=True, + allow_methods=["GET"], + allow_headers=["*"], +) + +app.include_router(loupe.router) \ No newline at end of file diff --git a/api/routes/loupe.py b/api/routes/loupe.py new file mode 100644 index 0000000..686c0c0 --- /dev/null +++ b/api/routes/loupe.py @@ -0,0 +1,12 @@ + +from fastapi import APIRouter +from starlette import responses +from api.controller.loupe_controller import LoupeController + + +router = APIRouter() + +@router.get('/loupe/projects') +async def get_all_projects(): + responses = LoupeController.get_all_projects() + return responses \ No newline at end of file diff --git a/app/main.py b/app/main.py deleted file mode 100644 index 801374a..0000000 --- a/app/main.py +++ /dev/null @@ -1,6 +0,0 @@ -from fastapi import FastAPI -from .routers import projects - -app = FastAPI() - -app.include_router(projects.router) \ No newline at end of file diff --git a/app/routers/__init__.py b/app/routers/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/routers/projects.py b/app/routers/projects.py deleted file mode 100644 index 7279683..0000000 --- a/app/routers/projects.py +++ /dev/null @@ -1,11 +0,0 @@ -from fastapi import APIRouter -from unlimiter.data.api import BenchlingV2APIConnection - - -router = APIRouter() - -@router.get('/projects') -async def get_all_projects(): - with BenchlingV2APIConnection() as benchling: - projects = benchling.projects.list_projects() - return projects \ No newline at end of file diff --git a/config/api_settings.py b/config/api_settings.py new file mode 100644 index 0000000..98fb382 --- /dev/null +++ b/config/api_settings.py @@ -0,0 +1,7 @@ +from pydantic import BaseSettings + +class Settings(BaseSettings): + app_name: str = "Core Services API" + + class Config: + env_file = '.env.dev' \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index fed0a2f..dced320 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,7 @@ services: BENCHLING_API_KEY: ${BENCHLING_API_KEY} GITHUB_TOKEN: ${GITHUB_TOKEN} container_name: core_api - command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 5000 + command: uvicorn api.main:app --reload --workers 1 --host 0.0.0.0 --port 5000 ports: - 5002:5000 environment: From da9bdb47e930f5c4f48104413b9d617a9af85ee7 Mon Sep 17 00:00:00 2001 From: Chris Rudnicky Date: Mon, 18 Oct 2021 10:18:29 -0700 Subject: [PATCH 3/4] wip --- .gitignore | 4 +--- api/lib/services/benchling_service.py | 10 ++++++++++ config/unlimiter.config.yaml | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 api/lib/services/benchling_service.py diff --git a/.gitignore b/.gitignore index 9303f20..e8f34bb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,8 @@ .env .env.* -lib/ - bin/ **/__pycache__/ -**/unlimiter.* +**/unlimiter.config* diff --git a/api/lib/services/benchling_service.py b/api/lib/services/benchling_service.py new file mode 100644 index 0000000..99c2938 --- /dev/null +++ b/api/lib/services/benchling_service.py @@ -0,0 +1,10 @@ +from unlimiter.data.api import BenchlingV2APIConnection +import timeit + +def get_all_projects(): + with BenchlingV2APIConnection() as benchling: + projects = benchling.projects.list_projects() + project_list = [] + for project in projects['projects']: + project_list.append(project['name']) + return project_list \ No newline at end of file diff --git a/config/unlimiter.config.yaml b/config/unlimiter.config.yaml index 5bf5364..5a8188a 100644 --- a/config/unlimiter.config.yaml +++ b/config/unlimiter.config.yaml @@ -6,10 +6,10 @@ asana_v1: token: benchling_v2: dev: - url: https://abscidev.benchling.com/api/v2 + url: https://abscitest.benchling.com/api/v2 auth: method: basic - username: sk_NILsCCOZZFVWWLLRr5NRd73KUATCz + username: sk_mAqh8a9o8ipbAIWTCyIQumeIX7LQQ password: '' benchling_warehouse: dev: From 69a58918258826754d094fb3821d6ca93f02a64a Mon Sep 17 00:00:00 2001 From: crudnicky Date: Mon, 18 Oct 2021 14:58:48 -0700 Subject: [PATCH 4/4] chore(dir changes): restructure directories and endpoint names --- api/lib/__init__.py | 0 api/lib/services/__init__.py | 0 api/lib/services/benchling_service.py | 8 +++----- api/main.py | 4 ++-- api/routes/{loupe.py => loupe/loupe_v1.py} | 2 +- api/routes/wfvt.py | 0 6 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 api/lib/__init__.py create mode 100644 api/lib/services/__init__.py rename api/routes/{loupe.py => loupe/loupe_v1.py} (87%) create mode 100644 api/routes/wfvt.py diff --git a/api/lib/__init__.py b/api/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/lib/services/__init__.py b/api/lib/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/lib/services/benchling_service.py b/api/lib/services/benchling_service.py index 99c2938..9c66418 100644 --- a/api/lib/services/benchling_service.py +++ b/api/lib/services/benchling_service.py @@ -1,10 +1,8 @@ from unlimiter.data.api import BenchlingV2APIConnection -import timeit + +import pprint def get_all_projects(): with BenchlingV2APIConnection() as benchling: projects = benchling.projects.list_projects() - project_list = [] - for project in projects['projects']: - project_list.append(project['name']) - return project_list \ No newline at end of file + return projects \ No newline at end of file diff --git a/api/main.py b/api/main.py index 71fdd41..94c26b0 100644 --- a/api/main.py +++ b/api/main.py @@ -1,6 +1,6 @@ from functools import lru_cache from fastapi import FastAPI -from .routes import loupe +from .routes.loupe import loupe_v1 from starlette.middleware.cors import CORSMiddleware app = FastAPI() @@ -13,4 +13,4 @@ allow_headers=["*"], ) -app.include_router(loupe.router) \ No newline at end of file +app.include_router(loupe_v1.router) \ No newline at end of file diff --git a/api/routes/loupe.py b/api/routes/loupe/loupe_v1.py similarity index 87% rename from api/routes/loupe.py rename to api/routes/loupe/loupe_v1.py index 686c0c0..37d7ae5 100644 --- a/api/routes/loupe.py +++ b/api/routes/loupe/loupe_v1.py @@ -6,7 +6,7 @@ router = APIRouter() -@router.get('/loupe/projects') +@router.get('/v1/loupe/projects') async def get_all_projects(): responses = LoupeController.get_all_projects() return responses \ No newline at end of file diff --git a/api/routes/wfvt.py b/api/routes/wfvt.py new file mode 100644 index 0000000..e69de29