enable smooth environment variable naming transition#311
Draft
MoralCode wants to merge 36 commits into
Draft
Conversation
| @@ -130,7 +131,7 @@ def start(ctx, disable_collection, development, pidfile, port): | |||
| processes = start_celery_worker_processes((core_worker_count, secondary_worker_count, facade_worker_count), disable_collection) | |||
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
W0621: Redefining name 'processes' from outer scope (line 396) (redefined-outer-name)
| @@ -15,6 +15,7 @@ | |||
| import requests | |||
| from redis.exceptions import ConnectionError as RedisConnectionError | |||
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
W0611: Unused ConnectionError imported from redis.exceptions as RedisConnectionError (unused-import)
| @@ -31,7 +32,7 @@ | |||
|
|
|||
| from keyman.KeyClient import KeyClient, KeyPublisher | |||
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
W0611: Unused KeyClient imported from keyman.KeyClient (unused-import)
shlokgilda
requested changes
May 10, 2026
Contributor
shlokgilda
left a comment
There was a problem hiding this comment.
Added some inline comments
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
…ode slowly over time Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
SystemEnv class to unify environment variable use and enable smooth transitionCo-authored-by: Shlok Gilda <gildashlok@hotmail.com> Signed-off-by: Adrian Edwards <17362949+MoralCode@users.noreply.github.com>
Co-authored-by: Shlok Gilda <gildashlok@hotmail.com> Signed-off-by: Adrian Edwards <17362949+MoralCode@users.noreply.github.com>
Co-authored-by: Shlok Gilda <gildashlok@hotmail.com> Signed-off-by: Adrian Edwards <17362949+MoralCode@users.noreply.github.com>
impact: low due to the new env variable interpretation layer Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
…s where env vars are explicitly needed in the CLI Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
8041729 to
1f89a32
Compare
|
|
||
| class TestExtractPrefix: | ||
| def test_env_extract_prefix(self): | ||
| assert extract_prefix("OTHER_DB", prefixes) == "OTHER_" |
| class TestExtractPrefix: | ||
| def test_env_extract_prefix(self): | ||
| assert extract_prefix("OTHER_DB", prefixes) == "OTHER_" | ||
| assert extract_prefix("COLLECTOSS_DB", prefixes) == "COLLECTOSS_" |
| assert extract_prefix("COLLECTOSS_DB", prefixes) == "COLLECTOSS_" | ||
|
|
||
| def test_env_extract_prefix_default(self): | ||
| assert extract_prefix("SOME_DB", prefixes) is None |
|
|
||
| def test_env_extract_prefix_default(self): | ||
| assert extract_prefix("SOME_DB", prefixes) is None | ||
| assert extract_prefix("THINGY_DB", prefixes) is None |
|
|
||
|
|
||
| def test_env_extract_prefix_unprefixed(self): | ||
| assert extract_prefix("DB", prefixes) is None |
| assert SystemEnv.get("COLLECTOSS_MISSING", None, prefixes) is None | ||
|
|
||
| def test_fetching_env_default(self): | ||
| assert SystemEnv.get("COLLECTOSS_DEFAULT", "SOME", prefixes) == "SOME" |
| def test_no_known_prefix(self): | ||
| # fallback handling | ||
| os.environ["THING"] = "C" | ||
| assert SystemEnv.get("THING", None, prefixes) == "C" |
|
|
||
| for case in cases: | ||
| os.environ["OTHER_BOOL"] = case | ||
| assert SystemEnv.get_bool("OTHER_BOOL", False, prefixes) == True, f"value '{case}' should resolve to True" |
|
|
||
| for case in cases: | ||
| os.environ["OTHER_BOOL"] = case | ||
| assert SystemEnv.get_bool("OTHER_BOOL", True, prefixes) == False, f"value '{case}' should resolve to False" |
|
|
||
| for case in cases: | ||
| os.environ["OTHER_BOOL"] = case | ||
| assert SystemEnv.get_bool("OTHER_BOOL", False, prefixes) == False, f"value '{case}' should resolve to Default value" |
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR introduces a new
SystemEnvclass that lives alongsideSystemConfigand aims to centralize/unify all environment variable access.The primary purpose of this is to slightly decouple the requested environment variable name from the name where the value is actually pulled from. For example, even if all in-code references use
COLLECTOSS_DBfor the database connection string, this layer will allow a values to be read fromAUGUR_DBas a fallback ifCOLLECTOSS_DB(preferred) is not set.This class is also set up to print a deprecation warning/notice whenever the
AUGURvariant of an environment variable is used as a fallback. The message makes it clear that this fallback behavior is only temporary and may not be around forever (although I don't see this code being removed anytime in the foreseeable future)This PR includes a unit tests for this new functionality and works as intended, including edge cases such as when the key the code requests doesn't use a known prefix (
os.getenv("CONFIG_DATADIR"))It also includes a special case function
get_bool()because there were ~3 different places in the code where a small python one-liner (that i wrote) had been copied around for convenience, and this was a good opportunity to refactor that to prevent those three versions from ever drifting in implementation from each other. There are certainly more places this logic can be reused as well as we unify the way all env vars are processed.Environment variables handled via Click (the CLI library) are addressed too. the click automatic prefix has been updated and the ~5 lines in 1 file where we were explicitly setting the variables are now updated to include both variants.
This PR resolves one of the large items that needs to be done to complete #279 for the next release.
Notes for Reviewers
This change includes unit tests for "backwards" variable access that keep the code able to refer to
AUGUR_variables so that those can be renamed laterThis PR does not actually change any environment variable names, but that can be done either in this PR or a followup depending on the discussion results
TODOs:
Not yet run to full collection or tested much beyond the unit tests - this will need to be done before merge (ideally by multiple maintainers)
env var access in shell scripts (docker startup) also need adjusting to potentially fall back to the old names
Signed commits