Skip to content

Commit

Permalink
no bug - turn Bugzilla->localconfig into an object to make use of laz…
Browse files Browse the repository at this point in the history
…y attributes and so on
  • Loading branch information
dylanwh authored Jun 13, 2019
1 parent 4e7658c commit f781a22
Show file tree
Hide file tree
Showing 55 changed files with 165 additions and 125 deletions.
12 changes: 7 additions & 5 deletions Bugzilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use Bugzilla::Field;
use Bugzilla::Flag;
use Bugzilla::Hook;
use Bugzilla::Install::Localconfig qw(read_localconfig);
use Bugzilla::Localconfig;
use Bugzilla::Install::Util qw(init_console include_languages);
use Bugzilla::Memcached;
use Bugzilla::Template;
Expand Down Expand Up @@ -163,16 +164,17 @@ sub input_params {
}
sub localconfig {
return $_[0]->process_cache->{localconfig} ||= read_localconfig();
return $_[0]->process_cache->{localconfig} ||= Bugzilla::Localconfig->new(read_localconfig());
}
sub params {
return request_cache->{params} ||= Bugzilla::Config::read_param_file();
}
sub get_param_with_override {
my ($class, $name) = @_;
return $class->localconfig->{param_override}{$name} // $class->params->{$name};
return $class->localconfig->param_override->{$name} // $class->params->{$name};
}

sub user {
Expand Down Expand Up @@ -449,7 +451,7 @@ sub job_queue {
sub jwt {
my ($class, @args) = @_;
require Mojo::JWT;
return Mojo::JWT->new(@args, secret => $class->localconfig->{jwt_secret});
return Mojo::JWT->new(@args, secret => $class->localconfig->jwt_secret);
}

sub dbh {
Expand Down Expand Up @@ -751,8 +753,8 @@ sub memcached {
# Connector to the Datadog metrics collection daemon.
sub datadog {
my ($class, $namespace) = @_;
my $host = $class->localconfig->{datadog_host};
my $port = $class->localconfig->{datadog_port};
my $host = $class->localconfig->datadog_host;
my $port = $class->localconfig->datadog_port;

$namespace //= '';

Expand Down
6 changes: 3 additions & 3 deletions Bugzilla/App/Plugin/Glue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sub register {
}
);

$app->secrets([Bugzilla->localconfig->{side_wide_secret}]);
$app->secrets([Bugzilla->localconfig->site_wide_secret]);

$app->renderer->add_handler(
'bugzilla' => sub {
Expand Down Expand Up @@ -73,7 +73,7 @@ sub register {
my ($c, $type) = @_;

if ($type == LOGIN_REQUIRED) {
$c->redirect_to(Bugzilla->localconfig->{basepath} . 'login');
$c->redirect_to(Bugzilla->localconfig->basepath . 'login');
return undef;
}
else {
Expand Down Expand Up @@ -146,7 +146,7 @@ sub register {
'url_is_attachment_base' => sub {
my ($c, $id) = @_;
return 0 unless Bugzilla::Util::use_attachbase();
my $attach_base = Bugzilla->localconfig->{'attachment_base'};
my $attach_base = Bugzilla->localconfig->attachment_base;

# If we're passed an id, we only want one specific attachment base
# for a particular bug. If we're not passed an ID, we just want to
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/App/Plugin/Hostage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ sub register {

sub _before_routes {
my ($c) = @_;
state $urlbase = Bugzilla->localconfig->{urlbase};
state $urlbase = Bugzilla->localconfig->urlbase;
state $urlbase_uri = URI->new($urlbase);
state $urlbase_host = $urlbase_uri->host;
state $urlbase_host_regex = qr/^bug(\d+)\.\Q$urlbase_host\E$/;
state $attachment_base = Bugzilla->localconfig->{attachment_base};
state $attachment_base = Bugzilla->localconfig->attachment_base;
state $attachment_root = _attachment_root($attachment_base);
state $attachment_host_regex = _attachment_host_regex($attachment_base);

Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/App/Plugin/OAuth2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub register {
$conf->{verify_auth_code} = \&_verify_auth_code;
$conf->{store_access_token} = \&_store_access_token;
$conf->{verify_access_token} = \&_verify_access_token;
$conf->{jwt_secret} = Bugzilla->localconfig->{jwt_secret};
$conf->{jwt_secret} = Bugzilla->localconfig->jwt_secret;
$conf->{jwt_claims} = sub {
my $args = shift;
if (!$args->{user_id}) {
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/App/Plugin/SizeLimit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sub register {
my ($self, $app, $conf) = @_;

if (HAVE_BSD_RESOURCE) {
my $setrlimit = decode_json(Bugzilla->localconfig->{setrlimit});
my $setrlimit = decode_json(Bugzilla->localconfig->setrlimit);

# This trick means the master process will not a size limit.
Mojo::IOLoop->next_tick(sub {
Expand All @@ -55,7 +55,7 @@ sub register {
}

if (HAVE_LINUX_SMAPS_TINY) {
my $size_limit = Bugzilla->localconfig->{size_limit};
my $size_limit = Bugzilla->localconfig->size_limit;
return unless $size_limit;

if ($size_limit < MIN_SIZE_LIMIT) {
Expand Down
6 changes: 3 additions & 3 deletions Bugzilla/Attachment/PatchReader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ sub setup_patch_readers {

# Add in cvs context if we have the necessary info to do it
if ( $context ne 'patch'
&& Bugzilla->localconfig->{cvsbin}
&& Bugzilla->localconfig->cvsbin
&& Bugzilla->params->{'cvsroot_get'})
{
require Bugzilla::PatchReader::AddCVSContext;

# We need to set $cvsbin as global, because PatchReader::CVSClient
# needs it in order to find 'cvs'.
$main::cvsbin = Bugzilla->localconfig->{cvsbin};
$main::cvsbin = Bugzilla->localconfig->cvsbin;
$last_reader->sends_data_to(new Bugzilla::PatchReader::AddCVSContext(
$context, Bugzilla->params->{'cvsroot_get'}
));
Expand Down Expand Up @@ -310,7 +310,7 @@ sub setup_template_patch_reader {
$vars->{'collapsed'} = $cgi->param('collapsed');
$vars->{'context'} = $context;
$vars->{'do_context'}
= Bugzilla->localconfig->{cvsbin}
= Bugzilla->localconfig->cvsbin
&& Bugzilla->params->{'cvsroot_get'}
&& !$vars->{'newid'};

Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/Auth/Login/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sub get_login_info {
# Attachments are served from a separate host (ideally), and so
# an evil attachment cannot abuse this check with a redirect.
elsif (my $referer = $cgi->referer) {
my $urlbase = Bugzilla->localconfig->{urlbase};
my $urlbase = Bugzilla->localconfig->urlbase;
$valid = 1 if $referer =~ /^\Q$urlbase\E/;
}

Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/BugMail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ sub _get_new_bugmail_fields {

sub _parse_see_also {
my (@links) = @_;
my $urlbase = Bugzilla->localconfig->{urlbase};
my $urlbase = Bugzilla->localconfig->urlbase;
my $bug_link_re = qr/^\Q$urlbase\Eshow_bug\.cgi\?id=(\d+)$/;

return grep { /^\d+$/ } map { /$bug_link_re/ ? int($1) : () } @links;
Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/BugUrl/Bugzilla/Local.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sub _check_value {
sub local_uri {
my ($self, $bug_id) = @_;
$bug_id ||= '';
return Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=$bug_id";
return Bugzilla->localconfig->urlbase . "show_bug.cgi?id=$bug_id";
}

sub bug {
Expand Down
12 changes: 6 additions & 6 deletions Bugzilla/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ sub new {
sub target_uri {
my ($self) = @_;

my $base = Bugzilla->localconfig->{urlbase};
my $base = Bugzilla->localconfig->urlbase;
if (my $request_uri = $self->request_uri) {
my $base_uri = URI->new($base);
$base_uri->path('');
Expand Down Expand Up @@ -386,7 +386,7 @@ sub _prevent_unsafe_response {

# Note that urlbase must end with a /.
# It almost certainly does, but let's be extra careful.
my $urlbase = Bugzilla->localconfig->{urlbase};
my $urlbase = Bugzilla->localconfig->urlbase;
$urlbase =~ s{/$}{};
qr{
# Begins with literal urlbase
Expand Down Expand Up @@ -616,7 +616,7 @@ sub send_cookie {
}

# Add the default path and the domain in.
state $uri = URI->new(Bugzilla->localconfig->{urlbase});
state $uri = URI->new(Bugzilla->localconfig->urlbase);
$paramhash{'-path'} = $uri->path;

# we don't set the domain.
Expand Down Expand Up @@ -710,7 +710,7 @@ sub redirect_search_url {

sub redirect_to_https {
my $self = shift;
my $urlbase = Bugzilla->localconfig->{'urlbase'};
my $urlbase = Bugzilla->localconfig->urlbase;

# If this is a POST, we don't want ?POSTDATA in the query string.
# We expect the client to re-POST, which may be a violation of
Expand All @@ -733,14 +733,14 @@ sub redirect_to_https {
sub redirect_to_urlbase {
my $self = shift;
my $path = $self->url('-path_info' => 1, '-query' => 1, '-relative' => 1);
print $self->redirect('-location' => Bugzilla->localconfig->{urlbase} . $path);
print $self->redirect('-location' => Bugzilla->localconfig->urlbase . $path);
exit;
}

sub base_redirect {
my ($self, $path, $is_perm) = @_;
print $self->redirect(
-location => Bugzilla->localconfig->{basepath} . ($path || ''),
-location => Bugzilla->localconfig->basepath . ($path || ''),
-status => $is_perm ? '301 Moved Permanently' : '302 Found'
);
exit;
Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ sub write_params {
local $Data::Dumper::Sortkeys = 1;

my %params = %$param_data;
$params{urlbase} = Bugzilla->localconfig->{urlbase};
$params{urlbase} = Bugzilla->localconfig->urlbase;
__PACKAGE__->_write_file(Data::Dumper->Dump([\%params], ['*param']));

# And now we have to reset the params cache so that Bugzilla will re-read
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ sub DEFAULT_CSP {
# Because show_bug code lives in many different .cgi files,
# we needed a centralized place to define the policy.
# normally the policy would just live in one .cgi file.
# Additionally, Bugzilla->localconfig->{urlbase} cannot be called at compile time, so this can't be a constant.
# Additionally, Bugzilla->localconfig->urlbase cannot be called at compile time, so this can't be a constant.
sub SHOW_BUG_MODAL_CSP {
my ($bug_id) = @_;
my %policy = (
Expand Down Expand Up @@ -811,7 +811,7 @@ sub SHOW_BUG_MODAL_CSP {
worker_src => ['none',],
);
if (Bugzilla::Util::use_attachbase() && $bug_id) {
my $attach_base = Bugzilla->localconfig->{'attachment_base'};
my $attach_base = Bugzilla->localconfig->attachment_base;
$attach_base =~ s/\%bugid\%/$bug_id/g;
push @{$policy{img_src}}, $attach_base;
push @{$policy{media_src}}, $attach_base;
Expand Down
12 changes: 6 additions & 6 deletions Bugzilla/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ sub connect_shadow {
$connect_params->{db_port} = Bugzilla->get_param_with_override('shadowdbport');
$connect_params->{db_sock} = Bugzilla->get_param_with_override('shadowdbsock');

if ( Bugzilla->localconfig->{'shadowdb_user'}
&& Bugzilla->localconfig->{'shadowdb_pass'})
if ( Bugzilla->localconfig->shadowdb_user
&& Bugzilla->localconfig->shadowdb_pass)
{
$connect_params->{db_user} = Bugzilla->localconfig->{'shadowdb_user'};
$connect_params->{db_pass} = Bugzilla->localconfig->{'shadowdb_pass'};
$connect_params->{db_user} = Bugzilla->localconfig->shadowdb_user;
$connect_params->{db_pass} = Bugzilla->localconfig->shadowdb_pass;
}
return $shadow_dbh = _connect($connect_params);
}
Expand Down Expand Up @@ -292,7 +292,7 @@ sub bz_create_database {

# See if we can connect to the actual Bugzilla database.
my $conn_success = eval { $dbh = connect_main() };
my $db_name = Bugzilla->localconfig->{db_name};
my $db_name = Bugzilla->localconfig->db_name;

if (!$conn_success) {
$dbh = _get_no_db_connection();
Expand Down Expand Up @@ -511,7 +511,7 @@ sub bz_server_version {
sub bz_last_key {
my ($self, $table, $column) = @_;

return $self->last_insert_id(Bugzilla->localconfig->{db_name},
return $self->last_insert_id(Bugzilla->localconfig->db_name,
undef, $table, $column);
}

Expand Down
6 changes: 3 additions & 3 deletions Bugzilla/DB/Mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ sub bz_check_server_version {
my $self = shift;

my $lc = Bugzilla->localconfig;
if (lc(Bugzilla->localconfig->{db_name}) eq 'mysql') {
if (lc(Bugzilla->localconfig->db_name) eq 'mysql') {
die "It is not safe to run Bugzilla inside a database named 'mysql'.\n"
. " Please pick a different value for \$db_name in localconfig.\n";
}
Expand Down Expand Up @@ -381,7 +381,7 @@ sub bz_setup_database {
}

# Upgrade tables from MyISAM to InnoDB
my $db_name = Bugzilla->localconfig->{db_name};
my $db_name = Bugzilla->localconfig->db_name;
my $myisam_tables = $self->selectcol_arrayref(
'SELECT TABLE_NAME FROM information_schema.TABLES
WHERE TABLE_SCHEMA = ? AND ENGINE = ?', undef, $db_name, 'MyISAM'
Expand Down Expand Up @@ -823,7 +823,7 @@ sub default_row_format {

sub _alter_db_charset_to_utf8 {
my $self = shift;
my $db_name = Bugzilla->localconfig->{db_name};
my $db_name = Bugzilla->localconfig->db_name;
my $charset = $self->utf8_charset;
my $collate = $self->utf8_collate;
$self->do("ALTER DATABASE $db_name CHARACTER SET $charset COLLATE $collate");
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/DB/Oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sub BUILDARGS {

# You can never connect to Oracle without a DB name,
# and there is no default DB.
$dbname ||= Bugzilla->localconfig->{db_name};
$dbname ||= Bugzilla->localconfig->db_name;

# Set the language enviroment
$ENV{'NLS_LANG'} = '.AL32UTF8' if Bugzilla->params->{'utf8'};
Expand Down Expand Up @@ -646,7 +646,7 @@ sub bz_setup_database {
# Create a WORLD_LEXER named BZ_LEX for multilingual fulltext search
my $lexer = $self->selectcol_arrayref(
"SELECT pre_name FROM CTXSYS.CTX_PREFERENCES WHERE pre_name = ? AND
pre_owner = ?", undef, 'BZ_LEX', uc(Bugzilla->localconfig->{db_user})
pre_owner = ?", undef, 'BZ_LEX', uc(Bugzilla->localconfig->db_user)
);
if (!@$lexer) {
$self->do(
Expand Down
6 changes: 3 additions & 3 deletions Bugzilla/Install/Filesystem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use constant HTTPD_ENV => qw(
###############

# Used by the permissions "constants" below.
sub _suexec { Bugzilla->localconfig->{'use_suexec'} }
sub _group { Bugzilla->localconfig->{'webservergroup'} }
sub _suexec { Bugzilla->localconfig->use_suexec }
sub _group { Bugzilla->localconfig->webservergroup }

# Writeable by the owner only.
use constant OWNER_WRITE => 0600;
Expand Down Expand Up @@ -773,7 +773,7 @@ sub _fix_perms_recursively {
sub _check_web_server_group {
my ($output) = @_;

my $group = Bugzilla->localconfig->{'webservergroup'};
my $group = Bugzilla->localconfig->webservergroup;
my $filename = bz_locations()->{'localconfig'};
my $group_id;

Expand Down
15 changes: 3 additions & 12 deletions Bugzilla/Install/Localconfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use parent qw(Exporter);
our @EXPORT_OK = qw(
read_localconfig
update_localconfig
LOCALCONFIG_VARS
);

# might want to change this for upstream
Expand Down Expand Up @@ -96,7 +97,7 @@ use constant LOCALCONFIG_VARS => (
{name => 'memcached_servers', default => '',},
{name => 'memcached_namespace', default => "bugzilla:",},
{name => 'urlbase', default => '',},
{name => 'canonical_urlbase', default => '',},
{name => 'canonical_urlbase', lazy => 1},
{name => 'attachment_base', default => '',},
{name => 'ses_username', default => '',},
{name => 'ses_password', default => '',},
Expand Down Expand Up @@ -192,16 +193,6 @@ sub read_localconfig {
? _read_localconfig_from_env()
: _read_localconfig_from_file($include_deprecated);

# Use the site's URL as the default Canonical URL
$config->{canonical_urlbase} //= $config->{urlbase};

# Get the absolute path of the URLBase value
$config->{basepath} = do {
my $path = $config->{urlbase};
$path =~ s/^https?:\/\/.*?\//\//;
$path;
};

return $config;
}

Expand Down Expand Up @@ -264,7 +255,7 @@ sub update_localconfig {
}
}

if (!$localconfig->{'interdiffbin'} && $output) {
if (!$localconfig->{interdiffbin} && $output) {
print "\n", install_string('patchutils_missing'), "\n";
}

Expand Down
Loading

0 comments on commit f781a22

Please sign in to comment.