class Subiam::DSL::Context

Attributes

result[R]

Public Class Methods

eval(dsl, path, options = {}) click to toggle source
# File lib/subiam/dsl/context.rb, line 4
def self.eval(dsl, path, options = {})
  self.new(path, options) {
    eval(dsl, binding, path)
  }
end
new(path, options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 12
def initialize(path, options = {}, &block)
  @path = path
  @options = options
  @result = {:users => {}, :groups => {}, :roles => {}, :instance_profiles => {}, :policies => {}, :target => nil}

  @context = Hashie::Mash.new(
    :path => path,
    :options => options,
    :templates => {}
  )

  instance_eval(&block)
end

Public Instance Methods

template(name, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 26
def template(name, &block)
  @context.templates[name.to_s] = block
end

Private Instance Methods

group(name, group_options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 59
def group(name, group_options = {}, &block)
  name = name.to_s

  if @result[:groups][name]
    raise "Group `#{name}` is already defined"
  end

  attrs = Subiam::DSL::Context::Group.new(@context, name, &block).result
  @result[:groups][name] = group_options.merge(attrs)
end
import(file) click to toggle source
# File lib/subiam/dsl/context.rb, line 32
def import(file)
  iamfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

  if File.exist?(iamfile)
    instance_eval(File.read(iamfile), iamfile)
  elsif File.exist?(iamfile + '.rb')
    instance_eval(File.read(iamfile + '.rb'), iamfile + '.rb')
  else
    raise("File: #{iamfile} or #{iamfile + '.rb'} not found.")
  end
end
instance_profile(name, instance_profile_options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 81
def instance_profile(name, instance_profile_options = {}, &block)
  name = name.to_s

  if @result[:instance_profiles][name]
    raise "instance_profile `#{name}` is already defined"
  end

  @result[:instance_profiles][name] = instance_profile_options
end
managed_policy(name, policy_options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 91
def managed_policy(name, policy_options = {}, &block)
  name = name.to_s

  if @result[:policies][name]
    raise "ManagedPolicy `#{name}` is already defined"
  end

  attrs = Subiam::DSL::Context::ManagedPolicy.new(@context, name, &block).result
  @result[:policies][name] = policy_options.merge(attrs)
end
role(name, role_options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 70
def role(name, role_options = {}, &block)
  name = name.to_s

  if @result[:roles][name]
    raise "Role `#{name}` is already defined"
  end

  attrs = Subiam::DSL::Context::Role.new(@context, name, &block).result
  @result[:roles][name] = role_options.merge(attrs)
end
target(regexp) click to toggle source
# File lib/subiam/dsl/context.rb, line 44
def target(regexp)
  @result[:target] = regexp
end
user(name, user_options = {}, &block) click to toggle source
# File lib/subiam/dsl/context.rb, line 48
def user(name, user_options = {}, &block)
  name = name.to_s

  if @result[:users][name]
    raise "User `#{name}` is already defined"
  end

  attrs = Subiam::DSL::Context::User.new(@context, name, &block).result
  @result[:users][name] = user_options.merge(attrs)
end