Class: Chef::Resource::SslCertificate

Inherits:
Chef::Resource show all
Includes:
Cert, Chain, Generators, Key, KeyCert, PKCS12, Readers, Subject
Defined in:
libraries/resource_ssl_certificate.rb,
libraries/resource_ssl_certificate_key.rb,
libraries/resource_ssl_certificate_cert.rb,
libraries/resource_ssl_certificate_chain.rb,
libraries/resource_ssl_certificate_pkcs12.rb,
libraries/resource_ssl_certificate_keycert.rb,
libraries/resource_ssl_certificate_readers.rb,
libraries/resource_ssl_certificate_subject.rb,
libraries/resource_ssl_certificate_generators.rb

Overview

ssl_certificate Chef Resource.

Defined Under Namespace

Modules: Cert, Chain, Generators, Key, KeyCert, PKCS12, Readers, Subject

Constant Summary

Constants included from PKCS12

PKCS12::ATTRS

Constants included from Generators

Generators::EXTENSIONS, Generators::FIELDS

Constants included from Chain

Chain::ATTRS, Chain::SOURCES

Constants included from Cert

Cert::ATTRS, Cert::SOURCES

Constants included from Key

Key::ATTRS, Key::SOURCES

Constants included from Subject

Subject::ATTRS

Instance Method Summary collapse

Methods included from PKCS12

#generate_pkcs12, #initialize_pkcs12_defaults, #pkcs12_content, #pkcs12_passphrase, #pkcs12_path, #verify_pkcs12

Methods included from Generators

#cert_add_extensions, #compare_self_signed_cert_with_ca, #compare_self_signed_cert_without_ca, #generate_ca_from_content, #generate_cert, #generate_cert_subject, #generate_cert_subject_from_hash, #generate_cert_subject_from_string, #generate_csr, #generate_generic_x509_key_cert, #generate_key, #generate_self_signed_cert_with_ca, #generate_self_signed_cert_with_ca_csr, #generate_self_signed_cert_with_ca_extensions, #generate_self_signed_cert_with_extensions, #generate_self_signed_cert_without_ca, #generate_self_signed_cert_without_ca_extensions, #handle_extended_key_usage, #handle_subject_alternative_names, #load_current_subjects, #log_debug_subjects, #verify_self_signed_cert

Methods included from Chain

#chain_bag, #chain_combined_name, #chain_combined_path, #chain_content, #chain_dir, #chain_encrypted, #chain_item, #chain_item_key, #chain_name, #chain_path, #chain_secret_file, #chain_source, #initialize_chain_defaults

Methods included from KeyCert

#bag, #dir, #encrypted, #item, #secret_file, #source, #years

Methods included from Cert

#ca_cert_path, #ca_key_passphrase, #ca_key_path, #cert_bag, #cert_content, #cert_dir, #cert_encrypted, #cert_item, #cert_item_key, #cert_name, #cert_path, #cert_secret_file, #cert_source, #extended_key_usage, #initialize_cert_defaults, #subject_alternate_names

Methods included from Key

#initialize_key_defaults, #key_bag, #key_content, #key_dir, #key_encrypted, #key_item, #key_item_key, #key_length, #key_mode, #key_name, #key_path, #key_secret_file, #key_source

Methods included from Subject

#city, #common_name, #country, #department, #email, #initialize_subject_defaults, #organization, #state

Constructor Details

#initialize(name, run_context = nil) ⇒ SslCertificate


61
62
63
64
65
66
67
68
69
# File 'libraries/resource_ssl_certificate.rb', line 61

def initialize(name, run_context = nil)
  super
  @resource_name = :ssl_certificate
  @action = :create
  @allowed_actions.push(@action)
  @provider = Chef::Provider::SslCertificate
  @namespace = Mash.new
  initialize_defaults
end

Instance Method Details

#==(other) ⇒ Object Also known as: ===


97
98
99
100
# File 'libraries/resource_ssl_certificate.rb', line 97

def ==(other)
  other.is_a?(self.class) &&
    key_eql?(other) && cert_eql?(other) && name_eql?(other)
end

#depends_chef_vault?Boolean


77
78
79
# File 'libraries/resource_ssl_certificate.rb', line 77

def depends_chef_vault?
  key_source == 'chef-vault' || cert_source == 'chef-vault'
end

#exist?Boolean


91
92
93
94
95
# File 'libraries/resource_ssl_certificate.rb', line 91

def exist?
  # chain_content is optional
  @key_content.is_a?(String) && @cert_content.is_a?(String) &&
    (@chain_content.is_a?(String) || @chain_content.nil?)
end

#group(arg = nil) ⇒ Object


128
129
130
131
132
133
# File 'libraries/resource_ssl_certificate.rb', line 128

def group(arg = nil)
  set_or_return(
    :group, arg,
    kind_of: String, default: node['ssl_certificate']['group']
  )
end

#initialize_attribute_defaults(attributes) ⇒ Object


71
72
73
74
75
# File 'libraries/resource_ssl_certificate.rb', line 71

def initialize_attribute_defaults(attributes)
  attributes.each do |var|
    instance_variable_set("@#{var}".to_sym, send("default_#{var}"))
  end
end

#loadObject

used by load_current_resource


82
83
84
85
86
87
88
89
# File 'libraries/resource_ssl_certificate.rb', line 82

def load
  key = read_from_path(key_path)
  key_content(key) unless key.nil?
  cert = read_from_path(cert_path)
  cert_content(cert) unless cert.nil?
  chain = read_from_path(chain_path) unless chain_path.nil?
  chain_content(chain) unless chain.nil?
end

#namespace(arg = nil) ⇒ Object


104
105
106
107
108
109
110
111
112
113
# File 'libraries/resource_ssl_certificate.rb', line 104

def namespace(arg = nil)
  unless arg.nil? || arg.is_a?(Chef::Node) ||
         arg.is_a?(Chef::Node::ImmutableMash)
    arg = read_node_namespace(arg)
  end
  set_or_return(
    :namespace, arg,
    kind_of: [Chef::Node, Chef::Node::ImmutableMash, Mash]
  )
end

#owner(arg = nil) ⇒ Object


122
123
124
125
126
# File 'libraries/resource_ssl_certificate.rb', line 122

def owner(arg = nil)
  set_or_return(
    :owner, arg, kind_of: String, default: node['ssl_certificate']['user']
  )
end

#time(arg = nil) ⇒ Object


115
116
117
118
119
120
# File 'libraries/resource_ssl_certificate.rb', line 115

def time(arg = nil)
  # ~ 10 years
  set_or_return(
    :time, arg, kind_of: [Integer, String, Time], default: 315_360_000
  )
end