Sha256: a21a814e724c865cd7dcb08d69573fb8a749e49b721ceccf81a50ec9b155b787

Contents?: true

Size: 1.09 KB

Versions: 217

Compression:

Stored size: 1.09 KB

Contents

module Jets::Resource::Iam
  class PolicyDocument
    extend Memoist

    attr_reader :definitions
    def initialize(*definitions)
      @definitions = definitions.flatten
      # empty starting policy that will be altered
      @policy = {
        version: "2012-10-17",
        statement: []
      }
    end

    def policy_document
      definitions.map { |definition| standardize(definition) }
      Jets::Camelizer.transform(@policy)
    end
    memoize :policy_document # only process policy_document once

    def standardize(definition)
      case definition
      when String
        # Expands simple string from: logs => logs:*
        definition = "#{definition}:*" unless definition.include?(':')
        @policy[:statement] << {
          action: [definition],
          effect: "Allow",
          resource: "*",
        }
      when Hash
        definition = definition.stringify_keys
        if definition.key?("Version") # special case where we replace the policy entirely
          @policy = definition
        else
          @policy[:statement] << definition
        end
      end
    end
  end
end

Version data entries

217 entries across 217 versions & 4 rubygems

Version Path
jets-4.0.12 lib/jets/resource/iam/policy_document.rb
jets-4.0.11 lib/jets/resource/iam/policy_document.rb
jets-4.0.10 lib/jets/resource/iam/policy_document.rb
jets-4.0.9 lib/jets/resource/iam/policy_document.rb
jets-4.0.8 lib/jets/resource/iam/policy_document.rb
jets-4.0.7 lib/jets/resource/iam/policy_document.rb
jets-4.0.6 lib/jets/resource/iam/policy_document.rb
jets-4.0.5 lib/jets/resource/iam/policy_document.rb
jets-4.0.4 lib/jets/resource/iam/policy_document.rb
jets-4.0.3 lib/jets/resource/iam/policy_document.rb
jets-4.0.2 lib/jets/resource/iam/policy_document.rb
jets-4.0.1 lib/jets/resource/iam/policy_document.rb
jets-4.0.0 lib/jets/resource/iam/policy_document.rb
jets-3.2.2 lib/jets/resource/iam/policy_document.rb
jets-3.2.1 lib/jets/resource/iam/policy_document.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/resource/iam/policy_document.rb
jets-3.2.0 lib/jets/resource/iam/policy_document.rb
jets-3.1.5 lib/jets/resource/iam/policy_document.rb
jets-3.1.4 lib/jets/resource/iam/policy_document.rb
jets-3.1.3 lib/jets/resource/iam/policy_document.rb