Skip to content

Commit

Permalink
Merge pull request #4 from BrewBlox/develop
Browse files Browse the repository at this point in the history
Edge release
  • Loading branch information
steersbob authored Feb 23, 2024
2 parents cd49a3a + 076796c commit 6b9e536
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions brewblox_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from contextvars import ContextVar
from datetime import datetime, timedelta, timezone
Expand All @@ -14,6 +15,7 @@

COOKIE_NAME = 'Authorization'

LOGGER = logging.getLogger(__name__)
CV_USERS: ContextVar[dict[str, str]] = ContextVar('users')

router = APIRouter()
Expand Down Expand Up @@ -45,6 +47,7 @@ class ServiceConfig(BaseSettings):
)

name: str = 'auth'
debug: bool = False
enabled: bool = True
ignore: str = ''
jwt_secret: str
Expand All @@ -57,8 +60,22 @@ def get_config() -> ServiceConfig:
return ServiceConfig()


def setup_logging(debug: bool):
level = logging.DEBUG if debug else logging.INFO
unimportant_level = logging.INFO if debug else logging.WARN
format = '%(asctime)s.%(msecs)03d [%(levelname).1s:%(name)s:%(lineno)d] %(message)s'
datefmt = '%Y/%m/%d %H:%M:%S'

logging.basicConfig(level=level, format=format, datefmt=datefmt)
logging.captureWarnings(True)

logging.getLogger('uvicorn.access').setLevel(unimportant_level)
logging.getLogger('uvicorn.error').disabled = True


def create_app() -> FastAPI:
config = get_config()
setup_logging(config.debug)

with open(config.passwd_file) as f:
CV_USERS.set({
Expand Down

0 comments on commit 6b9e536

Please sign in to comment.