Class: Gem::Commands::CheckcertCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
LocalRemoteOptions, VersionOption
Defined in:
lib/rubygems/commands/checkcert_command.rb

Overview

Gem command to display the certificate of a gem, if any.

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Constructor Details

#initializeCheckcertCommand

Returns a new instance of CheckcertCommand.



17
18
19
20
21
22
23
# File 'lib/rubygems/commands/checkcert_command.rb', line 17

def initialize
  super("checkcert", "Display the certificate of a gem's signature, if any.",
        :domain => :local, :version => Gem::Requirement.default)

  add_version_option
  add_local_remote_options
end

Instance Method Details

#argumentsObject

:nodoc:



25
26
27
# File 'lib/rubygems/commands/checkcert_command.rb', line 25

def arguments # :nodoc:
  'GEMNAME       name of an installed gem to check'
end

#check_certificateObject Also known as: execute



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubygems/commands/checkcert_command.rb', line 37

def check_certificate
  gem, specs = get_one_gem_name, []

  dep = Gem::Dependency.new gem, options[:version]

  if local? then
    if File.exist? gem then
      specs << Gem::Package.new(gem).spec # rescue nil
    else
      specs.push(*dep.matching_specs)
    end
  end

  if remote? then
    abort "rubygems sucks and doesn't include the cert info..."
  end

  if specs.empty? then
    alert_error "Unknown gem '#{gem}'"
    terminate_interaction 1
  end

  spec = specs.last
  cert = spec.cert_chain.join

  unless cert.empty? then
    IO.popen("openssl x509 -noout -text", "w+") do |io|
      io.puts cert
      puts io.read
    end
  else
    alert_error "Gem '#{gem}' is not signed"
    terminate_interaction 1
  end
end

#defaults_strObject

:nodoc:



29
30
31
# File 'lib/rubygems/commands/checkcert_command.rb', line 29

def defaults_str # :nodoc:
  "--local --version='>= 0'"
end

#usageObject

:nodoc:



33
34
35
# File 'lib/rubygems/commands/checkcert_command.rb', line 33

def usage # :nodoc:
  "#{program_name} GEMNAME [options]"
end