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
awspec-1.25.1 lib/awspec/generator/spec/kms.rb
awspec-1.25.0 lib/awspec/generator/spec/kms.rb
awspec-1.24.4 lib/awspec/generator/spec/kms.rb
awspec-1.24.3 lib/awspec/generator/spec/kms.rb
awspec-1.24.2 lib/awspec/generator/spec/kms.rb
awspec-1.24.1 lib/awspec/generator/spec/kms.rb
awspec-1.24.0 lib/awspec/generator/spec/kms.rb
awspec-1.23.0 lib/awspec/generator/spec/kms.rb
awspec-1.22.1 lib/awspec/generator/spec/kms.rb
awspec-1.22.0 lib/awspec/generator/spec/kms.rb
awspec-1.21.1 lib/awspec/generator/spec/kms.rb
awspec-1.21.0 lib/awspec/generator/spec/kms.rb
awspec-1.20.0 lib/awspec/generator/spec/kms.rb
awspec-1.19.2 lib/awspec/generator/spec/kms.rb
awspec-1.19.1 lib/awspec/generator/spec/kms.rb
awspec-1.19.0 lib/awspec/generator/spec/kms.rb
cthiesfork-awspec-1.2.4 lib/awspec/generator/spec/kms.rb
awspec-api_gateway_extended-1.2.4 lib/awspec/generator/spec/kms.rb
awspec-api_gateway_extended-1.2.3 lib/awspec/generator/spec/kms.rb
awspec-1.18.6 lib/awspec/generator/spec/kms.rb