Class: Puppet::SSL::Base

Inherits:
Object show all
Defined in:
lib/puppet/ssl/base.rb

Overview

The base class for wrapping SSL instances.

Constant Summary collapse

SEPARATOR =

For now, use the YAML separator.

"\n---\n"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



25
26
27
# File 'lib/puppet/ssl/base.rb', line 25

def content
  @content
end

#nameObject

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_classObject

Raises:



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?

Returns:

  • (Boolean)


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

#generateObject

Raises:



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_sObject

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_textObject

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