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

setup_notification command #2

Merged
merged 14 commits into from
Mar 21, 2024
Merged

setup_notification command #2

merged 14 commits into from
Mar 21, 2024

Conversation

annashamray
Copy link
Contributor

@annashamray annashamray commented Feb 9, 2024

fixes #1

@annashamray annashamray marked this pull request as draft February 9, 2024 16:43
@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@annashamray annashamray marked this pull request as ready for review February 21, 2024 16:05
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 think it makes more sense to run all phases of a step and only then move to the next step, so that you can sort out dependencies between steps.

Now the order of steps is irrelevant since you first check all pre-requisites, then run all configurations and then the self tests but that breaks if you have a step that requires another step to be completed first

if prerequisites are missing
"""
missing = [
var for var in self.required_settings if not getattr(settings, var, None)
Copy link
Member

Choose a reason for hiding this comment

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

What if a valid setting value is None? Is that a case to consider?

Copy link
Member

Choose a reason for hiding this comment

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

How should I interpret these required settings? Can you give an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I can't make up an example when we need None as a valid setting for configuration. But False can definitely be a valid one, so I'll refactor it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can find an example in Open Zaak - https://github.com/open-zaak/open-zaak/blob/4b870e709f1c08d53464eb6b76bc7ace11b2d87a/src/openzaak/config/bootstrap/demo.py#L29

Here we configure a demo user. So if settings with demo credentials are missing, then we raise PrerequisiteFailed
If we want to skip this step we can set DEMO_CONFIG_ENABLE = 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 guess if it can be None, its not required?

if not self.enable_setting:
return True

return getattr(settings, self.enable_setting, True)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to do this via a Django setting step? Why can't we directly point to the name of an envvar and skip having to define a Django setting that reads the envvar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use django settings to set defaults when it's possible. For example we can have a default for SELECTIELIJST_API_ROOT


class ConfigurationRunFailed(ConfigurationException):
"""
Raise an error then configuration process was faulty
Copy link
Member

Choose a reason for hiding this comment

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

s/then/when?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -0,0 +1,117 @@
from collections import OrderedDict
Copy link
Member

Choose a reason for hiding this comment

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

Python dicts retain insertion order, you generally don't need OrderedDict anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL! Changed to dict


class Command(BaseCommand):
help = (
"Bootstrap the initial Open Zaak configuration. "
Copy link
Member

Choose a reason for hiding this comment

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

Probably should remove Open Zaak from this docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed :)

Copy link
Contributor Author

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

To be honest I haven't considered case when one configuration step can be dependent on the other.
I thought of step.validate_requirements function more like a check that all required environment variables are provided. This is why I wanted first to check prerequisites of all the steps and give a full list of missing variables to the user.

I can do it step by step, but it can be annoying for the user.

Or I can divide this check into two parts: check required env vars and check other dependencies, and the latter can be done step by step.

if prerequisites are missing
"""
missing = [
var for var in self.required_settings if not getattr(settings, var, None)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I can't make up an example when we need None as a valid setting for configuration. But False can definitely be a valid one, so I'll refactor it.

if prerequisites are missing
"""
missing = [
var for var in self.required_settings if not getattr(settings, var, None)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can find an example in Open Zaak - https://github.com/open-zaak/open-zaak/blob/4b870e709f1c08d53464eb6b76bc7ace11b2d87a/src/openzaak/config/bootstrap/demo.py#L29

Here we configure a demo user. So if settings with demo credentials are missing, then we raise PrerequisiteFailed
If we want to skip this step we can set DEMO_CONFIG_ENABLE = False

if not self.enable_setting:
return True

return getattr(settings, self.enable_setting, True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use django settings to set defaults when it's possible. For example we can have a default for SELECTIELIJST_API_ROOT


class ConfigurationRunFailed(ConfigurationException):
"""
Raise an error then configuration process was faulty
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -0,0 +1,117 @@
from collections import OrderedDict
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL! Changed to dict


class Command(BaseCommand):
help = (
"Bootstrap the initial Open Zaak configuration. "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed :)

@annashamray
Copy link
Contributor Author

@sergei-maertens thank you for the review!

Copy link
Member

@joeribekker joeribekker left a comment

Choose a reason for hiding this comment

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

Just needs Django 4.2 support so it won't hold us back in migrating projects.

@annashamray
Copy link
Contributor Author

@joeribekker Django 4.2 is supported now

@annashamray annashamray merged commit e4559f7 into main Mar 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure django rest applications using environment variables
5 participants