Class: Puppet::SSL::Base
Overview
The base class for wrapping SSL instances.
Direct Known Subclasses
Certificate, CertificateRequest, CertificateRevocationList, Key
Constant Summary collapse
- SEPARATOR =
For now, use the YAML separator.
"\n---\n"
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .from_multiple_s(text) ⇒ Object
- .to_multiple_s(instances) ⇒ Object
- .wrapped_class ⇒ Object
- .wraps(klass) ⇒ Object
Instance Method Summary collapse
-
#ca? ⇒ Boolean
Is this file for the CA?.
- #fingerprint(md = :MD5) ⇒ Object
- #generate ⇒ Object
-
#initialize(name) ⇒ Base
constructor
A new instance of Base.
-
#read(path) ⇒ Object
Read content from disk appropriately.
-
#to_s ⇒ Object
Convert our thing to pem.
-
#to_text ⇒ Object
Provide the full text of the thing we’re dealing with.
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
36 37 38 |
# File 'lib/puppet/ssl/base.rb', line 36 def initialize(name) @name = name.to_s.downcase end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
25 26 27 |
# File 'lib/puppet/ssl/base.rb', line 25 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/puppet/ssl/base.rb', line 25 def name @name end |
Class Method Details
.from_multiple_s(text) ⇒ Object
8 9 10 |
# File 'lib/puppet/ssl/base.rb', line 8 def self.from_multiple_s(text) text.split(SEPARATOR).collect { |inst| from_s(inst) } end |
.to_multiple_s(instances) ⇒ Object
12 13 14 |
# File 'lib/puppet/ssl/base.rb', line 12 def self.to_multiple_s(instances) instances.collect { |inst| inst.to_s }.join(SEPARATOR) end |
.wrapped_class ⇒ Object
20 21 22 23 |
# File 'lib/puppet/ssl/base.rb', line 20 def self.wrapped_class raise(Puppet::DevError, "#{self} has not declared what class it wraps") unless defined?(@wrapped_class) @wrapped_class end |
.wraps(klass) ⇒ Object
16 17 18 |
# File 'lib/puppet/ssl/base.rb', line 16 def self.wraps(klass) @wrapped_class = klass end |
Instance Method Details
#ca? ⇒ Boolean
Is this file for the CA?
28 29 30 |
# File 'lib/puppet/ssl/base.rb', line 28 def ca? name == Puppet::SSL::Host.ca_name end |
#fingerprint(md = :MD5) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puppet/ssl/base.rb', line 57 def fingerprint(md = :MD5) require 'openssl/digest' # ruby 1.8.x openssl digest constants are string # but in 1.9.x they are symbols mds = md.to_s.upcase if OpenSSL::Digest.constants.include?(mds) md = mds elsif OpenSSL::Digest.constants.include?(mds.to_sym) md = mds.to_sym else raise ArgumentError, "#{md} is not a valid digest algorithm for fingerprinting certificate #{name}" end OpenSSL::Digest.const_get(md).hexdigest(content.to_der).scan(/../).join(':').upcase end |
#generate ⇒ Object
32 33 34 |
# File 'lib/puppet/ssl/base.rb', line 32 def generate raise Puppet::DevError, "#{self.class} did not override 'generate'" end |
#read(path) ⇒ Object
Read content from disk appropriately.
41 42 43 |
# File 'lib/puppet/ssl/base.rb', line 41 def read(path) @content = wrapped_class.new(File.read(path)) end |
#to_s ⇒ Object
Convert our thing to pem.
46 47 48 49 |
# File 'lib/puppet/ssl/base.rb', line 46 def to_s return "" unless content content.to_pem end |
#to_text ⇒ Object
Provide the full text of the thing we’re dealing with.
52 53 54 55 |
# File 'lib/puppet/ssl/base.rb', line 52 def to_text return "" unless content content.to_text end |