-
Notifications
You must be signed in to change notification settings - Fork 5
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
Experiment: multi-environment configuration in Python #161
Draft
jamesbursa
wants to merge
17
commits into
main
Choose a base branch
from
jamesbursa/python-config-management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
44eccbf
Experiment: multi-environment configuration in Python
jamesbursa 17f93c8
Experiment: multi-environment configuration in Python
jamesbursa 3d4da44
Add tests and fix minor bugs
jamesbursa 2da8195
Fix GitHub formats
jamesbursa 4194db8
Fix lint and test failures and fix db-upgrade
jamesbursa d1c90d2
Format and lint fixes
jamesbursa e86e683
Add type annotations
jamesbursa 1fec89a
One more import order fix
jamesbursa e25d471
Fix environment for database
jamesbursa ca4704e
Fix `make openapi-spec`
jamesbursa d62bd78
Simplify `make openapi-spec`
jamesbursa f7df2b8
Remove unused import
jamesbursa e56ab12
Fix return type of main()
jamesbursa 4b29c4e
Disable bandit check for app.run in debug mode
jamesbursa d54a16e
Move load() into a separate file
jamesbursa dd7e4d6
Merge branch 'main' into jamesbursa/python-config-management
jamesbursa 2a01d3f
Add local_override_example.py
jamesbursa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Multi-environment configuration expressed in Python. | ||
# | ||
|
||
from src.adapters.db.clients.postgres_config import PostgresDBConfig | ||
from src.app_config import AppConfig | ||
from src.logging.config import LoggingConfig | ||
from src.util.env_config import PydanticBaseEnvConfig | ||
|
||
|
||
class RootConfig(PydanticBaseEnvConfig): | ||
app: AppConfig | ||
database: PostgresDBConfig | ||
logging: LoggingConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# Default configuration. | ||
# | ||
# This is the base layer of configuration. It is used if an environment does not override a value. | ||
# Each environment may override individual values (see local.py, dev.py, prod.py, etc.). | ||
# | ||
# This configuration is also used when running tests (individual test cases may have code to use | ||
# different configuration). | ||
# | ||
|
||
from src.adapters.db.clients.postgres_config import PostgresDBConfig | ||
from src.app_config import AppConfig | ||
from src.config import RootConfig | ||
from src.logging.config import LoggingConfig, LoggingFormat | ||
|
||
|
||
def default_config() -> RootConfig: | ||
return RootConfig( | ||
app=AppConfig(), | ||
database=PostgresDBConfig(), | ||
logging=LoggingConfig( | ||
format=LoggingFormat.json, | ||
level="INFO", | ||
enable_audit=True, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# Configuration for dev environments. | ||
# | ||
# This file only contains overrides (differences) from the defaults in default.py. | ||
# | ||
|
||
from .. import default | ||
|
||
config = default.default_config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Configuration for local development environments. | ||
# | ||
# This file only contains overrides (differences) from the defaults in default.py. | ||
# | ||
|
||
import pydantic.types | ||
|
||
from src.logging.config import LoggingFormat | ||
|
||
from .. import default | ||
|
||
config = default.default_config() | ||
|
||
config.database.password = pydantic.types.SecretStr("secret123") | ||
config.database.hide_sql_parameter_logs = False | ||
config.database.sslmode = "prefer" | ||
config.logging.format = LoggingFormat.human_readable | ||
config.logging.enable_audit = False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
environment: Optional[str] = None
? That might be annoying with the linter though