diff options
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 104 |
1 files changed, 90 insertions, 14 deletions
@@ -8,10 +8,12 @@ require 'rubygems/text' module Gem::GemcutterUtilities ERROR_CODE = 1 include Gem::Text attr_writer :host ## # Add the --key option @@ -72,7 +74,7 @@ module Gem::GemcutterUtilities # # If +allowed_push_host+ metadata is present, then it will only allow that host. - def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block) require 'net/http' self.host = host if host @@ -95,11 +97,19 @@ module Gem::GemcutterUtilities request_method = Net::HTTP.const_get method.to_s.capitalize response = Gem::RemoteFetcher.fetcher.request(uri, request_method, &block) - return response unless mfa_unauthorized?(response) - Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req| - req.add_field "OTP", get_otp - block.call(req) end end @@ -112,19 +122,37 @@ module Gem::GemcutterUtilities ask 'Code: ' end ## # Signs in with the RubyGems API at +sign_in_host+ and sets the rubygems API # key. - def sign_in(sign_in_host = nil) sign_in_host ||= self.host return if api_key - pretty_host = if Gem::DEFAULT_HOST == sign_in_host - 'RubyGems.org' - else - sign_in_host - end say "Enter your #{pretty_host} credentials." say "Don't have an account yet? " + @@ -134,14 +162,18 @@ module Gem::GemcutterUtilities password = ask_for_password "Password: " say "\n" - response = rubygems_api_request(:get, "api/v1/api_key", - sign_in_host) do |request| request.basic_auth email, password request.add_field "OTP", options[:otp] if options[:otp] end with_response response do |resp| - say "Signed in." set_api_key host, resp.body end end @@ -195,4 +227,48 @@ module Gem::GemcutterUtilities end end end |