Class: Chef::Provider::SslCertificate

Inherits:
Chef::Provider show all
Defined in:
libraries/provider_ssl_certificate.rb

Overview

Chef Provider for ssl_certificate Resource.

Instance Method Summary collapse

Instance Method Details

#action_createObject


122
123
124
125
126
127
128
129
130
131
# File 'libraries/provider_ssl_certificate.rb', line 122

def action_create
  new_resource_updated = new_resource.updated_by_last_action?
  install_chef_vault
  return if current_resource_updated?(new_resource_updated)
  create_key
  create_cert
  create_pkcs12 if create_pkcs12?
  create_chain_combined
  create_chain if create_chain?
end

#create_certObject


78
79
80
81
82
83
# File 'libraries/provider_ssl_certificate.rb', line 78

def create_cert
  file_create(
    'SSL public certificate',
    new_resource.cert_path, new_resource.cert_content
  )
end

#create_chainObject


100
101
102
103
104
105
# File 'libraries/provider_ssl_certificate.rb', line 100

def create_chain
  file_create(
    'SSL intermediary chain certificate',
    new_resource.chain_path, new_resource.chain_content
  )
end

#create_chain?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'libraries/provider_ssl_certificate.rb', line 96

def create_chain?
  !new_resource.chain_name.nil? && !new_resource.chain_content.nil?
end

#create_chain_combinedObject


107
108
109
110
111
112
113
114
# File 'libraries/provider_ssl_certificate.rb', line 107

def create_chain_combined
  combined_content = [new_resource.cert_content]
  combined_content << new_resource.chain_content if create_chain?
  file_create(
    'SSL intermediary chain combined certificate',
    new_resource.chain_combined_path, combined_content.join("\n")
  )
end

#create_keyObject


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

def create_key
  file_create(
    'SSL certificate key',
    new_resource.key_path, new_resource.key_content, new_resource.key_mode
  )
end

#create_pkcs12Object


89
90
91
92
93
94
# File 'libraries/provider_ssl_certificate.rb', line 89

def create_pkcs12
  file_create(
    'SSL PKCS12 certificate',
    new_resource.pkcs12_path, new_resource.pkcs12_content, 00600
  )
end

#create_pkcs12?Boolean

Returns:

  • (Boolean)

85
86
87
# File 'libraries/provider_ssl_certificate.rb', line 85

def create_pkcs12?
  !new_resource.pkcs12_path.nil?
end

#current_resource_updated?(new_resource_updated) ⇒ Boolean

Returns:

  • (Boolean)

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

def current_resource_updated?(new_resource_updated)
  @current_resource.exist? &&
    @current_resource == new_resource &&
    new_resource_updated == false
end

#file(name, &resource_attrs_block) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'libraries/provider_ssl_certificate.rb', line 48

def file(name, &resource_attrs_block)
  resource = Chef::Resource::File.new(name, new_resource.run_context)
  resource.owner(new_resource.owner)
  resource.group(new_resource.group)
  resource.sensitive(true) if resource.respond_to?(:sensitive)
  resource.instance_eval(&resource_attrs_block) if block_given?
  resource.action(:nothing)
  resource
end

#file_create(desc, f_path, f_content, f_mode = 00644) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
69
# File 'libraries/provider_ssl_certificate.rb', line 58

def file_create(desc, f_path, f_content, f_mode = 00644)
  resource = file("#{new_resource.name} #{desc}") do
    path f_path
    content f_content
    mode f_mode
  end
  run_context.resource_collection << resource if defined?(ChefSpec)
  resource.run_action(:create)
  return resource unless resource.updated_by_last_action?
  new_resource.updated_by_last_action(true)
  resource
end

#install_chef_vaultObject


41
42
43
44
45
46
# File 'libraries/provider_ssl_certificate.rb', line 41

def install_chef_vault
  return unless new_resource.depends_chef_vault?
  r = Chef::Resource::ChefGem.new('chef-vault', new_resource.run_context)
  r.after_created
  new_resource.updated_by_last_action(r.updated_by_last_action?)
end

#load_current_resourceObject


34
35
36
37
38
39
# File 'libraries/provider_ssl_certificate.rb', line 34

def load_current_resource
  @current_resource ||=
    Chef::Resource::SslCertificate.new(@new_resource.name, run_context)
  @current_resource.load
  @current_resource
end