Sha256: dac31fd0252e64a969bd0ea5ed74f991e3a304b1b5808fd121d93c96c047c42a

Contents?: true

Size: 965 Bytes

Versions: 44

Compression:

Stored size: 965 Bytes

Contents

module Awspec::Generator
  module Spec
    class Kms
      include Awspec::Helper::Finder
      def generate_all
        aliases = select_all_kms_aliases.select { |kms_alias| customer_managed_key?(kms_alias) }
        raise 'Not Found alias' if aliases.empty?
        ERB.new(keys_spec_template, nil, '-').result(binding).chomp
      end

      def keys_spec_template
        template = <<-'EOF'
<% aliases.each do |kms_alias| %>
describe kms('<%= kms_alias.alias_name.split('/').last %>') do
  it { should exist }
<% if find_kms_key(kms_alias.target_key_id).enabled -%>
  it { should be_enabled }
<% end -%>
end
<% end %>
EOF
        template
      end

      private

      def customer_managed_key?(kms_alias)
        # An aliase that has no target key id field is predefined by AWS.
        # see: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/KMS/Client.html#list_aliases-instance_method
        !kms_alias.target_key_id.nil?
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 3 rubygems

Version Path
cthiesfork-awspec-1.2.2 lib/awspec/generator/spec/kms.rb
cthiesfork-awspec-1.2.1 lib/awspec/generator/spec/kms.rb
awspec-1.18.5 lib/awspec/generator/spec/kms.rb
cthiesfork-awspec-1.2.0 lib/awspec/generator/spec/kms.rb
cthiesfork-awspec-1.1.0 lib/awspec/generator/spec/kms.rb
cthiesfork-awspec-1.0.0 lib/awspec/generator/spec/kms.rb
awspec-1.18.4 lib/awspec/generator/spec/kms.rb
awspec-1.18.3 lib/awspec/generator/spec/kms.rb
awspec-1.18.2 lib/awspec/generator/spec/kms.rb
awspec-1.18.1 lib/awspec/generator/spec/kms.rb
awspec-1.18.0 lib/awspec/generator/spec/kms.rb
awspec-1.17.4 lib/awspec/generator/spec/kms.rb
awspec-1.17.3 lib/awspec/generator/spec/kms.rb
awspec-1.17.2 lib/awspec/generator/spec/kms.rb
awspec-1.17.1 lib/awspec/generator/spec/kms.rb
awspec-1.17.0 lib/awspec/generator/spec/kms.rb
awspec-1.16.1 lib/awspec/generator/spec/kms.rb
awspec-1.16.0 lib/awspec/generator/spec/kms.rb
awspec-1.15.3 lib/awspec/generator/spec/kms.rb
awspec-1.15.2 lib/awspec/generator/spec/kms.rb