Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
60024b1
add a deprefix helper and some unit tests
MoralCode May 8, 2026
6735697
refactor into a better prefix extraction helper
MoralCode May 8, 2026
a547500
add first pass SystemEnv
MoralCode May 8, 2026
a0b3e20
allow different prefixes to be passed in for testing purposes
MoralCode May 8, 2026
657cc53
update deprecation message
MoralCode May 8, 2026
578c4a3
basic functionality unit tests
MoralCode May 8, 2026
ac8fcef
handle cases with no known prefix to avoid breaking stuff
MoralCode May 8, 2026
6aa89a2
factor out bool fetching class to deduplicate logic
MoralCode May 8, 2026
5d33715
Test to make sure we can potentially migrate the AUGUR_ vars in the c…
MoralCode May 8, 2026
1e07a3a
replace all references to os.getenv with new class
MoralCode May 8, 2026
af281ec
deprecate older Environment class that is buried in the module tree
MoralCode May 8, 2026
01c2fad
get_bool docstring
MoralCode May 8, 2026
f52626b
basic setter
MoralCode May 8, 2026
35845f1
replace references to os.environ[] with new class
MoralCode May 8, 2026
ed673bf
remove some redundant wrapping code
MoralCode May 8, 2026
c72520e
replace references to os.environ.get
MoralCode May 8, 2026
9ed52b8
Swap out only usage of deprecated Environment class
MoralCode May 8, 2026
a6070fd
Remove no-longer-used Environment class in API
MoralCode May 8, 2026
67bf777
Refactor extract_prefix
MoralCode May 29, 2026
ec58731
refactor get_bool
MoralCode May 29, 2026
b47a836
fix ~ path expansion in default scorecard value
MoralCode May 29, 2026
31f25c1
replace a bunch of env var names the application accesses
MoralCode May 20, 2026
a9101b5
update env var names in RST docs
MoralCode May 20, 2026
dc7e090
update vars in example env
MoralCode May 27, 2026
fb7d113
update variable names in docker compose
MoralCode May 27, 2026
bf8b20c
hard change env var prefix for CLI commands
MoralCode May 29, 2026
43c576a
attempt to add transitional variables for the specific existing place…
MoralCode May 29, 2026
d382165
factor tests into a class
MoralCode May 29, 2026
a80349d
import SystemEnv into celery_app
MoralCode May 29, 2026
aeb05b5
move test next to the actual known good config tests
MoralCode May 29, 2026
b340f65
add more detailed failure reasons to get_bool tests
MoralCode May 29, 2026
1f89a32
split environment tests into two classes
MoralCode May 29, 2026
741fba0
apply homedir resolution fix to SCC path as well
MoralCode May 29, 2026
de2fc9f
fix docs underline lengths
MoralCode May 29, 2026
6330627
remove unused imports
MoralCode May 29, 2026
a023827
use SystemEnv for fetching database variable
MoralCode May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions collectoss/api/gunicorn_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from collectoss.application.db.lib import get_value
from collectoss.application.db import dispose_database_engine
from collectoss.application.environment import SystemEnv

logger = logging.getLogger(__name__)

Expand All @@ -20,8 +21,8 @@
workers = multiprocessing.cpu_count() * 2 + 1
umask = 0o007
reload = True

is_dev = os.getenv("AUGUR_DEV", 'False').lower() in ('true', '1', 't', 'y', 'yes')
# this satisfies the type checker
is_dev = SystemEnv.get_bool("AUGUR_DEV", False)

if is_dev:

Expand All @@ -40,7 +41,8 @@
# set the log location for gunicorn
logs_directory = get_value('Logging', 'logs_directory')

is_docker = os.getenv("AUGUR_DOCKER_DEPLOY", 'False').lower() in ('true', '1', 't', 'y', 'yes')
# this syntax satisfies the type checker
is_docker = SystemEnv.get_bool("AUGUR_DOCKER_DEPLOY", False)
accesslog = f"{logs_directory}/gunicorn.log"
errorlog = f"{logs_directory}/gunicorn.log"

Expand Down
10 changes: 6 additions & 4 deletions collectoss/api/routes/auggie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import requests
import slack

from collectoss.application.environment import SystemEnv

from ..server import app


Expand Down Expand Up @@ -252,7 +254,7 @@ def get_auggie_user():
# return Response(response=response, status=200, mimetype="application/json")
## From Method
profile_name = 'collectoss'
if os.environ.get('AUGUR_IS_PROD'):
if SystemEnv.get('COLLECTOSS_IS_PROD'):
profile_name = 'default'
client = boto3.Session(region_name='us-east-1', profile_name=profile_name).client('dynamodb')
response = client.get_item(
Expand All @@ -278,7 +280,7 @@ def update_auggie_user_tracking():
# return Response(response=response, status=200, mimetype="application/json")
## From Method
profile_name = 'collectoss'
if os.environ.get('AUGUR_IS_PROD'):
if SystemEnv.get('COLLECTOSS_IS_PROD'):
profile_name = 'default'
client = boto3.Session(region_name='us-east-1', profile_name=profile_name).client('dynamodb')
response = client.update_item(
Expand Down Expand Up @@ -326,7 +328,7 @@ def slack_login():
print("slack_login")

r = requests.get(
url=f'https://slack.com/api/oauth.v2.access?code={body["code"]}&client_id={os.environ["AUGGIE_CLIENT_ID"]}&client_secret={os.environ["AUGGIE_CLIENT_SECRET"]}&redirect_uri=http%3A%2F%2Flocalhost%3A8080')
url=f'https://slack.com/api/oauth.v2.access?code={body["code"]}&client_id={SystemEnv.get("AUGGIE_CLIENT_ID")}&client_secret={SystemEnv.get("AUGGIE_CLIENT_SECRET")}&redirect_uri=http%3A%2F%2Flocalhost%3A8080')
data = r.json()

if (data["ok"]):
Expand All @@ -340,7 +342,7 @@ def slack_login():
email = user_response["user"]["email"]

profile_name = 'collectoss'
if os.environ.get('AUGUR_IS_PROD'):
if SystemEnv.get('COLLECTOSS_IS_PROD'):
profile_name = 'default'
print("Making Boto3 Session")
client = boto3.Session(region_name='us-east-1',
Expand Down
7 changes: 2 additions & 5 deletions collectoss/api/view/init.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
from pathlib import Path
from .server import Environment
from collectoss.application.logs import SystemLogger
import secrets, yaml

env = Environment()
from collectoss.application.environment import SystemEnv

# load configuration files and initialize globals
configFile = Path(env.setdefault("CONFIG_LOCATION", "config.yml"))
configFile = Path(SystemEnv.get("CONFIG_LOCATION") or "config.yml")

settings = {}

Expand Down
52 changes: 0 additions & 52 deletions collectoss/api/view/server/Environment.py

This file was deleted.

3 changes: 1 addition & 2 deletions collectoss/api/view/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .LoginException import LoginException
from .Environment import Environment
from .LoginException import LoginException
8 changes: 5 additions & 3 deletions collectoss/application/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

from collectoss.application.db.engine import DatabaseEngine
from collectoss.application.db import get_engine, dispose_database_engine
from sqlalchemy.exc import OperationalError
from sqlalchemy.exc import OperationalError
from collectoss.application.environment import SystemEnv



def check_connectivity(urls=["http://chaoss.community", "http://github.com", "http://gitlab.com"], timeout=10.0):
Expand Down Expand Up @@ -65,11 +67,11 @@ def new_func(ctx, *args, **kwargs):
return ctx.invoke(function_db_connection, *args, **kwargs)
except OperationalError as e:

db_environment_var = os.getenv("AUGUR_DB")
db_environment_var = SystemEnv.get("COLLECTOSS_DB")

# determine the location to print in error string
if db_environment_var:
location = f"the AUGUR_DB environment variable\nAUGUR_DB={os.getenv('AUGUR_DB')}"
location = f"the AUGUR_DB environment variable\nAUGUR_DB={SystemEnv.get('COLLECTOSS_DB')}"
else:
with open("db.config.json", 'r') as f:
db_config = json.load(f)
Expand Down
2 changes: 1 addition & 1 deletion collectoss/application/cli/_multicommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pathlib import Path
# import collectoss.application

CONTEXT_SETTINGS = dict(auto_envvar_prefix='AUGUR')
CONTEXT_SETTINGS = dict(auto_envvar_prefix='COLLECTOSS')

class CLIMultiCommand(click.MultiCommand):
def __commands_folder(self):
Expand Down
8 changes: 5 additions & 3 deletions collectoss/application/cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from collectoss.application.cli import test_connection, test_db_connection, with_database, DatabaseContext
from collectoss.application.cli._cli_util import _broadcast_signal_to_processes, raise_open_file_limit, clear_redis_caches, clear_rabbitmq_messages
from collectoss.application.db.lib import get_value
from collectoss.application.environment import SystemEnv


logger = SystemLogger("collectoss", reset_logfiles=False).get_logger()

Expand All @@ -36,7 +38,7 @@ def start(ctx, development, port):
"""Start CollectOSS's backend server."""

try:
if os.environ.get('AUGUR_DOCKER_DEPLOY') != "1":
if SystemEnv.get('COLLECTOSS_DOCKER_DEPLOY') != "1":
raise_open_file_limit(100000)
except Exception as e:
logger.error(
Expand All @@ -46,7 +48,7 @@ def start(ctx, development, port):
raise e

if development:
os.environ["AUGUR_DEV"] = "1"
SystemEnv.set("AUGUR_DEV", "1")
logger.info("Starting in development mode")

try:
Expand Down Expand Up @@ -142,7 +144,7 @@ def get_api_processes():
def is_api_process(process):

command = ''.join(process.info['cmdline'][:]).lower()
if os.getenv('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in command:
if SystemEnv.get('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in command:

if process.pid != os.getpid():

Expand Down
23 changes: 12 additions & 11 deletions collectoss/application/cli/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


from collectoss.application.environment import SystemEnv
from collectoss.tasks.start_tasks import collection_monitor, create_collection_status_records
from collectoss.tasks.git.facade_tasks import clone_repos
from collectoss.tasks.github.contributors import process_contributors
Expand All @@ -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)


reset_logs = os.getenv("AUGUR_RESET_LOGS", 'True').lower() in ('true', '1', 't', 'y', 'yes')
reset_logs = SystemEnv.get_bool("AUGUR_RESET_LOGS", True)

logger = SystemLogger("collectoss", reset_logfiles=reset_logs).get_logger()

Expand Down Expand Up @@ -61,7 +62,7 @@ def start(ctx, disable_collection, development, pidfile, port):
signal.signal(signal.SIGINT, manager.shutdown_signal_handler)

try:
if os.environ.get('AUGUR_DOCKER_DEPLOY') != "1":
if SystemEnv.get('COLLECTOSS_DOCKER_DEPLOY') != "1":
raise_open_file_limit(100000)
except Exception as e:
logger.error(
Expand All @@ -71,10 +72,10 @@ def start(ctx, disable_collection, development, pidfile, port):
raise e

if development:
os.environ["AUGUR_DEV"] = "1"
SystemEnv.set("AUGUR_DEV", "1")
logger.info("Starting in development mode")

os.environ["AUGUR_PIDFILE"] = pidfile
SystemEnv.set("AUGUR_PIDFILE", pidfile)

try:
gunicorn_location = os.getcwd() + "/collectoss/api/gunicorn_conf.py"
Expand All @@ -86,10 +87,10 @@ def start(ctx, disable_collection, development, pidfile, port):
if not port:
port = get_value("Server", "port")

os.environ["AUGUR_PORT"] = str(port)
SystemEnv.set("AUGUR_PORT", str(port))

if disable_collection:
os.environ["AUGUR_DISABLE_COLLECTION"] = "1"
SystemEnv.set("AUGUR_DISABLE_COLLECTION", "1")

core_worker_count = get_value("Celery", 'core_worker_count')
secondary_worker_count = get_value("Celery", 'secondary_worker_count')
Expand Down Expand Up @@ -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)

manager.processes = processes

celery_beat_schedule_db = os.getenv("CELERYBEAT_SCHEDULE_DB", "celerybeat-schedule.db")
celery_beat_schedule_db = SystemEnv.get("CELERYBEAT_SCHEDULE_DB", "celerybeat-schedule.db")
if os.path.exists(celery_beat_schedule_db):
logger.info("Deleting old task schedule")
os.remove(celery_beat_schedule_db)
Expand All @@ -144,7 +145,7 @@ def start(ctx, disable_collection, development, pidfile, port):
manager.keypub = keypub

if not disable_collection:
if os.environ.get('AUGUR_DOCKER_DEPLOY') != "1":
if SystemEnv.get('COLLECTOSS_DOCKER_DEPLOY') != "1":
orchestrator = subprocess.Popen("python keyman/Orchestrator.py".split())

# Wait for orchestrator startup
Expand Down Expand Up @@ -355,10 +356,10 @@ def export_env(config):
Exports your GitHub key and database credentials
"""

export_file = open(os.getenv('AUGUR_EXPORT_FILE', 'collectoss_export_env.sh'), 'w+')
export_file = open(SystemEnv.get('COLLECTOSS_EXPORT_FILE') or 'collectoss_export_env.sh', 'w+')
export_file.write('#!/bin/bash')
export_file.write('\n')
env_file = open(os.getenv('AUGUR_ENV_FILE', 'docker_env.txt'), 'w+')
env_file = open(SystemEnv.get('COLLECTOSS_ENV_FILE') or 'docker_env.txt', 'w+')

for env_var in config.get_env_config().items():
if "LOG" not in env_var[0]:
Expand Down Expand Up @@ -403,7 +404,7 @@ def get_backend_processes():
for process in psutil.process_iter(['cmdline', 'name', 'environ']):
if process.info['cmdline'] is not None and process.info['environ'] is not None:
try:
if os.getenv('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in ''.join(process.info['cmdline'][:]).lower():
if SystemEnv.get('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in ''.join(process.info['cmdline'][:]).lower():
if process.pid != os.getpid():
process_list.append(process)
except (KeyError, FileNotFoundError):
Expand Down
7 changes: 4 additions & 3 deletions collectoss/application/cli/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import traceback
import sqlalchemy as s

from collectoss.application.environment import SystemEnv
from collectoss.tasks.start_tasks import collection_monitor, create_collection_status_records
from collectoss.tasks.git.facade_tasks import clone_repos
from collectoss.tasks.github.util.github_api_key_handler import GithubApiKeyHandler
Expand Down Expand Up @@ -45,7 +46,7 @@ def start(ctx, development):
"""Start CollectOSS's backend server."""

try:
if os.environ.get('AUGUR_DOCKER_DEPLOY') != "1":
if SystemEnv.get('COLLECTOSS_DOCKER_DEPLOY') != "1":
raise_open_file_limit(100000)
except Exception as e:
logger.error(
Expand Down Expand Up @@ -75,7 +76,7 @@ def start(ctx, development):
keypub.publish(key, "gitlab_rest")

if development:
os.environ["AUGUR_DEV"] = "1"
SystemEnv.set("AUGUR_DEV", "1")
logger.info("Starting in development mode")

core_worker_count = get_value("Celery", 'core_worker_count')
Expand Down Expand Up @@ -237,7 +238,7 @@ def get_collection_processes():
def is_collection_process(process):

command = ''.join(process.info['cmdline'][:]).lower()
if os.getenv('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in command:
if SystemEnv.get('VIRTUAL_ENV') in process.info['environ']['VIRTUAL_ENV'] and 'python' in command:
if process.pid != os.getpid():

if "collectossbackendcollection" in command or "celery_app.celery_appbeat" in command:
Expand Down
17 changes: 10 additions & 7 deletions collectoss/application/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@

logger = logging.getLogger(__name__)

ENVVAR_PREFIX = "AUGUR_"
ENVVAR_PREFIX = "COLLECTOSS_"

def get_transitional_envs(name: str) -> list:
return [ENVVAR_PREFIX + name, "AUGUR_" + name]

@click.group('config', short_help='Generate an augur.config.json')
@click.pass_context
def cli(ctx):
ctx.obj = DatabaseContext()

@cli.command('init')
@click.option('--github-api-key', help="GitHub API key for data collection from the GitHub API", envvar=ENVVAR_PREFIX + 'GITHUB_API_KEY')
@click.option('--facade-repo-directory', help="Directory on the database server where Facade should clone repos", envvar=ENVVAR_PREFIX + 'FACADE_REPO_DIRECTORY')
@click.option('--gitlab-api-key', help="GitLab API key for data collection from the GitLab API", envvar=ENVVAR_PREFIX + 'GITLAB_API_KEY')
@click.option('--redis-conn-string', help="String to connect to redis cache", envvar=ENVVAR_PREFIX + 'REDIS_CONN_STRING')
@click.option('--rabbitmq-conn-string', help="String to connect to rabbitmq broker", envvar=ENVVAR_PREFIX + 'RABBITMQ_CONN_STRING')
@click.option('--logs-directory', help="Directory to store logs", envvar=ENVVAR_PREFIX + 'LOGS_DIRECTORY')
@click.option('--github-api-key', help="GitHub API key for data collection from the GitHub API", envvar=get_transitional_envs('GITHUB_API_KEY'))
@click.option('--facade-repo-directory', help="Directory on the database server where Facade should clone repos", envvar=get_transitional_envs('FACADE_REPO_DIRECTORY'))
@click.option('--gitlab-api-key', help="GitLab API key for data collection from the GitLab API", envvar=get_transitional_envs('GITLAB_API_KEY'))
@click.option('--redis-conn-string', help="String to connect to redis cache", envvar=get_transitional_envs('REDIS_CONN_STRING'))
@click.option('--rabbitmq-conn-string', help="String to connect to rabbitmq broker", envvar=get_transitional_envs('RABBITMQ_CONN_STRING'))
@click.option('--logs-directory', help="Directory to store logs", envvar=get_transitional_envs('LOGS_DIRECTORY'))
@test_connection
@test_db_connection
@with_database
Expand Down
Loading
Loading