-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module StackMaster | ||
module ParameterResolvers | ||
class AcmCertificate < Resolver | ||
CertificateNotFound = Class.new(StandardError) | ||
|
||
def initialize(config, stack_definition) | ||
@config = config | ||
@stack_definition = stack_definition | ||
end | ||
|
||
def resolve(value) | ||
cert_arn = all_certs.map { |c| c.certificate_arn if c.domain_name == value }.compact.first | ||
raise CertificateNotFound, "Could not find certificate #{value} in #{@stack_definition.region}" unless cert_arn | ||
cert_arn | ||
end | ||
|
||
private | ||
|
||
def all_certs | ||
certs = [] | ||
next_token = nil | ||
loop do | ||
resp = Aws::ACM::Client.new(region: @stack_definition.region).list_certificates(next_token: next_token) | ||
certs << resp.certificate_summary_list | ||
next_token = resp.next_token | ||
break if next_token.nil? | ||
end | ||
certs.flatten | ||
end | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
spec/stack_master/parameter_resolvers/acm_certificate_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
RSpec.describe StackMaster::ParameterResolvers::AcmCertificate do | ||
let(:config) { double(base_dir: '/base') } | ||
let(:stack_definition) { double(stack_name: 'mystack', region: 'us-east-1') } | ||
subject(:resolver) { described_class.new(config, stack_definition) } | ||
let(:acm) { Aws::ACM::Client.new } | ||
|
||
before do | ||
allow(Aws::ACM::Client).to receive(:new).and_return(acm) | ||
end | ||
|
||
context 'when a certificate is found' do | ||
before do | ||
acm.stub_responses(:list_certificates, certificate_summary_list: [ | ||
{ certificate_arn: 'arn:aws:acm:us-east-1:12345:certificate/abc', domain_name: 'abc' }, | ||
{ certificate_arn: 'arn:aws:acm:us-east-1:12345:certificate/def', domain_name: 'def' } | ||
]) | ||
end | ||
|
||
it 'returns the certificate' do | ||
expect(resolver.resolve('def')).to eq 'arn:aws:acm:us-east-1:12345:certificate/def' | ||
end | ||
end | ||
|
||
context 'when no certificate is found' do | ||
before do | ||
acm.stub_responses(:list_certificates, certificate_summary_list: []) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { resolver.resolve('def') }.to raise_error( | ||
StackMaster::ParameterResolvers::AcmCertificate::CertificateNotFound, | ||
'Could not find certificate def in us-east-1' | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters