Sha256: 10f4c7120fa02a29796d379ac05978105ccc093dcfff6ca164466db5dcffef11

Contents?: true

Size: 1.47 KB

Versions: 45

Compression:

Stored size: 1.47 KB

Contents

module Awspec::Generator
  module Spec
    class S3Bucket
      include Awspec::Helper::Finder
      def generate_all
        buckets = select_all_buckets
        raise 'Not Found Bucket' if buckets.empty?
        specs = buckets.map do |bucket|
          content(bucket)
        end
        specs.join("\n")
      end

      def generate(bucket_name)
        bucket = find_bucket(bucket_name)
        content(bucket)
      end

      def generate_grant_specs(acl)
        linespecs = []
        acl.grants.each do |grant|
          linespecs.push(ERB.new(grant_linetemplate, nil, '-').result(binding))
        end
        linespecs
      end

      def grant_linetemplate
        grantee = 'grant.grantee.display_name || grant.grantee.uri || grant.grantee.id'
        template = <<-EOF
it { should have_acl_grant(grantee: '<%= #{grantee} %>', permission: '<%= grant.permission %>') }
        EOF
        template
      end

      def bucket_spec_template
        template = <<-'EOF'
describe s3_bucket('<%= bucket.name %>') do
  it { should exist }
  its(:acl_owner) { should eq '<%= acl.owner.display_name %>' }
  its(:acl_grants_count) { should eq <%= acl.grants.count %> }
<% grant_specs.each do |line| %>
  <%= line %>
<% end %>
end
EOF
        template
      end

      private

      def content(bucket)
        acl = find_bucket_acl(bucket.name)
        grant_specs = generate_grant_specs(acl)
        ERB.new(bucket_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
awspec-0.46.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.45.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.44.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.43.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.42.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.41.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.40.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.39.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.38.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.8 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.7 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.6 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.5 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.4 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.3 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.2 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.1 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.37.0 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.36.1 lib/awspec/generator/spec/s3_bucket.rb
awspec-0.36.0 lib/awspec/generator/spec/s3_bucket.rb