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.1'

Instance Method Summary collapse

Constructor Details

#initializeCheckcertCommand



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

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:



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

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

#check_certificateObject Also known as: execute



36
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
# File 'lib/rubygems/commands/checkcert_command.rb', line 36

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::Format.from_file_by_path(gem).spec # rescue nil
    end

    specs.push(*Gem.source_index.search(dep)) if specs.empty?
  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:



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

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

#usageObject

:nodoc:



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

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