1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rubygems/commands/push_command.rb
drbrain 1633e543db * lib/rubygems/commands/push_command.rb: Fixed credential download for
`gem push --host`
* lib/rubygems/gemcutter_utilities.rb:  ditto.
* test/rubygems/test_gem_commands_push_command.rb:  Test for the above.
* test/rubygems/test_gem_gemcutter_utilities.rb:  ditto.

* lib/rubygems/config_file.rb:  Abort if the `gem push` credentials
  file has insecure permissions.
* test/rubygems/test_gem_config_file.rb:  Test for the above.

* lib/rubygems/ext/builder.rb:  Do not look for Gemfile, Isolate, etc.
  while building gem extensions.

* lib/rubygems/package.rb:  Unset spec and files list if a gem's
  signatures cannot be verified.
* test/rubygems/test_gem_package.rb:  Test for the above.

* lib/rubygems/specification.rb:  Reduce use of eval.
* lib/rubygems/test_case.rb:  ditto.

* test/rubygems/test_gem_specification.rb:  Test setting
  specification_version for legacy gems.  Dup Gem.ruby before
  untainting in case it's frozen.

* lib/rubygems.rb:  Reduce use of eval.  Only read files when looking
  for Gemfile, Isolate, etc.
* test/rubygems/test_gem.rb:  Test for the above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-05 02:37:35 +00:00

86 lines
2 KiB
Ruby

require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/gemcutter_utilities'
require 'rubygems/package'
class Gem::Commands::PushCommand < Gem::Command
include Gem::LocalRemoteOptions
include Gem::GemcutterUtilities
def description # :nodoc:
'Push a gem up to RubyGems.org'
end
def arguments # :nodoc:
"GEM built gem to push up"
end
def usage # :nodoc:
"#{program_name} GEM"
end
def initialize
super 'push', description
add_proxy_option
add_key_option
add_option('--host HOST',
'Push to another gemcutter-compatible host') do |value, options|
options[:host] = value
end
@host = nil
end
def execute
@host = options[:host]
sign_in @host
send_gem get_one_gem_name
end
def send_gem name
args = [:post, "api/v1/gems"]
latest_rubygems_version = Gem.latest_rubygems_version
if latest_rubygems_version < Gem.rubygems_version and
Gem.rubygems_version.prerelease? and
Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version then
alert_error <<-ERROR
You are using a beta release of RubyGems (#{Gem::VERSION}) which is not
allowed to push gems. Please downgrade or upgrade to a release version.
The latest released RubyGems version is #{latest_rubygems_version}
You can upgrade or downgrade to the latest release version with:
gem update --system=#{latest_rubygems_version}
ERROR
terminate_interaction 1
end
unless @host then
if gem_data = Gem::Package.new(name) then
@host = gem_data.spec.metadata['default_gem_server']
end
end
args << @host if @host
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
end
with_response response
end
end