Class: Puppet::SSL::CertificateAuthority::Interface
- Defined in:
- lib/puppet/ssl/certificate_authority/interface.rb
Defined Under Namespace
Classes: InterfaceError
Constant Summary collapse
- INTERFACE_METHODS =
[:destroy, :list, :revoke, :generate, :sign, :print, :verify, :fingerprint]
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#method ⇒ Object
Returns the value of attribute method.
-
#subjects ⇒ Object
Returns the value of attribute subjects.
Instance Method Summary collapse
-
#apply(ca) ⇒ Object
Actually perform the work.
-
#fingerprint(ca) ⇒ Object
Print certificate information.
- #generate(ca) ⇒ Object
-
#initialize(method, options) ⇒ Interface
constructor
A new instance of Interface.
-
#list(ca) ⇒ Object
List the hosts.
-
#print(ca) ⇒ Object
Print certificate information.
-
#sign(ca) ⇒ Object
Sign a given certificate.
Constructor Details
#initialize(method, options) ⇒ Interface
Returns a new instance of Interface.
42 43 44 45 46 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 42 def initialize(method, ) self.method = method self.subjects = [:to] @digest = [:digest] || :MD5 end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
12 13 14 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 12 def digest @digest end |
#method ⇒ Object
Returns the value of attribute method.
12 13 14 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 12 def method @method end |
#subjects ⇒ Object
Returns the value of attribute subjects.
12 13 14 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 12 def subjects @subjects end |
Instance Method Details
#apply(ca) ⇒ Object
Actually perform the work.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 15 def apply(ca) unless subjects or method == :list raise ArgumentError, "You must provide hosts or :all when using #{method}" end begin return send(method, ca) if respond_to?(method) (subjects == :all ? ca.list : subjects).each do |host| ca.send(method, host) end rescue InterfaceError raise rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not call #{method}: #{detail}" end end |
#fingerprint(ca) ⇒ Object
Print certificate information.
101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 101 def fingerprint(ca) (subjects == :all ? ca.list + ca.waiting?: subjects).each do |host| if value = ca.fingerprint(host, @digest) puts "#{host} #{value}" else Puppet.err "Could not find certificate for #{host}" end end end |
#generate(ca) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 34 def generate(ca) raise InterfaceError, "It makes no sense to generate all hosts; you must specify a list" if subjects == :all subjects.each do |host| ca.generate(host) end end |
#list(ca) ⇒ Object
List the hosts.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 49 def list(ca) unless subjects puts ca.waiting?.join("\n") return nil end signed = ca.list requests = ca.waiting? if subjects == :all hosts = [signed, requests].flatten elsif subjects == :signed hosts = signed.flatten else hosts = subjects end hosts.uniq.sort.each do |host| invalid = false begin ca.verify(host) unless requests.include?(host) rescue Puppet::SSL::CertificateAuthority::CertificateVerificationError => details invalid = details.to_s end if not invalid and signed.include?(host) puts "+ #{host} (#{ca.fingerprint(host, @digest)})" elsif invalid puts "- #{host} (#{ca.fingerprint(host, @digest)}) (#{invalid})" else puts "#{host} (#{ca.fingerprint(host, @digest)})" end end end |
#print(ca) ⇒ Object
Print certificate information.
90 91 92 93 94 95 96 97 98 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 90 def print(ca) (subjects == :all ? ca.list : subjects).each do |host| if value = ca.print(host) puts value else Puppet.err "Could not find certificate for #{host}" end end end |
#sign(ca) ⇒ Object
Sign a given certificate.
112 113 114 115 116 117 118 |
# File 'lib/puppet/ssl/certificate_authority/interface.rb', line 112 def sign(ca) list = subjects == :all ? ca.waiting? : subjects raise InterfaceError, "No waiting certificate requests to sign" if list.empty? list.each do |host| ca.sign(host) end end |