Sha256: decfa0a0912ac1c049158c6bb7535decbb729a17db35ea97900496ee7aaa7bea

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

class S3Secure::Policy
  class Document
    extend Memoist

    delegate :has?, to: :checker

    def initialize(bucket, bucket_policy, remove: false)
      @bucket, @bucket_policy, @remove = bucket, bucket_policy, remove # existing document policy
    end

    # Returns JSON text
    # Currently only support adding ForceSSLOnlyAccess document policy.
    def policy_document(sid, remove: false)
      enforcer_class = "S3Secure::Policy::Document::#{sid}"
      enforcer_class += "Remove" if @remove
      enforcer_class = enforcer_class.constantize # IE: ForceSSLOnlyAccess or ForceSSLOnlyAccessRemove
      enforcer = enforcer_class.new(@bucket, @bucket_policy)
      policy = enforcer.policy_document
      JSON.pretty_generate(policy) if policy
    end

    def checker
      Checker.new(@bucket_policy)
    end
    memoize :checker
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
s3-secure-0.2.0 lib/s3_secure/policy/document.rb
s3-secure-0.1.0 lib/s3_secure/policy/document.rb