Sha256: 62302d6832fd82e7d2a7919aa2198dd4f87acea5731e180ed5bb35f49abdd6a5

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

module Cody::Dsl
  module Role
    PROPERTIES = %w[
      assume_role_policy_document
      managed_policy_arns
      max_session_duration
      path
      permissions_boundary
      policies
      role_name
    ]
    PROPERTIES.each do |prop|
      define_method(prop) do |v|
        @properties[prop.to_sym] = v
      end
    end

    # convenience wrapper methods
    def iam_policy(*definitions)
      @iam_statements = definitions.map { |definition| standardize_iam_policy(definition) }
    end

    # Returns standarized IAM statement
    def standardize_iam_policy(definition)
      case definition
      when String
        # Expands simple string from: logs => logs:*
        definition = "#{definition}:*" unless definition.include?(':')
        {
          action: [definition],
          effect: "Allow",
          resource: "*",
        }
      when Hash
        definition
      end
    end

    def managed_iam_policy(*definitions)
      @managed_policy_arns = definitions.map { |definition| standardize_managed_iam_policy(definition) }
    end

    # AmazonEC2ReadOnlyAccess => arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
    def standardize_managed_iam_policy(definition)
      return definition if definition.include?('iam::aws:policy')

      "arn:aws:iam::aws:policy/#{definition}"
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
cody-0.9.8 lib/cody/dsl/role.rb
cody-0.9.7 lib/cody/dsl/role.rb
cody-0.9.6 lib/cody/dsl/role.rb
cody-0.9.5 lib/cody/dsl/role.rb
cody-0.9.4 lib/cody/dsl/role.rb
cody-0.9.3 lib/cody/dsl/role.rb
cody-0.9.2 lib/cody/dsl/role.rb
cody-0.9.1 lib/cody/dsl/role.rb
cody-0.9.0 lib/cody/dsl/role.rb
cody-0.8.6 lib/cody/dsl/role.rb
cody-0.8.5 lib/cody/dsl/role.rb
cody-0.8.4 lib/cody/dsl/role.rb
cody-0.8.3 lib/cody/dsl/role.rb
cody-0.8.2 lib/cody/dsl/role.rb
cody-0.8.1 lib/cody/dsl/role.rb
cody-0.8.0 lib/cody/dsl/role.rb
cody-0.7.3 lib/cody/dsl/role.rb
cody-0.7.2 lib/cody/dsl/role.rb
cody-0.7.1 lib/cody/dsl/role.rb
cody-0.7.0 lib/cody/dsl/role.rb