-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'blossomlabsio:main' into main
- Loading branch information
Showing
31 changed files
with
144 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GITHUB_CLIENT_ID="YOUR_GITHUB_CLIENT_ID" | ||
GITHUB_CLIENT_SECRET="YOUR_GITHUB_CLIENT_SECRET" |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from .auth_router import router | ||
from typing import Annotated, Dict | ||
from starlette.responses import RedirectResponse | ||
from fastapi import Depends, status | ||
from ....core.settings.config import Config, get_settings | ||
import httpx | ||
|
||
|
||
@router.get("/github-login") | ||
async def github_auth(settings: Annotated[Config, Depends(get_settings)]): | ||
return RedirectResponse(f"https://github.com/login/oauth/authorize?client_id={settings.GITHUB_CLIENT_ID}", status_code=status.HTTP_302_FOUND) | ||
|
||
|
||
@router.get("/github-code") | ||
async def github_code(code: str, settings: Annotated[Config, Depends(get_settings)]): | ||
params: Dict[str, str] = { | ||
"client_id": settings.GITHUB_CLIENT_ID, | ||
"client_secret": settings.GITHUB_CLIENT_SECRET, | ||
"code": code | ||
} | ||
|
||
headers: Dict[str, str] = { | ||
"Accept": "application/json" | ||
} | ||
async with httpx.AsyncClient() as client: | ||
response = await client.post(url="https://github.com/login/oauth/access_token", params=params, headers=headers) | ||
|
||
response_json = response.json() | ||
access_token = response_json['access_token'] | ||
|
||
async with httpx.AsyncClient() as client: | ||
headers.update({"Authorization": f"Bearer {access_token}"}) | ||
response = await client.get("https://api.github.com/user", headers=headers) | ||
|
||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from fastapi import APIRouter, Depends | ||
|
||
router = APIRouter( | ||
prefix="/bloom/v1/auth", | ||
tags=["auth"] | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from fastapi import APIRouter, status | ||
from typing import Annotated | ||
|
||
router = APIRouter( | ||
prefix="/bloom/v1/status", | ||
tags=["status"] | ||
) | ||
|
||
|
||
@router.get("", status_code=status.HTTP_200_OK) | ||
async def check_api_status(): | ||
return {"status": "working"} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
from functools import lru_cache | ||
|
||
|
||
class Config(BaseSettings): | ||
GITHUB_CLIENT_ID: str | ||
GITHUB_CLIENT_SECRET: str | ||
|
||
model_config = SettingsConfigDict(env_file=".env") | ||
|
||
|
||
@lru_cache | ||
def get_settings(): | ||
return Config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Dict, Any | ||
from pydantic import BaseModel | ||
|
||
|
||
class LogConfig(BaseModel): | ||
"""Logging configuration to be set for the server""" | ||
|
||
LOGGER_NAME: str = "Bloom" | ||
LOG_FORMAT: str = "%(levelprefix)s | %(asctime)s | %(message)s" | ||
LOG_LEVEL: str = "DEBUG" | ||
|
||
# Logging config | ||
version: int = 1 | ||
disable_existing_loggers: bool = False | ||
formatters: Dict[str, Dict[str, str]] = { | ||
"default": { | ||
"()": "uvicorn.logging.DefaultFormatter", | ||
"fmt": LOG_FORMAT, | ||
"datefmt": "%Y-%m-%d %H:%M:%S", | ||
}, | ||
} | ||
handlers: Dict[str, Dict[str, Any]] = { | ||
"default": { | ||
"formatter": "default", | ||
"class": "logging.StreamHandler", | ||
"stream": "ext://sys.stderr", | ||
}, | ||
} | ||
loggers: Dict[str, Dict[str, Any]] = { | ||
LOGGER_NAME: {"handlers": ["default"], "level": LOG_LEVEL}, | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from .api.router.status import status_router | ||
from .api.router.auth import auth_github | ||
from .core.settings.logger import LogConfig | ||
from logging.config import dictConfig | ||
|
||
dictConfig(LogConfig()) | ||
|
||
|
||
app = FastAPI() | ||
|
||
origins = ["*"] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router(status_router.router) | ||
app.include_router(auth_github.router) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
anyio==3.7.0 | ||
certifi==2023.5.7 | ||
click==8.1.3 | ||
dnspython==2.3.0 | ||
annotated-types==0.5.0 | ||
anyio==3.7.1 | ||
certifi==2023.7.22 | ||
click==8.1.7 | ||
dnspython==2.4.2 | ||
email-validator==2.0.0.post2 | ||
exceptiongroup==1.1.1 | ||
fastapi==0.96.0 | ||
fastapi==0.103.2 | ||
h11==0.14.0 | ||
httpcore==0.17.2 | ||
httptools==0.5.0 | ||
httpx==0.24.1 | ||
httpcore==0.18.0 | ||
httptools==0.6.0 | ||
httpx==0.25.0 | ||
idna==3.4 | ||
itsdangerous==2.1.2 | ||
Jinja2==3.1.2 | ||
MarkupSafe==2.1.3 | ||
orjson==3.9.0 | ||
pydantic==1.10.8 | ||
orjson==3.9.7 | ||
pydantic==2.4.2 | ||
pydantic-extra-types==2.1.0 | ||
pydantic-settings==2.0.3 | ||
pydantic_core==2.10.1 | ||
python-dotenv==1.0.0 | ||
python-multipart==0.0.6 | ||
PyYAML==6.0 | ||
PyYAML==6.0.1 | ||
sniffio==1.3.0 | ||
starlette==0.27.0 | ||
typing_extensions==4.6.3 | ||
ujson==5.7.0 | ||
uvicorn==0.22.0 | ||
typing_extensions==4.8.0 | ||
ujson==5.8.0 | ||
uvicorn==0.23.2 | ||
uvloop==0.17.0 | ||
watchfiles==0.19.0 | ||
watchfiles==0.20.0 | ||
websockets==11.0.3 | ||
pytest==7.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pip3 freeze >requirements.txt |