Sha256: 07db91f3f8ad0803477364f876e240fd8a6a2336f30155a121b4723bd2e17a30

Contents?: true

Size: 1.54 KB

Versions: 23

Compression:

Stored size: 1.54 KB

Contents

class Miam::DSL::Context::Role
  include Miam::TemplateHelper

  def initialize(context, name, &block)
    @role_name = name
    @context = context.merge(:role_name => name)
    @result = {:instance_profiles => [], :policies => {}, :attached_managed_policies => []}
    instance_eval(&block)
  end

  def result
    unless @result[:assume_role_policy_document]
      raise "Role `#{@role_name}`: AssumeRolePolicyDocument is not defined"
    end

    @result
  end

  private

  def instance_profiles(*profiles)
    @result[:instance_profiles].concat(profiles.map(&:to_s))
  end

  def assume_role_policy_document
    if @result[:assume_role_policy_document]
      raise "Role `#{@role_name}` > AssumeRolePolicyDocument: already defined"
    end

    assume_role_policy_document = yield

    unless assume_role_policy_document.kind_of?(Hash)
      raise "Role `#{@role_name}` > AssumeRolePolicyDocument: wrong argument type #{policy_document.class} (expected Hash)"
    end

    @result[:assume_role_policy_document] = assume_role_policy_document
  end

  def policy(name)
    name = name.to_s

    if @result[:policies][name]
      raise "Role `#{@role_name}` > Policy `#{name}`: already defined"
    end

    policy_document = yield

    unless policy_document.kind_of?(Hash)
      raise "Role `#{@role_name}` > Policy `#{name}`: wrong argument type #{policy_document.class} (expected Hash)"
    end

    @result[:policies][name] = policy_document
  end

  def attached_managed_policies(*policies)
    @result[:attached_managed_policies].concat(policies.map(&:to_s))
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
miam-0.2.4.beta15 lib/miam/dsl/context/role.rb
miam-0.2.4.beta14 lib/miam/dsl/context/role.rb
miam-0.2.4.beta13 lib/miam/dsl/context/role.rb
miam-0.2.4.beta12 lib/miam/dsl/context/role.rb
miam-0.2.4.beta11 lib/miam/dsl/context/role.rb
miam-0.2.4.beta10 lib/miam/dsl/context/role.rb
miam-0.2.4.beta9 lib/miam/dsl/context/role.rb
miam-0.2.4.beta8 lib/miam/dsl/context/role.rb
miam-0.2.4.beta7 lib/miam/dsl/context/role.rb
miam-0.2.4.beta6 lib/miam/dsl/context/role.rb
miam-0.2.4.beta5 lib/miam/dsl/context/role.rb
miam-0.2.4.beta4 lib/miam/dsl/context/role.rb
miam-0.2.4.beta3 lib/miam/dsl/context/role.rb
miam-0.2.4.beta2 lib/miam/dsl/context/role.rb
miam-0.2.4.beta lib/miam/dsl/context/role.rb
miam-0.2.3 lib/miam/dsl/context/role.rb
miam-0.2.3.beta3 lib/miam/dsl/context/role.rb
miam-0.2.3.beta2 lib/miam/dsl/context/role.rb
miam-0.2.3.beta lib/miam/dsl/context/role.rb
miam-0.2.2 lib/miam/dsl/context/role.rb