From 23d38f5253ed578dc675a24ab6a2eea0c98bd157 Mon Sep 17 00:00:00 2001 From: Girija Soni Date: Thu, 9 Jan 2025 16:58:45 +0530 Subject: [PATCH] Fixes #38124 - Invalidate tokens for specific user/users --- lib/hammer_cli_foreman.rb | 5 +++- lib/hammer_cli_foreman/registration_tokens.rb | 25 +++++++++++++++++++ lib/hammer_cli_foreman/user.rb | 3 ++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lib/hammer_cli_foreman/registration_tokens.rb diff --git a/lib/hammer_cli_foreman.rb b/lib/hammer_cli_foreman.rb index ef28fe132..299cb63ed 100644 --- a/lib/hammer_cli_foreman.rb +++ b/lib/hammer_cli_foreman.rb @@ -166,10 +166,13 @@ def self.exception_handler_class HammerCLI::MainCommand.lazy_subcommand('host-registration', _("Host Registration"), 'HammerCLIForeman::Registration', 'hammer_cli_foreman/registration') + + HammerCLI::MainCommand.lazy_subcommand('registration-tokens', _("Manipulate registration tokens"), + 'HammerCLIForeman::RegistrationTokens', 'hammer_cli_foreman/registration_tokens') + rescue => e handler = HammerCLIForeman::ExceptionHandler.new(:context => {}, :adapter => :base) handler.handle_exception(e) raise HammerCLI::ModuleLoadingError.new(e) end - end diff --git a/lib/hammer_cli_foreman/registration_tokens.rb b/lib/hammer_cli_foreman/registration_tokens.rb new file mode 100644 index 000000000..c56be1589 --- /dev/null +++ b/lib/hammer_cli_foreman/registration_tokens.rb @@ -0,0 +1,25 @@ +module HammerCLIForeman + class RegistrationTokens < HammerCLIForeman::Command + resource :registration_tokens + command_name 'registration-tokens' + desc _('Manage registration tokens') + + class InvalidateMultipleCommand < HammerCLIForeman::DeleteCommand + action :invalidate_jwt_tokens + command_name 'invalidate-multiple' + success_message _('Successfully invalidated registration tokens.') + + build_options + end + + class InvalidateCommand < HammerCLIForeman::DeleteCommand + action :invalidate_jwt + command_name 'invalidate' + success_message _('Successfully invalidated registration tokens.') + + build_options + end + + autoload_subcommands + end +end diff --git a/lib/hammer_cli_foreman/user.rb b/lib/hammer_cli_foreman/user.rb index 01ab8f71e..a9da87237 100644 --- a/lib/hammer_cli_foreman/user.rb +++ b/lib/hammer_cli_foreman/user.rb @@ -93,7 +93,8 @@ class DeleteCommand < HammerCLIForeman::DeleteCommand lazy_subcommand('table-preference', _("Managing table preferences"), 'HammerCLIForeman::TablePreference', 'hammer_cli_foreman/table_preference' ) + lazy_subcommand('registration-tokens', _("Managing registration tokens"), + 'HammerCLIForeman::RegistrationTokens', 'hammer_cli_foreman/registration_tokens') autoload_subcommands end - end