Class: CfnVpn::Acm

Inherits:
Object
  • Object
show all
Defined in:
lib/cfnvpn/acm.rb

Instance Method Summary collapse

Constructor Details

#initialize(region, cert_dir) ⇒ Acm

Returns a new instance of Acm.



7
8
9
10
# File 'lib/cfnvpn/acm.rb', line 7

def initialize(region,cert_dir)
  @client = Aws::ACM::Client.new(region: region)
  @cert_dir = cert_dir
end

Instance Method Details

#get_certificate_tags(certificate_arn, key = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cfnvpn/acm.rb', line 42

def get_certificate_tags(certificate_arn,key=nil)
  resp = @client.list_tags_for_certificate({
    certificate_arn: certificate_arn
  })

  if key.nil?
    return resp.tags
  else
    resp.tags.each do |tag|
      return tag.value if tag.key == key
    end

    raise "no tag key #{key} matched the certificate #{certificate_arn}"
  end
end

#import_certificate(cert, key, ca) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cfnvpn/acm.rb', line 12

def import_certificate(cert,key,ca)
  cert_body = load_certificate(cert)
  key_body = load_certificate(key)
  ca_body = load_certificate(ca)

  resp = @client.import_certificate({
    certificate: cert_body,
    private_key: key_body,
    certificate_chain: ca_body
  })
  return resp.certificate_arn
end

#load_certificate(cert) ⇒ Object



38
39
40
# File 'lib/cfnvpn/acm.rb', line 38

def load_certificate(cert)
  File.read("#{@cert_dir}/#{cert}")
end

#tag_certificate(arn, name, type, cfnvpn_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cfnvpn/acm.rb', line 25

def tag_certificate(arn,name,type,cfnvpn_name)
  tags = [
    { key: "Name", value: name },
    { key: "cfnvpn:name", value: cfnvpn_name },
    { key: "cfnvpn:certificate:type", value: type }
  ]

  @client.add_tags_to_certificate({
    certificate_arn: arn,
    tags: tags
  })
end