From 1e2027a97adb7481c7cb296330039313fefd95c6 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Mon, 4 Jul 2016 10:43:48 -0400 Subject: Bug 1284263 - Add optional support for $DATABASE_URL instead of localconfig for db_* connection params. --- Bugzilla/Install/Localconfig.pm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index 82ec9ae35..d591ece15 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -59,6 +59,10 @@ use constant LOCALCONFIG_VARS => ( name => 'use_suexec', default => 0, }, + { + name => 'db_from_env', + default => 0, + }, { name => 'db_driver', default => 'sqlite', @@ -198,6 +202,25 @@ sub read_localconfig { } } } + require Bugzilla::Error; + if ($localconfig{db_from_env}) { + if (Bugzilla->has_feature('db_from_env')) { + require URI::db; + unless ($ENV{DATABASE_URL}) { + Bugzilla::Error::ThrowUserError('missing_database_url'); + } + my $uri = URI::db->new($ENV{DATABASE_URL}); + $localconfig{db_driver} = $uri->canonical_engine; + $localconfig{db_name} = $uri->dbname; + $localconfig{db_host} = $uri->host; + $localconfig{db_user} = $uri->user; + $localconfig{db_pass} = $uri->password; + $localconfig{db_port} = $uri->port // 0; + } + else { + Bugzilla::Error::ThrowUserError('feature_disabled', { feature => 'db_from_env' }); + } + } return \%localconfig; } @@ -233,6 +256,7 @@ sub update_localconfig { my $output = $params->{output} || 0; my $answer = Bugzilla->installation_answers; my $localconfig = read_localconfig('include deprecated'); + my $db_from_env = Bugzilla->localconfig->{db_from_env}; my @new_vars; foreach my $var (LOCALCONFIG_VARS) { @@ -258,7 +282,7 @@ sub update_localconfig { # an answer file, then we don't notify about site_wide_secret # because we assume the intent was to auto-generate it anyway. if (!scalar(keys %$answer) || $name ne 'site_wide_secret') { - push(@new_vars, $name); + push(@new_vars, $name) unless $db_from_env && $name =~ /^db_(?!from_env)/; } $localconfig->{$name} = $var->{default}; } @@ -298,6 +322,9 @@ sub update_localconfig { foreach my $var (LOCALCONFIG_VARS) { my $name = $var->{name}; my $desc = $var->{desc}; + + next if $db_from_env && $name =~ /^db_(?!from_env)/; + if(!length $desc){ $desc = install_string("localconfig_$name", { root => ROOT_USER }); chomp($desc); -- cgit v1.2.3-24-g4f1b