Sha256: 9de5d1cb39e76d35d094c271702e1f0649db2ac1ba4aa1b5078321394352265a

Contents?: true

Size: 1.57 KB

Versions: 181

Compression:

Stored size: 1.57 KB

Contents

module Awspec::Generator
  module Spec
    class IamPolicy
      include Awspec::Helper::Finder
      def generate_all
        policies = select_all_attached_policies
        raise 'Not Found policy' if policies.empty?
        ERB.new(policy_spec_template, nil, '-').result(binding).chomp
      end

      # rubocop:disable all
      def policy_spec_template
        template = <<-'EOF'
<% policies.each do |policy| %>
describe iam_policy('<%= policy.policy_name %>') do
  it { should exist }
<%- if policy.is_attachable -%>
  it { should be_attachable }
<%- else -%>
  it { should_not be_attachable }
<%- end -%>
  its(:arn) { should eq '<%= policy.arn %>' }
  its(:update_date) { should eq Time.parse('<%= policy.update_date %>') }
  its(:attachment_count) { should eq <%= policy.attachment_count %> }
<%- users = select_attached_users(policy.arn) -%>
<%- if users.empty? -%>
  it { should_not be_attached_to_user }
<%- else -%>
<%- users.each do |user| -%>
  it { should     be_attached_to_user('<%= user.user_name %>') }
<%- end -%>
<%- end -%>
<%- groups = select_attached_groups(policy.arn) -%>
<%- if groups.empty? -%>
  it { should_not be_attached_to_group }
<%- else -%>
<%- groups.each do |group| -%>
  it { should     be_attached_to_group('<%= group.group_name %>') }
<%- end -%>
<%- end -%>
<%- roles = select_attached_roles(policy.arn) -%>
<%- if roles.empty? -%>
  it { should_not be_attached_to_role }
<%- else -%>
<%- roles.each do |role| -%>
  it { should     be_attached_to_role('<%= role.role_name %>') }
<%- end -%>
<%- end -%>
end
<% end %>
EOF
        template
      end
    end
  end
end

Version data entries

181 entries across 181 versions & 4 rubygems

Version Path
awspec-0.79.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.79.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.78.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.77.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.77.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.76.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.76.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.75.2 lib/awspec/generator/spec/iam_policy.rb
awspec-0.75.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.75.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.74.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.74.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.73.2 lib/awspec/generator/spec/iam_policy.rb
awspec-0.73.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.73.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.72.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.71.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.70.0 lib/awspec/generator/spec/iam_policy.rb
awspec-0.69.1 lib/awspec/generator/spec/iam_policy.rb
awspec-0.69.0 lib/awspec/generator/spec/iam_policy.rb