Skip to content

Commit

Permalink
Merge branch 'blossomlabsio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ghanatava authored Oct 4, 2023
2 parents a139b27 + c38c1a2 commit 0f418b8
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .env.example
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"
3 changes: 0 additions & 3 deletions app/core/config.py

This file was deleted.

Empty file removed app/core/events.py
Empty file.
Empty file removed app/core/logging.py
Empty file.
Empty file removed app/main.py
Empty file.
Empty file removed app/services/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions bloom/api/router/auth/auth_github.py
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()
6 changes: 6 additions & 0 deletions bloom/api/router/auth/auth_router.py
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.
12 changes: 12 additions & 0 deletions bloom/api/router/status/status_router.py
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.
14 changes: 14 additions & 0 deletions bloom/core/settings/config.py
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()
31 changes: 31 additions & 0 deletions bloom/core/settings/logger.py
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.
24 changes: 24 additions & 0 deletions bloom/main.py
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.
43 changes: 0 additions & 43 deletions pyproject.toml

This file was deleted.

35 changes: 19 additions & 16 deletions requirements.txt
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
1 change: 1 addition & 0 deletions scripts/update_req.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip3 freeze >requirements.txt
Empty file removed setup.cfg
Empty file.

0 comments on commit 0f418b8

Please sign in to comment.