Sha256: 2f57c811d1d3da81eecd6bd5a95b95ba391984bf85a0908c5bfa70cfb40a2529

Contents?: true

Size: 691 Bytes

Versions: 6

Compression:

Stored size: 691 Bytes

Contents

class S3Secure::Policy
  class List < Base
    def run
      buckets.each do |bucket|
        @s3 = s3_regional_client(bucket)
        puts "Policy for bucket #{bucket.color(:green)}"
        policy = get_policy(bucket)

        if policy
          puts policy
        else
          puts "Bucket does not have a bucket policy"
        end
      end
    end

    def get_policy(bucket)
      resp = @s3.get_bucket_policy(bucket: bucket)
      data = JSON.load(resp.policy.read) # String
      JSON.pretty_generate(data)
    rescue Aws::S3::Errors::NoSuchBucketPolicy
    end

    # Useful when calling List outside of the list CLI
    def set_s3(client)
      @s3 = client
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
s3-secure-0.4.2 lib/s3_secure/policy/list.rb
s3-secure-0.4.1 lib/s3_secure/policy/list.rb
s3-secure-0.4.0 lib/s3_secure/policy/list.rb
s3-secure-0.3.0 lib/s3_secure/policy/list.rb
s3-secure-0.2.0 lib/s3_secure/policy/list.rb
s3-secure-0.1.0 lib/s3_secure/policy/list.rb