class Awspec::Generator::Spec::S3Bucket
Public Instance Methods
bucket_spec_template()
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 36 def bucket_spec_template template = <<-'EOF' describe s3_bucket('<%= bucket.name %>') do it { should exist } <%- if acl -%> its(:acl_owner) { should eq '<%= acl.owner.display_name %>' } its(:acl_grants_count) { should eq <%= acl.grants.count %> } <%- end -%> <% grant_specs.each do |line| %> <%= line %> <% end %> <%- if bucket_policy -%> it { should have_policy('<%= bucket_policy %>') } <%- end -%> <%- if tag -%> it { should have_tag('env').value('dev') } <%- end -%> end EOF template end
generate(bucket_name)
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 14 def generate(bucket_name) bucket = find_bucket(bucket_name) content(bucket) end
generate_all()
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 5 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
generate_grant_specs(acl)
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 19 def generate_grant_specs(acl) return [] unless acl linespecs = [] acl.grants.each do |grant| linespecs.push(ERB.new(grant_linetemplate, nil, '-').result(binding)) end linespecs end
grant_linetemplate()
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 28 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
Private Instance Methods
content(bucket)
click to toggle source
# File lib/awspec/generator/spec/s3_bucket.rb, line 60 def content(bucket) acl = find_bucket_acl(bucket.name) grant_specs = generate_grant_specs(acl) tag = find_bucket_tag(bucket.name, 'env') policy = find_bucket_policy(bucket.name) bucket_policy = policy.policy.read if policy ERB.new(bucket_spec_template, nil, '-').result(binding).gsub(/^\n/, '') end