Skip to content

enable smooth environment variable naming transition#311

Merged
MoralCode merged 78 commits into
mainfrom
feat/flexible_env
Jun 10, 2026
Merged

enable smooth environment variable naming transition#311
MoralCode merged 78 commits into
mainfrom
feat/flexible_env

Conversation

@MoralCode

@MoralCode MoralCode commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description
This PR introduces a new SystemEnv class that lives alongside SystemConfig and 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_DB for the database connection string, this layer will allow a values to be read from AUGUR_DB as a fallback if COLLECTOSS_DB (preferred) is not set.

This class is also set up to print a deprecation warning/notice whenever the AUGUR variant 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 also addresses the init, config, and entrypoint bash scripts uses at startup by replacing them with python equivalents (and enabling them to utilize the new environment variable switcher as well). This effectively means the earliest phases of the startup sequence in CollectOSS have been cleaned up somewhat

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 renames all code references to use the new COLLECTOSS_ prefix, with the SystemEnv adapting these accesses to be able to read from AUGUR_ variables if COLLECTOSS_ ones aren't present.

This PR works in the sense that CollectOSS is able to start up with this change present with the default env

Signed commits

  • Yes, I signed my commits.

@MoralCode MoralCode requested a review from shlokgilda May 8, 2026 20:52
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread tests/test_application/test_config/test_environment.py Fixed
Comment thread collectoss/api/view/init.py Outdated
@@ -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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0611: Unused KeyClient imported from keyman.KeyClient (unused-import)

Comment thread collectoss/tasks/git/dependency_tasks/core.py
Comment thread collectoss/tasks/git/dependency_tasks/core.py Outdated
Comment thread collectoss/tasks/git/scc_value_tasks/core.py
Comment thread collectoss/tasks/init/celery_app.py Outdated
@MoralCode MoralCode added this to the v1.1 Migration Release milestone May 8, 2026

@shlokgilda shlokgilda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added some inline comments

Comment thread collectoss/tasks/init/celery_app.py
Comment thread collectoss/application/environment.py Outdated
Comment thread collectoss/application/environment.py Outdated
Comment thread collectoss/application/environment.py
Comment thread collectoss/application/environment.py Outdated
Comment thread collectoss/application/environment.py
Comment thread collectoss/tasks/git/dependency_tasks/core.py Outdated
@MoralCode MoralCode added the waiting This change is waiting for some other changes to land first label May 18, 2026
@MoralCode MoralCode marked this pull request as draft May 20, 2026 20:27
@MoralCode MoralCode self-assigned this May 27, 2026
@MoralCode MoralCode moved this from Todo to In Progress in CollectOSS Feature Roadmap May 27, 2026
@MoralCode MoralCode changed the title introduce a SystemEnv class to unify environment variable use and enable smooth transition enable smooth environment variable naming transition May 29, 2026
@MoralCode MoralCode force-pushed the feat/flexible_env branch from 8041729 to 1f89a32 Compare May 29, 2026 21:44
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
Comment thread tests/test_classes/test_environment.py Fixed
MoralCode added 14 commits June 10, 2026 09:02
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>
MoralCode added 16 commits June 10, 2026 11:55
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
…autoimport locations

Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
so it doesn't import CollectOSS

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>
github keys being put in wrong places

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>
…tential completion

Temporary workaround until we have a faster DB initialization

Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@MoralCode MoralCode force-pushed the feat/flexible_env branch from e30329f to c049811 Compare June 10, 2026 15:56
this should hopefully take care of everything up front like the original scripts did, without creating issues related to the cursed import situation

Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@@ -130,7 +132,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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0621: Redefining name 'processes' from outer scope (line 397) (redefined-outer-name)

Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread collectoss/application/cli/backend.py Outdated
Comment thread docker/backend/preflight.py Outdated
MoralCode and others added 6 commits June 10, 2026 14:30
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>
…plication

Signed-off-by: Adrian Edwards <adredwar@redhat.com>
…re CollectOSS starts.

This avoids some race conditions with the startup process that could create issues, especially on first initialization and especially in CI where we are still replaying migrations

Co-Authored-By: guptapratykshh <pratykshgupta9999@gmail.com>
Co-Authored-By: Sukuna0007Abhi <appsonly310@gmail.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@MoralCode MoralCode force-pushed the feat/flexible_env branch from 9e2a164 to bba22af Compare June 10, 2026 21:15
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@MoralCode MoralCode merged commit 3094dc2 into main Jun 10, 2026
16 checks passed
@MoralCode MoralCode deleted the feat/flexible_env branch June 10, 2026 22:33
@github-project-automation github-project-automation Bot moved this from In Progress to Done in CollectOSS Feature Roadmap Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants