Sha256: 43bd7cfb7a5ee130d3ef9e141ac185ebbe0deea4fddcc1763b445b740f047122

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Awspec::Generator
  module Spec
    class IamGroup
      include Awspec::Helper::Finder
      def generate_all
        groups = select_all_iam_groups
        raise 'Not Found IAM Group' if groups.empty?

        specs = groups.map do |group|
          inline_policies = select_inline_policy_by_group_name(group.group_name).map do |policy_name|
            res = iam_client.get_group_policy({
                                                group_name: group.group_name,
                                                policy_name: policy_name
                                              })
            document = JSON.generate(JSON.parse(URI.decode_www_form_component(res.policy_document)))
            "it { should have_inline_policy('#{policy_name}').policy_document('#{document}') }"
          end
          content = ERB.new(iam_group_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
        end
        specs.join("\n")
      end

      def iam_group_spec_template
        <<-'EOF'
describe iam_group('<%= group.group_name %>') do
  it { should exist }
  its(:arn) { should eq '<%= group.arn %>' }
  its(:create_date) { should eq Time.parse('<%= group.create_date %>') }
<% select_iam_policy_by_group_name(group.group_name).each do |policy| %>  it { should have_iam_policy('<%= policy.policy_name %>') }
<% end %>
<%- inline_policies.each do |line| -%>
  <%= line %>
<%- end -%>
end
EOF
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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