Class: Acmesmith::PostIssuingHooks::Acm
- Defined in:
- lib/acmesmith/post_issuing_hooks/acm.rb
Instance Attribute Summary collapse
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Attributes inherited from Base
Instance Method Summary collapse
- #acm ⇒ Object
- #certificate_arn ⇒ Object
- #execute ⇒ Object
- #find_certificate_arn ⇒ Object
-
#initialize(certificate_arn: nil, region:) ⇒ Acm
constructor
A new instance of Acm.
Methods inherited from Base
Constructor Details
#initialize(certificate_arn: nil, region:) ⇒ Acm
Returns a new instance of Acm.
7 8 9 10 11 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 7 def initialize(certificate_arn: nil, region:) @certificate_arn = certificate_arn @certificate_arn_set = true if @certificate_arn @region = region end |
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
13 14 15 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 13 def region @region end |
Instance Method Details
#acm ⇒ Object
35 36 37 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 35 def acm @acm ||= Aws::ACM::Client.new(region: region) end |
#certificate_arn ⇒ Object
15 16 17 18 19 20 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 15 def certificate_arn return @certificate_arn if @certificate_arn_set @certificate_arn ||= find_certificate_arn @certificate_arn_set = true @certificate_arn end |
#execute ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 39 def execute puts "=> Importing certificate CN=#{common_name} into AWS ACM (region=#{region})" if certificate_arn puts " * updating ARN: #{certificate_arn}" else puts " * Importing as as new certificate" end resp = acm.import_certificate( { certificate: certificate.certificate.to_pem, private_key: certificate.private_key.to_pem, certificate_chain: certificate.issuer_pems, }.merge(certificate_arn ? {certificate_arn: certificate_arn} : {}) ) unless certificate_arn puts " * ARN: #{resp.certificate_arn}" end acm.( certificate_arn: resp.certificate_arn, tags: [key: 'Acmesmith', value: '1'], ) end |
#find_certificate_arn ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/acmesmith/post_issuing_hooks/acm.rb', line 22 def find_certificate_arn acm.list_certificates().each do |page| page.certificate_summary_list.each do |summary| if summary.domain_name == common_name = acm.(certificate_arn: summary.certificate_arn). if .find{ |_| _.key == 'Acmesmith' } return summary.certificate_arn end end end end end |