Skip to content

Commit

Permalink
First big pass
Browse files Browse the repository at this point in the history
  • Loading branch information
chouinar committed Oct 5, 2023
1 parent 2cd5609 commit 236d3e9
Show file tree
Hide file tree
Showing 54 changed files with 806 additions and 1,249 deletions.
6 changes: 3 additions & 3 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# The build stage that will be used to deploy to the various environments
# needs to be called `release` in order to integrate with the repo's
# top-level Makefile
FROM python:3-slim AS base
FROM python:3.11-slim AS base

# Install poetry, the package manager.
# https://python-poetry.org
Expand Down Expand Up @@ -57,7 +57,7 @@ COPY . /app
ENV HOST=0.0.0.0

# Run the application.
CMD ["poetry", "run", "python", "-m", "src"]
CMD ["poetry", "run", "python", "src/app.py"]

#---------
# Release
Expand Down Expand Up @@ -109,4 +109,4 @@ ENV HOST=0.0.0.0
USER ${RUN_USER}

# Run the application.
CMD ["poetry", "run", "gunicorn", "src.app:create_app()"]
CMD ["poetry", "run", "python", "src/app.py"]
2 changes: 0 additions & 2 deletions app/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ PYTHONPATH=/app/
# commands that can run in or out
# of the Docker container - defaults to outside

FLASK_APP=src.app:create_app

############################
# Logging
############################
Expand Down
124 changes: 54 additions & 70 deletions app/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ marshmallow = "^3.18.0"
gunicorn = "^21.2.0"
fastapi = {extras = ["all"], version = "^0.103.1"}
psycopg = {extras = ["binary"], version = "^3.1.10"}
starlette-context = "^0.3.6"


[tool.poetry.group.dev.dependencies]
Expand All @@ -29,14 +30,14 @@ flake8 = "^5.0.4"
flake8-bugbear = "^22.8.23"
flake8-alfred = "^1.1.1"
isort = "^5.10.1"
mypy = "^0.971"
mypy = "1.5.1"
moto = {extras = ["s3"], version = "^4.0.2"}
types-pytz = "^2022.2.1"
coverage = "^6.4.4"
Faker = "^14.2.0"
factory-boy = "^3.2.1"
bandit = "^1.7.4"
pytest = "^6.0.0"
pytest = "7.4.2"
pytest-watch = "^4.2.0"
pytest-lazy-fixture = "^0.6.3"
types-pyyaml = "^6.0.12.11"
Expand Down Expand Up @@ -83,6 +84,9 @@ warn_redundant_casts = true
warn_unreachable = true
warn_unused_ignores = true

plugins = ["pydantic.mypy"]


[tool.bandit]
# Ignore audit logging test file since test audit logging requires a lot of operations that trigger bandit warnings
exclude_dirs = ["./tests/src/logging/test_audit.py"]
Expand Down
6 changes: 6 additions & 0 deletions app/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ ignore =
E266,
# don't use bare except, B001 is more descriptive
E722

# Tell Flake to not error when we do "def my_func(some_field = default_value)" when
# the default value is one of the following types as these are used by FastAPI.
# These are calls to classes and functions and are immutably safe in their usage.
# https://stackoverflow.com/questions/73306462/flake8-throws-b008-fastapi-data-type-definitions
extend-immutable-calls = Depends, Security, fastapi_db.DbSessionDependency
8 changes: 4 additions & 4 deletions app/src/adapters/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Database module.
This module contains the DBClient class, which is used to manage database connections.
This module can be used on it's own or with an application framework such as Flask.
This module can be used on it's own or with an application framework such as Fast API.
To use this module with Flask, use the flask_db module.
To use this module with FastAPI, use the fastapi_db module.
Usage:
import src.adapters.db as db
Expand All @@ -26,7 +26,7 @@
from src.adapters.db.client import Connection, DBClient, Session
from src.adapters.db.clients.postgres_client import PostgresDBClient

# Do not import flask_db here, because this module is not dependent on any specific framework.
# Code can choose to use this module on its own or with the flask_db module depending on needs.
# Do not import fastapi_db here, because this module is not dependent on any specific framework.
# Code can choose to use this module on its own or with the fastapi_db module depending on needs.

__all__ = ["Connection", "DBClient", "Session", "PostgresDBClient"]
2 changes: 1 addition & 1 deletion app/src/adapters/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class DBClient(abc.ABC, metaclass=abc.ABCMeta):
"""Database connection manager.
This class is used to manage database connections for the Flask app.
This class is used to manage database connections for the app.
It has methods for getting a new connection or session object.
A derived class must initialize _engine in the __init__ function
Expand Down
20 changes: 10 additions & 10 deletions app/src/adapters/db/clients/postgres_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@


class PostgresDBConfig(PydanticBaseEnvConfig):
check_connection_on_init: bool = Field(True, env="DB_CHECK_CONNECTION_ON_INIT")
aws_region: Optional[str] = Field(None, env="AWS_REGION")
host: str = Field(env="DB_HOST")
name: str = Field(env="DB_NAME")
username: str = Field(env="DB_USER")
password: Optional[str] = Field(None, env="DB_PASSWORD")
db_schema: str = Field("public", env="DB_SCHEMA")
port: int = Field(5432, env="DB_PORT")
hide_sql_parameter_logs: bool = Field(True, env="HIDE_SQL_PARAMETER_LOGS")
ssl_mode: str = Field("require", env="DB_SSL_MODE")
check_connection_on_init: bool = Field(True, alias="DB_CHECK_CONNECTION_ON_INIT")
aws_region: Optional[str] = Field(None, alias="AWS_REGION")
host: str = Field(alias="DB_HOST")
name: str = Field(alias="DB_NAME")
username: str = Field(alias="DB_USER")
password: Optional[str] = Field(None, alias="DB_PASSWORD")
db_schema: str = Field("public", alias="DB_SCHEMA")
port: int = Field(5432, alias="DB_PORT")
hide_sql_parameter_logs: bool = Field(True, alias="HIDE_SQL_PARAMETER_LOGS")
ssl_mode: str = Field("require", alias="DB_SSL_MODE")


def get_db_config() -> PostgresDBConfig:
Expand Down
Loading

0 comments on commit 236d3e9

Please sign in to comment.