]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1514848 - Revoke all mozreview API keys
authorDylan William Hardison <dylan@hardison.net>
Wed, 19 Dec 2018 21:30:30 +0000 (16:30 -0500)
committerGitHub <noreply@github.com>
Wed, 19 Dec 2018 21:30:30 +0000 (16:30 -0500)
Bugzilla/DB.pm
Bugzilla/Quantum.pm
Bugzilla/Quantum/Command/revoke_api_keys.pm [new file with mode: 0644]
Makefile.PL

index 21c4386788dcf1b7e78bf02d18711b3ed6dce541..efe91105e36940a38d6352d2d0e21e37c58e9e78 100644 (file)
@@ -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;
index ab20b7ee4e75cc40656e648afd626a1ae46ff9a8..670781fb16273fe2351ccba4c4d86ce259b5634c 100644 (file)
@@ -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 (file)
index 0000000..304a88b
--- /dev/null
@@ -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<Bugzilla::Quantum::Command::revoke_api_keys> revokes API keys.
+
+=head1 ATTRIBUTES
+
+L<Bugzilla::Quantum::Command::revoke_api_keys> inherits all attributes from
+L<Mojolicious::Command> 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<Bugzilla::Quantum::Command::revoke_api_keys> inherits all methods from
+L<Mojolicious::Command> and implements the following new ones.
+
+=head2 run
+
+  $revoke_api_keys->run(@ARGV);
+
+Run this command.
+
+=cut
index 915644044f19125e7f42771a061db7c43977f43c..3171287ee34dc8d1bf7e615907c055d79dd0a0ab 100755 (executable)
@@ -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',