Class: Gem::Commands::OwnerCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::OwnerCommand
- Includes:
- GemcutterUtilities, LocalRemoteOptions, Text
- Defined in:
- lib/rubygems/commands/owner_command.rb
Constant Summary
Constants included from GemcutterUtilities
GemcutterUtilities::API_SCOPES, GemcutterUtilities::ERROR_CODE, GemcutterUtilities::EXCLUSIVELY_API_SCOPES
Instance Attribute Summary
Attributes included from GemcutterUtilities
Attributes inherited from Gem::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
- #add_owners(name, owners) ⇒ Object
-
#arguments ⇒ Object
:nodoc:.
-
#description ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ OwnerCommand
constructor
A new instance of OwnerCommand.
- #manage_owners(method, name, owners) ⇒ Object
- #remove_owners(name, owners) ⇒ Object
- #show_owners(name) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
Methods included from GemcutterUtilities
#add_key_option, #add_otp_option, #api_key, #mfa_unauthorized?, #otp, #rubygems_api_request, #set_api_key, #sign_in, #update_scope, #verify_api_key, #webauthn_enabled?, #with_response
Methods included from Text
#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text
Methods included from LocalRemoteOptions
#accept_uri_http, #add_bulk_threshold_option, #add_clear_sources_option, #add_local_remote_options, #add_proxy_option, #add_source_option, #add_update_sources_option, #both?, #local?, #remote?
Methods inherited from Gem::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, #check_deprecated_options, common_options, #defaults_str, #deprecate_option, #deprecated?, extra_args, extra_args=, #extract_gem_name_and_version, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ OwnerCommand
Returns a new instance of OwnerCommand.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubygems/commands/owner_command.rb', line 37 def initialize super "owner", "Manage gem owners of a gem on the push server" add_proxy_option add_key_option add_otp_option defaults.merge! add: [], remove: [] add_option "-a", "--add NEW_OWNER", "Add an owner by user identifier" do |value, | [:add] << value end add_option "-r", "--remove OLD_OWNER", "Remove an owner by user identifier" do |value, | [:remove] << value end add_option "-h", "--host HOST", "Use another gemcutter-compatible host", " (e.g. https://rubygems.org)" do |value, | [:host] = value end end |
Instance Method Details
#add_owners(name, owners) ⇒ Object
87 88 89 |
# File 'lib/rubygems/commands/owner_command.rb', line 87 def add_owners(name, owners) manage_owners :post, name, owners end |
#arguments ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/rubygems/commands/owner_command.rb', line 29 def arguments # :nodoc: "GEM gem to manage owners for" end |
#description ⇒ Object
:nodoc:
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubygems/commands/owner_command.rb', line 13 def description # :nodoc: "The owner command lets you add and remove owners of a gem on a push\nserver (the default is https://rubygems.org). Multiple owners can be\nadded or removed at the same time, if the flag is given multiple times.\n\nThe supported user identifiers are dependent on the push server.\nFor rubygems.org, both e-mail and handle are supported, even though the\nuser identifier field is called \"email\".\n\nThe owner of a gem has the permission to push new versions, yank existing\nversions or edit the HTML page of the gem. Be careful of who you give push\npermission to.\n EOF\nend\n" |
#execute ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubygems/commands/owner_command.rb', line 59 def execute @host = [:host] sign_in(scope: get_owner_scope) name = get_one_gem_name add_owners name, [:add] remove_owners name, [:remove] show_owners name end |
#manage_owners(method, name, owners) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rubygems/commands/owner_command.rb', line 95 def manage_owners(method, name, owners) owners.each do |owner| response = send_owner_request(method, name, owner) action = method == :delete ? "Removing" : "Adding" with_response response, "#{action} #{owner}" rescue Gem::WebauthnVerificationError => e raise e rescue StandardError # ignore early exits to allow for completing the iteration of all owners end end |
#remove_owners(name, owners) ⇒ Object
91 92 93 |
# File 'lib/rubygems/commands/owner_command.rb', line 91 def remove_owners(name, owners) manage_owners :delete, name, owners end |
#show_owners(name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubygems/commands/owner_command.rb', line 70 def show_owners(name) Gem.load_yaml response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request| request.add_field "Authorization", api_key end with_response response do |resp| owners = Gem::SafeYAML.load clean_text(resp.body) say "Owners for gem: #{name}" owners.each do |owner| say "- #{owner["email"] || owner["handle"] || owner["id"]}" end end end |
#usage ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/rubygems/commands/owner_command.rb', line 33 def usage # :nodoc: "#{program_name} GEM" end |