summaryrefslogtreecommitdiff
path: root/lib/rubygems/gemcutter_utilities.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/gemcutter_utilities.rb')
-rw-r--r--lib/rubygems/gemcutter_utilities.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 3687e776e2..00e68916c4 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -52,6 +52,13 @@ module Gem::GemcutterUtilities
end
##
+ # The OTP code from the command options or from the user's configuration.
+
+ def otp
+ options[:otp] || ENV["GEM_HOST_OTP_CODE"]
+ end
+
+ ##
# The host to connect to either from the RUBYGEMS_HOST environment variable
# or from the user's configuration
@@ -126,7 +133,7 @@ module Gem::GemcutterUtilities
response = rubygems_api_request(:put, "api/v1/api_key",
sign_in_host, scope: scope) do |request|
request.basic_auth email, password
- request["OTP"] = options[:otp] if options[:otp]
+ request["OTP"] = otp if otp
request.body = URI.encode_www_form({:api_key => api_key }.merge(update_scope_params))
end
@@ -159,7 +166,7 @@ module Gem::GemcutterUtilities
response = rubygems_api_request(:post, "api/v1/api_key",
sign_in_host, scope: scope) do |request|
request.basic_auth email, password
- request["OTP"] = options[:otp] if options[:otp]
+ request["OTP"] = otp if otp
request.body = URI.encode_www_form({ name: key_name }.merge(scope_params))
end
@@ -224,7 +231,7 @@ module Gem::GemcutterUtilities
request_method = Net::HTTP.const_get method.to_s.capitalize
Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req|
- req["OTP"] = options[:otp] if options[:otp]
+ req["OTP"] = otp if otp
block.call(req)
end
end