aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/commands/push_command.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-01 11:01:00 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-01 11:01:00 +0000
commit7a46a3b94121339cbead211c4497142bee82fddb (patch)
treebc6e9f11a1b60f8c4258e4780b18f952b0a8ec35 /lib/rubygems/commands/push_command.rb
parent5cae104e51be9cbf524b7d953b33d0909c46d006 (diff)
downloadruby-7a46a3b94121339cbead211c4497142bee82fddb.tar.gz
Merge rubygems-3.0.0.beta3.
* [GSoC] Multi-factor feature for RubyGems https://github.com/rubygems/rubygems/pull/2369 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/push_command.rb')
-rw-r--r--lib/rubygems/commands/push_command.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb
index 20812368c4..3ea4703a3e 100644
--- a/lib/rubygems/commands/push_command.rb
+++ b/lib/rubygems/commands/push_command.rb
@@ -33,6 +33,7 @@ command. For further discussion see the help for the yank command.
add_proxy_option
add_key_option
+ add_otp_option
add_option('--host HOST',
'Push to another gemcutter-compatible host',
@@ -113,11 +114,10 @@ You can upgrade or downgrade to the latest release version with:
say "Pushing gem to #{@host || Gem.host}..."
- response = rubygems_api_request(*args) do |request|
- request.body = Gem.read_binary name
- request.add_field "Content-Length", request.body.size
- request.add_field "Content-Type", "application/octet-stream"
- request.add_field "Authorization", api_key
+ response = send_push_request(name, args)
+
+ if need_otp? response
+ response = send_push_request(name, args, true)
end
with_response response
@@ -125,6 +125,16 @@ You can upgrade or downgrade to the latest release version with:
private
+ def send_push_request(name, args, use_otp = false)
+ rubygems_api_request(*args) do |request|
+ request.body = Gem.read_binary name
+ request.add_field "Content-Length", request.body.size
+ request.add_field "Content-Type", "application/octet-stream"
+ request.add_field "Authorization", api_key
+ request.add_field "OTP", options[:otp] if use_otp
+ end
+ end
+
def get_hosts_for(name)
gem_metadata = Gem::Package.new(name).spec.metadata