Sha256: cd2fd4300d366a0e258162f50784ee7de3e8842af0f29129ee5e5b08e8d713e4

Contents?: true

Size: 969 Bytes

Versions: 12

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

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
        <<-'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
      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

12 entries across 12 versions & 1 rubygems

Version Path
awspec-1.30.0 lib/awspec/generator/spec/kms.rb
awspec-1.29.3 lib/awspec/generator/spec/kms.rb
awspec-1.29.2 lib/awspec/generator/spec/kms.rb
awspec-1.29.1 lib/awspec/generator/spec/kms.rb
awspec-1.29.0 lib/awspec/generator/spec/kms.rb
awspec-1.28.2 lib/awspec/generator/spec/kms.rb
awspec-1.28.1 lib/awspec/generator/spec/kms.rb
awspec-1.28.0 lib/awspec/generator/spec/kms.rb
awspec-1.27.1 lib/awspec/generator/spec/kms.rb
awspec-1.27.0 lib/awspec/generator/spec/kms.rb
awspec-1.26.0 lib/awspec/generator/spec/kms.rb
awspec-1.25.2 lib/awspec/generator/spec/kms.rb