Hello all,
I’d like to add a configuration module etc/RT_SiteConfig.d/FromEnv.pm
with the following code:
###########################################################################
# Load configurations from environment. Not all configurations can be set,
# only those in CamelCase (e.g. rtname cannot). Supported environment
# variables MUST start with RTCFG, then words are separated by underscores.
#
# Example: RTCFG_ORGANIZATION --> Organization
# Example: RTCFG_WEB_PORT --> WebPort
# Example: RTCFG_LOG_TO_FILE_NAMED --> LogToFileNamed
#
# Relies on RT::Config::SetFromConfig to behave like it does, which is
# unfortunately not documented.
for my $env_key (keys(%ENV)) {
my ($leader, @parts) = split m{_}mxs, $env_key;
next if $leader ne 'RTCFG';
my $rt_key = join '', map { ucfirst(lc($_)) } @parts;
Set($rt_key, $ENV{$env_key});
}
1;
This usage of function Set()
(i.e. using variable $rt_key
that holds the name of the configuration, instead of the “usual” $WebPort
and $LogToFileNamed
) within the configuration module above is not documented and relies on the behaviour of method RT::Config::SetFromConfig()
which is not documented as well.
I’d like to avoid using something that works today but is potentially broken tomorrow, so I would either ask to clarify in the docs that this behaviour of Set()
(i.e. using a variable holding the name of the configuration) is supported or ask how else I can inject configurations read from the environment.
My use case is adapting RT to be run in Kubernetes, where I expect that the database credentials will be stored inside a Secret and then propagated into the Pod by means of one or more environment variables. This might possibly expand to other configurations held in a ConfigMap.
Thanks!