Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lecture de la configuration avec pydantic-settings, et documentation #65

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinxcontrib.autodoc_pydantic",
]

templates_path = ["_templates"]
Expand Down Expand Up @@ -90,3 +91,13 @@
# -- Options for autosectionlabel -----------------------------------------

autosectionlabel_prefix_document = True

# -- Options for autodo_pydantic_settings -------------------------------------------

autodoc_pydantic_model_show_json = False
autodoc_pydantic_model_show_config_summary = False
autodoc_pydantic_model_show_config_summary = False
autodoc_pydantic_model_show_validator_summary = False
autodoc_pydantic_model_show_validator_members = False
autodoc_pydantic_model_show_field_summary = False
autodoc_pydantic_field_list_validators = False
1 change: 1 addition & 0 deletions documentation/maintainers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Cette partie de la documentation est à destination des personnes qui déploient
:maxdepth: 2

pullRequestValidation
settings
meetingFiles
4 changes: 4 additions & 0 deletions documentation/maintainers/settings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Configuration
#############

.. autopydantic_model:: flaskr.settings.MainSettings
25 changes: 24 additions & 1 deletion poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ flask-wtf = "^1.1.1"
redis = "4.4.4"
requests = "^2.27.1"
werkzeug = "<2.3"
pydantic-settings = "^2.1.0"

[tool.poetry.group.dev]
optional = true
Expand All @@ -55,6 +56,7 @@ optional = true
sphinx = "^7.0.0"
sphinx-rtd-theme = "^2.0.0"
sphinx-issues = "^3.0.0"
autodoc-pydantic = "^2.0.1"
myst-parser = "^2.0.0"

[tool.black]
Expand All @@ -65,7 +67,6 @@ extend-exclude = '''
'''

[tool.pytest.ini_options]
env_files = ["web.env"]
testpaths = "web"

[tool.ruff]
Expand Down
6 changes: 3 additions & 3 deletions web.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ OIDC_USERINFO_HTTP_METHOD=POST
OIDC_REDIRECT_URI=http://localhost:5000/oidc_callback

# Attendee OIDC Configuration (back to default if empty)
OIDC_ATTENDEE_ENABLED=
OIDC_ATTENDEE_ENABLED=true
OIDC_ATTENDEE_ISSUER=
OIDC_ATTENDEE_CLIENT_ID=
OIDC_ATTENDEE_CLIENT_SECRET=
Expand All @@ -62,9 +62,9 @@ SMTP_HOST=0.0.0.0
SMTP_PORT=1025
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_SSL=
SMTP_SSL=false
EMAIL_WHITELIST=.*@(.*\.|)gouv\.fr
RIE_NETWORK_IPS=192.168.0.0/16,172.16.0.0/12,192.168.1.97/16,127.0.0.0/16
RIE_NETWORK_IPS=192.168.0.0/16,172.16.0.0/12,127.0.0.0/16
BIGBLUEBUTTON_ANALYTICS_CALLBACK_URL=https://bbb-analytics-staging.osc-fr1.scalingo.io/v1/post_events

# Nextcloud and meeting Files connection configuration
Expand Down
1 change: 0 additions & 1 deletion web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ COPY misc/wsgi.py misc/gunicorn.py misc/run_webserver.sh /opt/bbb-visio/
COPY misc/delete_uploaded_files.cron /etc/cron.d/delete_uploaded_files
RUN chmod u+x /opt/bbb-visio/run_webserver.sh
COPY migrations /opt/bbb-visio/migrations
COPY instance/config.py /opt/bbb-visio/instance/config.py
COPY flaskr /opt/bbb-visio/flaskr

WORKDIR /opt/bbb-visio/
Expand Down
2 changes: 0 additions & 2 deletions web/Dockerfile-tests
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ RUN pip install -r /tmp/requirements.txt
COPY requirements.dev.txt /tmp/requirements.dev.txt
RUN pip install -r /tmp/requirements.dev.txt

COPY instance/config.py /opt/bbb-visio/instance/config.py

WORKDIR /opt/bbb-visio
ENTRYPOINT ["pytest"]
20 changes: 13 additions & 7 deletions web/flaskr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from flask_caching import Cache
from flask_migrate import Migrate
from flask_wtf.csrf import CSRFProtect
from flaskr.settings import MainSettings
from flaskr.utils import is_rie


Expand All @@ -27,6 +28,14 @@
cache = Cache()


def setup_configuration(app, config=None):
if config:
app.config.from_mapping(config)

config_obj = MainSettings.model_validate(config or {})
app.config.from_object(config_obj)


def setup_cache(app):
cache.init_app(
app,
Expand All @@ -37,14 +46,11 @@ def setup_cache(app):
)


def setup_logging(app, test_config=None, gunicorn_logging=False):
def setup_logging(app, gunicorn_logging=False):
if gunicorn_logging:
gunicorn_logger = logging.getLogger("gunicorn.error")
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
app.config.from_pyfile("config.py")
if test_config:
app.config.from_mapping(test_config)


def setup_i18n(app):
Expand Down Expand Up @@ -108,10 +114,10 @@ def internal_error(error):


def create_app(test_config=None, gunicorn_logging=False):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app = Flask(__name__)
setup_configuration(app, test_config)
setup_cache(app)
setup_logging(app, test_config, gunicorn_logging)
setup_logging(app, gunicorn_logging)
setup_i18n(app)
setup_csrf(app)
setup_database(app)
Expand Down
Loading
Loading