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"
- VALID_CERTNAME =
Only allow printing ascii characters, excluding /
/\A[ -.0-~]+\Z/
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
- .validate_certname(name) ⇒ 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.
44 45 46 47 |
# File 'lib/vendor/puppet/ssl/base.rb', line 44 def initialize(name) @name = name.to_s.downcase self.class.validate_certname(@name) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
33 34 35 |
# File 'lib/vendor/puppet/ssl/base.rb', line 33 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/vendor/puppet/ssl/base.rb', line 33 def name @name end |
Class Method Details
.from_multiple_s(text) ⇒ Object
12 13 14 |
# File 'lib/vendor/puppet/ssl/base.rb', line 12 def self.from_multiple_s(text) text.split(SEPARATOR).collect { |inst| from_s(inst) } end |
.to_multiple_s(instances) ⇒ Object
16 17 18 |
# File 'lib/vendor/puppet/ssl/base.rb', line 16 def self.to_multiple_s(instances) instances.collect { |inst| inst.to_s }.join(SEPARATOR) end |
.validate_certname(name) ⇒ Object
29 30 31 |
# File 'lib/vendor/puppet/ssl/base.rb', line 29 def self.validate_certname(name) raise "Certname #{name.inspect} must not contain unprintable or non-ASCII characters" unless name =~ VALID_CERTNAME end |
.wrapped_class ⇒ Object
24 25 26 27 |
# File 'lib/vendor/puppet/ssl/base.rb', line 24 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
20 21 22 |
# File 'lib/vendor/puppet/ssl/base.rb', line 20 def self.wraps(klass) @wrapped_class = klass end |
Instance Method Details
#ca? ⇒ Boolean
Is this file for the CA?
36 37 38 |
# File 'lib/vendor/puppet/ssl/base.rb', line 36 def ca? name == Puppet::SSL::Host.ca_name end |
#fingerprint(md = :MD5) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vendor/puppet/ssl/base.rb', line 66 def fingerprint(md = :MD5) # 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
40 41 42 |
# File 'lib/vendor/puppet/ssl/base.rb', line 40 def generate raise Puppet::DevError, "#{self.class} did not override 'generate'" end |
#read(path) ⇒ Object
Read content from disk appropriately.
50 51 52 |
# File 'lib/vendor/puppet/ssl/base.rb', line 50 def read(path) @content = wrapped_class.new(File.read(path)) end |
#to_s ⇒ Object
Convert our thing to pem.
55 56 57 58 |
# File 'lib/vendor/puppet/ssl/base.rb', line 55 def to_s return "" unless content content.to_pem end |
#to_text ⇒ Object
Provide the full text of the thing we’re dealing with.
61 62 63 64 |
# File 'lib/vendor/puppet/ssl/base.rb', line 61 def to_text return "" unless content content.to_text end |