Class: Opsicle::Permit

Inherits:
Object
  • Object
show all
Defined in:
lib/opsicle/commands/permit.rb

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Permit

Returns a new instance of Permit.



3
4
5
# File 'lib/opsicle/commands/permit.rb', line 3

def initialize(environment)
  @client = Client.new(environment)
end

Instance Method Details

#all_stack_idsObject



16
17
18
# File 'lib/opsicle/commands/permit.rb', line 16

def all_stack_ids
  @client.api_call(:describe_stacks)[:stacks].map{ |stack| stack[:stack_id] }
end

#current_stack_idObject



20
21
22
# File 'lib/opsicle/commands/permit.rb', line 20

def current_stack_id
  @client.config.opsworks_config[:stack_id]
end

#execute(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/opsicle/commands/permit.rb', line 7

def execute(options={})
  stack_ids = options[:all_stacks] ? all_stack_ids : [current_stack_id]
  stack_ids.each do |stack_id|
    iam_user_arns(options[:user]).each do |arn|
      set_permission(arn, stack_id)
    end
  end
end

#iam_user_arns(user_names) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/opsicle/commands/permit.rb', line 24

def iam_user_arns(user_names)
  if user_names && !user_names.empty?
    user_names.map do |user_name|
      profile = profiles.detect{ |profile| profile[:name] == user_name || profile[:ssh_username] == user_name}
      raise ArgumentError, "User #{user_name} not found" unless profile
      profile[:iam_user_arn]
    end
  else
    [UserProfile.new(@client).arn]
  end
end