summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Install
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-10-07 00:11:25 +0200
committerGitHub <noreply@github.com>2017-10-07 00:11:25 +0200
commitbbfe30297f0a56d4d384f60e0ff20e7c67e08d7a (patch)
treeb2f34eca75df83ecc1f8da1f5d59184bcad242b0 /Bugzilla/Install
parent6fe0afaa39271bbd75cf068abd67b19fd062a843 (diff)
downloadbugzilla-bbfe30297f0a56d4d384f60e0ff20e7c67e08d7a.tar.gz
bugzilla-bbfe30297f0a56d4d384f60e0ff20e7c67e08d7a.tar.xz
Bug 1404092 - Bugzilla->localconfig should directly use environmental variables and ignore the localconfig file
Diffstat (limited to 'Bugzilla/Install')
-rw-r--r--Bugzilla/Install/Filesystem.pm14
-rw-r--r--Bugzilla/Install/Localconfig.pm57
2 files changed, 68 insertions, 3 deletions
diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm
index 3114d64be..2a2e9b71a 100644
--- a/Bugzilla/Install/Filesystem.pm
+++ b/Bugzilla/Install/Filesystem.pm
@@ -21,7 +21,8 @@ use warnings;
use Bugzilla::Constants;
use Bugzilla::Error;
-use Bugzilla::Install::Localconfig;
+use Bugzilla::Install::Localconfig qw(ENV_KEYS);
+
use Bugzilla::Install::Util qw(install_string);
use Bugzilla::Util;
use Bugzilla::Hook;
@@ -101,6 +102,14 @@ use constant INDEX_HTML => <<'EOT';
</html>
EOT
+sub HTTPD_ENV_CONF {
+
+ return join( "\n",
+ "PerlPassEnv LOCALCONFIG_ENV",
+ map { "PerlPassEnv " . $_ } ENV_KEYS
+ ) . "\n";
+}
+
###############
# Permissions #
###############
@@ -407,6 +416,9 @@ sub FILESYSTEM {
"robots.txt" => { perms => CGI_READ,
overwrite => 1,
contents => \&robots_txt},
+ "httpd/env.conf" => { perms => CGI_READ,
+ overwrite => 1,
+ contents => \&HTTPD_ENV_CONF },
);
# Because checksetup controls the creation of index.html separately
diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm
index 8807a44dd..c1c8fb12e 100644
--- a/Bugzilla/Install/Localconfig.pm
+++ b/Bugzilla/Install/Localconfig.pm
@@ -30,14 +30,20 @@ use List::Util qw(first);
use Tie::Hash::NamedCapture;
use Safe;
use Term::ANSIColor;
+use Taint::Util qw(untaint);
use parent qw(Exporter);
our @EXPORT_OK = qw(
read_localconfig
update_localconfig
+ ENV_KEYS
);
+# might want to change this for upstream
+use constant ENV_PREFIX => 'BMO_';
+use constant PARAM_OVERRIDE => qw( inbound_proxies shadowdb shadowdbhost shadowdbport shadowdbsock );
+
sub _sensible_group {
return '' if ON_WINDOWS;
return scalar getgrgid($EGID);
@@ -82,6 +88,7 @@ use constant LOCALCONFIG_VARS => (
default => 'bugs',
},
{
+
name => 'db_user',
default => 'bugs',
},
@@ -149,7 +156,38 @@ use constant LOCALCONFIG_VARS => (
},
);
-sub read_localconfig {
+use constant ENV_KEYS => (
+ (map { ENV_PREFIX . $_->{name} } LOCALCONFIG_VARS),
+ (map { ENV_PREFIX . $_ } PARAM_OVERRIDE),
+);
+
+sub _read_localconfig_from_env {
+ my %localconfig;
+
+ foreach my $var ( LOCALCONFIG_VARS ) {
+ my $name = $var->{name};
+ my $key = ENV_PREFIX . $name;
+ if ($name eq 'param_override') {
+ foreach my $override (PARAM_OVERRIDE) {
+ my $o_key = ENV_PREFIX . $override;
+ $localconfig{param_override}{$override} = $ENV{$o_key};
+ untaint($localconfig{param_override}{$override});
+ }
+ }
+ elsif (exists $ENV{$key}) {
+ $localconfig{$name} = $ENV{$key};
+ untaint($localconfig{$name});
+ }
+ else {
+ my $default = $var->{default};
+ $localconfig{$name} = ref($default) eq 'CODE' ? $default->() : $default;
+ }
+ }
+
+ return \%localconfig;
+}
+
+sub _read_localconfig_from_file {
my ($include_deprecated) = @_;
my $filename = bz_locations()->{'localconfig'};
@@ -211,6 +249,16 @@ sub read_localconfig {
return \%localconfig;
}
+sub read_localconfig {
+ my ($include_deprecated) = @_;
+
+ if ($ENV{LOCALCONFIG_ENV}) {
+ return _read_localconfig_from_env();
+ }
+ else {
+ return _read_localconfig_from_file($include_deprecated);
+ }
+}
#
# This is quite tricky. But fun!
@@ -239,6 +287,11 @@ sub read_localconfig {
sub update_localconfig {
my ($params) = @_;
+ if ($ENV{LOCALCONFIG_ENV}) {
+ require Carp;
+ Carp::croak("update_localconfig() called with LOCALCONFIG_ENV enabled");
+ }
+
my $output = $params->{output} || 0;
my $answer = Bugzilla->installation_answers;
my $localconfig = read_localconfig('include deprecated');
@@ -319,7 +372,7 @@ sub update_localconfig {
}
# Reset the cache for Bugzilla->localconfig so that it will be re-read
- delete Bugzilla->request_cache->{localconfig};
+ delete Bugzilla->process_cache->{localconfig};
return { old_vars => \@old_vars, new_vars => \@new_vars };
}