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

Feature/114 add django setup configuration #115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Coperh
Copy link

@Coperh Coperh commented Jul 9, 2024

fixes: #114

Implements django setup configuration in OIDC itself

@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch 10 times, most recently from fc242eb to c9f80ed Compare July 10, 2024 13:18
@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch 2 times, most recently from c60c2e3 to 6a447fc Compare July 26, 2024 13:54
@Coperh Coperh marked this pull request as ready for review July 26, 2024 13:57
@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch from 6e001b1 to aca7802 Compare July 30, 2024 12:29
@Coperh
Copy link
Author

Coperh commented Jul 30, 2024

Mostly copied AdminOIDCConfigurationSettings from open inwoner and the documentation. Made the endpoints required since it fails to save without them. Converted the unittest to pytest

Example of it being used here open-zaak/open-zaak#1728

@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch from 20f406b to aca9492 Compare August 2, 2024 07:34
@Coperh
Copy link
Author

Coperh commented Aug 2, 2024

I am also unsure about the package/file names

@Coperh Coperh removed the request for review from pi-sigma August 2, 2024 07:55
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a preliminary glance, haven't looked into much details yet, but I have some concerns - perhaps about the way django-setup-configuration itself works:

amount of settings

there are a lot of settings being defined purely to facilitate bootstrapping configuration. Some of these setting names also have a big potential to cause confusion with settings that actually have some meaning at runtime. I don't think this will improve the developer experience

settings datatypes

I noticed in OIP that settings are used so that envvars can be used to specify them, but the datatypes of these settings (like lists of strings, periods/comma's having special meaning...) but also dict/mappings complicates passing them via the env

you basically have a Helm chart or Ansible playbook where the datatype is properly defined in YAML, this is then templated out to a string so it can be passed as an envvar, after which the application deserializes it again from a string into the expected datatype

I would much prefer one of the options below (with the first having my preference):

  • load a YAML/TOML/JSON file that contains the data/config to initialize. you then only need to point to which file to load, plus it will scale in the future when we don't have solo models anymore but instead regular models. it's basically a django-agnostic fixture format
  • read the values directly from the env and remove the need to define them as settings. the library knows how to interpret each envvar and parse it into the expected data-structure

IMO the former approach makes documenting the format a lot easier, you can simply provide an example template, you can add comments if you use YAML/TOML and the processing step of that file is able to populate missing information (the endpoints!) from the discovery endpoint if that's all that is specified.

.github/workflows/ci.yml Show resolved Hide resolved
CHANGELOG.rst Outdated Show resolved Hide resolved
mozilla_django_oidc_db/setupconfig/boostrap.py Outdated Show resolved Hide resolved
testapp/settings.py Show resolved Hide resolved
testapp/settings.py Outdated Show resolved Hide resolved
mozilla_django_oidc_db/setupconfig/boostrap.py Outdated Show resolved Hide resolved
mozilla_django_oidc_db/setupconfig/boostrap.py Outdated Show resolved Hide resolved
mozilla_django_oidc_db/setupconfig/boostrap.py Outdated Show resolved Hide resolved
tests/setupconfig/test_auth.py Outdated Show resolved Hide resolved
@alextreme
Copy link
Member

FYI for Conor, Paul is working on a related issue: https://taiga.maykinmedia.nl/project/open-inwoner/issue/2563

@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch 2 times, most recently from 92960f5 to 68d3a61 Compare August 14, 2024 15:53
@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch 2 times, most recently from 3bc045b to 93f6c66 Compare August 23, 2024 10:47
Comment on lines 37 to 40
all_settings = {
"sync_groups": config.sync_groups,
"oidc_use_nonce": config.oidc_use_nonce,
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to use default values for boolean fields if its empty? Otherwise they always default to false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use the __init__ in the form to set a default? self.fields["sync_groups"].default = False? But maybe I'm not understanding the question right.

@Coperh
Copy link
Author

Coperh commented Sep 3, 2024

Have reimplemented it in OZ with the new format: open-zaak/open-zaak#1728

docs/setup_configuration.rst Outdated Show resolved Hide resolved
docs/setup_configuration.rst Outdated Show resolved Hide resolved
docs/setup_configuration.rst Outdated Show resolved Hide resolved
docs/setup_configuration.rst Outdated Show resolved Hide resolved
docs/setup_configuration.rst Outdated Show resolved Hide resolved
tests/setupconfig/conftest.py Outdated Show resolved Hide resolved
tests/setupconfig/test_auth.py Outdated Show resolved Hide resolved
)
assert config.username_claim == ["claim_name"]
assert config.groups_claim == ["groups_claim_name"]
assert config.claim_mapping == {"first_name": "given_name"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, this bug should really be caught by form validation 🤔

tests/setupconfig/test_auth.py Show resolved Hide resolved
Comment on lines +181 to +204
assert not config.is_configured()

config.configure()

assert config.is_configured()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this actually means/implies?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK tbh. Copied it from open-iwoner

@Coperh Coperh force-pushed the feature/114-add-django-setup-configuration branch from 54ad63f to 3aac68c Compare October 22, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants