Skip to content

Commit

Permalink
Simplify oslo_config setup to use ST2_* env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Nov 9, 2024
1 parent 9256f36 commit d103fbf
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 43 deletions.
4 changes: 1 addition & 3 deletions st2actions/st2actions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(CONF)
CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
6 changes: 1 addition & 5 deletions st2actions/st2actions/notifier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH

CONF = cfg.CONF


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2actions/st2actions/scheduler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=sys_constants.VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2actions/st2actions/workflows/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=sys_constants.VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2api/st2api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2auth/st2auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource()
st2cfg.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
9 changes: 6 additions & 3 deletions st2common/st2common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,16 @@ def get_name(group_name, option_name):
return "ST2_{}__{}".format(group_name.upper(), option_name.upper())


def parse_args(args=None, ignore_errors=False):
def use_st2_env_vars(conf: cfg.ConfigOpts) -> None:
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = St2EnvironmentConfigurationSource()
conf._env_driver = St2EnvironmentConfigurationSource()


def parse_args(args=None, ignore_errors=False):
use_st2_env_vars(cfg.CONF)
register_opts(ignore_errors=ignore_errors)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)
3 changes: 1 addition & 2 deletions st2reactor/st2reactor/cmd/trigger_re_fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def _parse_config():
CONF.register_cli_opts(cli_opts)
st2cfg.register_opts(ignore_errors=False)

# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource()
st2cfg.use_st2_env_vars(CONF)
CONF(args=sys.argv[1:])


Expand Down
4 changes: 1 addition & 3 deletions st2reactor/st2reactor/garbage_collector/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2reactor/st2reactor/rules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2reactor/st2reactor/sensor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource()
st2cfg.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2reactor/st2reactor/timer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
4 changes: 1 addition & 3 deletions st2stream/st2stream/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@


def parse_args(args=None):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
cfg.CONF(
args=args,
version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH],
use_env=True, # Make our env var support explicit (default is True)
)


Expand Down
5 changes: 2 additions & 3 deletions st2tests/st2tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ def reset():


def parse_args(args=None, coordinator_noop=True):
# Override oslo_config's 'OS_' env var prefix with 'ST2_'.
cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource()
common_config.use_st2_env_vars(cfg.CONF)
_setup_config_opts(coordinator_noop=coordinator_noop)

kwargs = {"use_env": True}
kwargs = {}
if USE_DEFAULT_CONFIG_FILES:
kwargs["default_config_files"] = [DEFAULT_CONFIG_FILE_PATH]

Expand Down

0 comments on commit d103fbf

Please sign in to comment.