From: Dylan William Hardison Date: Wed, 19 Dec 2018 21:30:30 +0000 (-0500) Subject: Bug 1514848 - Revoke all mozreview API keys X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9be1d11eb0ef93cbcdd247097f6ca43c30f77e80;p=thirdparty%2Fbugzilla.git Bug 1514848 - Revoke all mozreview API keys --- diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 21c438678..efe91105e 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -1352,7 +1352,7 @@ sub _build_connector { $attributes->{Callbacks} = { connected => sub { my ($dbh, $dsn) = @_; - INFO("$PROGRAM_NAME connected mysql $dsn"); + TRACE("$PROGRAM_NAME connected mysql $dsn"); ThrowCodeError('not_in_transaction') if $self && $self->bz_in_transaction; $class->on_dbi_connected(@_) if $class->can('on_dbi_connected'); return; diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm index ab20b7ee4..670781fb1 100644 --- a/Bugzilla/Quantum.pm +++ b/Bugzilla/Quantum.pm @@ -39,7 +39,7 @@ has 'static' => sub { Bugzilla::Quantum::Static->new }; sub startup { my ($self) = @_; - DEBUG('Starting up'); + TRACE('Starting up'); $self->plugin('Bugzilla::Quantum::Plugin::BlockIP'); $self->plugin('Bugzilla::Quantum::Plugin::Glue'); $self->plugin('Bugzilla::Quantum::Plugin::Hostage') @@ -50,6 +50,8 @@ sub startup { $self->plugin('Bugzilla::Quantum::Plugin::Helpers'); $self->plugin('Bugzilla::Quantum::Plugin::OAuth2'); + push @{ $self->commands->namespaces }, 'Bugzilla::Quantum::Command'; + $self->hook( before_routes => sub { my ($c) = @_; diff --git a/Bugzilla/Quantum/Command/revoke_api_keys.pm b/Bugzilla/Quantum/Command/revoke_api_keys.pm new file mode 100644 index 000000000..304a88b81 --- /dev/null +++ b/Bugzilla/Quantum/Command/revoke_api_keys.pm @@ -0,0 +1,96 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Quantum::Command::revoke_api_keys; ## no critic (Capitalization) +use 5.10.1; +use Mojo::Base 'Mojolicious::Command'; + +use Bugzilla::Constants; +use Bugzilla::User::APIKey; +use Mojo::File 'path'; +use Mojo::Util 'getopt'; +use PerlX::Maybe 'maybe'; + +has description => 'Revoke api keys'; +has usage => sub { shift->extract_usage }; + +sub run { + my ($self, @args) = @_; + my ($app_id, $description); + + Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + getopt \@args, + 'a|app-id=s' => \$app_id, + 'd|description-id=s' => \$description; + die $self->usage unless $app_id || $description; + + my $query = { + revoked => 0, + maybe(app_id => $app_id), maybe(description => $description) + }; + my $keys = Bugzilla::User::APIKey->match($query); + foreach my $key (@$keys) { + say 'Updating ', $key->id; + $key->set_revoked(1); + $key->update(); + } +} + +1; +__END__ +=encoding utf8 + +=head1 NAME + +Bugzilla::Quantum::Command::revoke_api_keys - revoke API keys command + +=head1 SYNOPSIS + + Usage: APPLICATION revoke_api_keys [OPTIONS] + + mojo revoke_api_keys -a deadbeef + + Options: + -h, --help Show this summary of available options + -a, --app-id app_id Match against a specific app_id + -d, --description desc Match against a specific description + +=head1 DESCRIPTION + +L revokes API keys. + +=head1 ATTRIBUTES + +L inherits all attributes from +L and implements the following new ones. + +=head2 description + + my $description = $revoke_api_keys->description; + $revoke_api_keys = $revoke_api_keys->description('Foo'); + +Short description of this command, used for the command list. + +=head2 usage + + my $usage = $revoke_api_keys->usage; + $revoke_api_keys = $revoke_api_keys->usage('Foo'); + +Usage information for this command, used for the help screen. + +=head1 METHODS + +L inherits all methods from +L and implements the following new ones. + +=head2 run + + $revoke_api_keys->run(@ARGV); + +Run this command. + +=cut diff --git a/Makefile.PL b/Makefile.PL index 915644044..3171287ee 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -82,6 +82,7 @@ my %requires = ( 'Net::DNS' => '0', 'Package::Stash' => '0.37', 'Parse::CPAN::Meta' => '1.44', + 'PerlX::Maybe' => 0, 'Role::Tiny' => '2.000003', 'Scope::Guard' => '0.21', 'Sereal' => '4.004',