Module: Formatron::S3::ChefServerCert

Defined in:
lib/formatron/s3/chef_server_cert.rb

Overview

manage the Chef Server SSL certificate and key stored on S3

Constant Summary collapse

CERT_NAME =
'ssl.cert'
KEY_NAME =
'ssl.key'

Class Method Summary collapse

Class Method Details

.cert_key(name:, target:, guid:) ⇒ Object

rubocop:enable Metrics/MethodLength



68
69
70
71
72
73
74
# File 'lib/formatron/s3/chef_server_cert.rb', line 68

def self.cert_key(name:, target:, guid:)
  Path.key(
    name: name,
    target: target,
    sub_key: "#{guid}/#{CERT_NAME}"
  )
end

.deploy(aws:, kms_key:, bucket:, name:, target:, guid:, cert:, key:) ⇒ Object

rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/formatron/s3/chef_server_cert.rb', line 13

def self.deploy(
  aws:,
  kms_key:,
  bucket:,
  name:,
  target:,
  guid:,
  cert:,
  key:
)
  cert_key = self.cert_key name: name, target: target, guid: guid
  Formatron::LOG.info do
    "Upload Chef Server SSL certifcate to #{bucket}/#{cert_key}"
  end
  aws.upload_file(
    kms_key: kms_key,
    bucket: bucket,
    key: cert_key,
    content: cert
  )
  key_key = self.key_key name: name, target: target, guid: guid
  Formatron::LOG.info do
    "Upload Chef Server SSL key to #{bucket}/#{key_key}"
  end
  aws.upload_file(
    kms_key: kms_key,
    bucket: bucket,
    key: key_key,
    content: key
  )
end

.destroy(aws:, bucket:, name:, target:, guid:) ⇒ Object

rubocop:disable Metrics/MethodLength



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/formatron/s3/chef_server_cert.rb', line 48

def self.destroy(aws:, bucket:, name:, target:, guid:)
  cert_key = self.cert_key name: name, target: target, guid: guid
  Formatron::LOG.info do
    "Delete Chef Server SSL certificate from #{bucket}/#{cert_key}"
  end
  aws.delete_file(
    bucket: bucket,
    key: cert_key
  )
  key_key = self.key_key name: name, target: target, guid: guid
  Formatron::LOG.info do
    "Delete Chef Server SSL key from #{bucket}/#{key_key}"
  end
  aws.delete_file(
    bucket: bucket,
    key: key_key
  )
end

.key_key(name:, target:, guid:) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/formatron/s3/chef_server_cert.rb', line 76

def self.key_key(name:, target:, guid:)
  Path.key(
    name: name,
    target: target,
    sub_key: "#{guid}/#{KEY_NAME}"
  )
end