Class: Subiam::Client

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper
Defined in:
lib/subiam/client.rb

Instance Method Summary collapse

Methods included from Logger::Helper

#log

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



4
5
6
7
8
9
10
11
12
# File 'lib/subiam/client.rb', line 4

def initialize(options = {})
  @options = {:format => :ruby}.merge(options)
  aws_config = options[:aws_config] || {}
  @iam = Aws::IAM::Client.new(aws_config)
  @sts = Aws::STS::Client.new(aws_config)
  @driver = Subiam::Driver.new(@iam, @sts, options)
  @password_manager = options[:password_manager] || Subiam::PasswordManager.new('-', options)
  @target = nil
end

Instance Method Details

#apply(file) ⇒ Object



54
55
56
# File 'lib/subiam/client.rb', line 54

def apply(file)
  walk(file)
end

#export(export_options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/subiam/client.rb', line 14

def export(export_options = {})
  exported, group_users, instance_profile_roles = Subiam::Exporter.export(@iam, @options)
  exported.sort_array!

  if block_given?
    [:users, :groups, :roles, :instance_profiles, :policies].each do |type|
      splitted = {:users => {}, :groups => {}, :roles => {}, :instance_profiles => {}, :policies => {}}

      if export_options[:split_more]
        exported[type].sort_by {|k, v| k }.each do |name, attrs|
          more_splitted = splitted.dup
          more_splitted[type] = {}
          more_splitted[type][name] = attrs

          dsl = exec_by_format(
            :ruby => proc { Subiam::DSL.convert(more_splitted, @options).strip },
            :json => proc { JSON.pretty_generate(more_splitted) }
          )

          yield(:type => type, :name => name, :dsl => dsl)
        end
      else
        splitted[type] = exported[type]

        dsl = exec_by_format(
          :ruby => proc { Subiam::DSL.convert(splitted, @options).strip },
          :json => proc { JSON.pretty_generate(splitted) }
        )

        yield(:type => type, :dsl => dsl)
      end
    end
  else
    dsl = exec_by_format(
      :ruby => proc { Subiam::DSL.convert(exported, @options).strip },
      :json => proc { JSON.pretty_generate(exported) }
    )
  end
end