Skip to content

Commit

Permalink
Move ask_otp into a single method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecnelises committed Feb 1, 2019
1 parent ca12852 commit f3595e6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/rubygems/commands/owner_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def manage_owners(method, name, owners)
response = send_owner_request(method, name, owner)

if need_ask_otp? response
ask_otp
response = send_owner_request(method, name, owner)
end

Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def send_gem(name)
response = send_push_request(name, args)

if need_ask_otp? response
ask_otp
response = send_push_request(name, args)
end

Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/yank_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def yank_gem(version, platform)
response = yank_api_request(*args)

if need_ask_otp? response
ask_otp
response = yank_api_request(*args)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/rubygems/gemcutter_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def sign_in(sign_in_host = nil)
end

if need_ask_otp? response
ask_otp
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]
Expand Down Expand Up @@ -184,10 +185,12 @@ def need_ask_otp?(response)
return false if options[:otp]
return unless response.kind_of?(Net::HTTPUnauthorized) &&
response.body.start_with?('You have enabled multifactor authentication')
true
end

def ask_otp
say 'You have enabled multi-factor authentication. Please enter OTP code.'
options[:otp] = ask 'Code: '
true
end

def set_api_key(host, key)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/test_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# @fetcher.fetch_path('http://gems.example.com/sequence') # => [1, 2, 3]
# @fetcher.fetch_path('http://gems.example.com/sequence') # => [4, 5, 6]
#
# # use procs as fake response
# # procs can be accepted
#
# @fetcher.data['http://gems.example.com/random'] = proc do
# Random.rand
Expand Down

0 comments on commit f3595e6

Please sign in to comment.