canonical / paas-app-charmer

2 stars 2 forks source link

Refactor for integrations #18

Closed javierdelapuente closed 3 months ago

javierdelapuente commented 3 months ago

Applicable spec:

Overview

This PR is a refactor for paas-app-charmer. Its main goal is to refactor CharmState, so it is leaner and it is not instantiated in GunicornBase.__init__. Besides, itchanges how the integrations (the ones that can be optional, like redis, postgresql, mongo and mysql and in the future s3, saml...) are managed in the CharmState, so objects like DatabaseRequires do not get to the WsgiApp. These are the main tasks done:

Rationale

The desired architecture uses state objects (kind of DTOs) to send information to the WsgiApp, so for example it can generate environment variables. However, as information from Juju can be changed by for example libraries, this state cannot be created in the __init__ method. At the moment, Juju related classes like DatabaseRequires were sent in the state. To solve this issue, the CharmState has been split and the Juju related parts are not instantiated in __init__.

CharmState has also been changed to be simpler.

Juju Events Changes

Module Changes

Library Changes

Checklist

github-actions[bot] commented 3 months ago

Test coverage for 80f9fc2f6b1e2680a954d719d69cbc042ca501d6

Name                                            Stmts   Miss Branch BrPart  Cover   Missing
-------------------------------------------------------------------------------------------
paas_app_charmer/__init__.py                        0      0      0      0   100%
paas_app_charmer/_gunicorn/__init__.py              0      0      0      0   100%
paas_app_charmer/_gunicorn/charm.py               132     20     18      4    83%   129-130, 132-133, 154->exit, 166-170, 184-186, 240-241, 246, 251, 256, 266, 271, 276, 281, 286
paas_app_charmer/_gunicorn/charm_state.py          53      1     10      1    97%   165
paas_app_charmer/_gunicorn/charm_utils.py          23      0      0      0   100%
paas_app_charmer/_gunicorn/observability.py        13      0      2      0   100%
paas_app_charmer/_gunicorn/secret_storage.py       13      0      0      0   100%
paas_app_charmer/_gunicorn/webserver.py            75      4     14      1    94%   156, 168-174
paas_app_charmer/_gunicorn/workload_config.py      19      0      0      0   100%
paas_app_charmer/_gunicorn/wsgi_app.py             72      0     30      0   100%
paas_app_charmer/database_migration.py             33      0      2      0   100%
paas_app_charmer/databases.py                      25      2     11      1    92%   89-90
paas_app_charmer/django/__init__.py                 1      0      0      0   100%
paas_app_charmer/django/charm.py                   44      7     10      1    78%   72-77, 98, 113-114
paas_app_charmer/exceptions.py                      4      0      0      0   100%
paas_app_charmer/flask/__init__.py                  1      0      0      0   100%
paas_app_charmer/flask/charm.py                    36      0      6      0   100%
paas_app_charmer/secret_storage.py                 39      3     16      5    85%   50, 54->53, 55->57, 85, 104
-------------------------------------------------------------------------------------------
TOTAL                                             583     37    119     13    92%

Static code analysis report

Run started:2024-06-03 16:16:50.311881

Test results:
    No issues identified.

Code scanned:
    Total lines of code: 1312
    Total lines skipped (#nosec): 0
    Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
    Total issues (by severity):
        Undefined: 0
        Low: 0
        Medium: 0
        High: 0
    Total issues (by confidence):
        Undefined: 0
        Low: 0
        Medium: 0
        High: 0
Files skipped (0):