Class: RsUserPolicy::RightApi::MultiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rs_user_policy/right_api/multi_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, accounts) ⇒ MultiClient

Creates RightApi::Client instances for each account ID supplied. If any supplied account ID is an enterprise master account, the child accounts are found and added to this MultiClient as well.

Parameters:

  • email (String)

    Email address of a RightScale user with permissions to access the API

  • password (String)

    Password of a RightScale user with permissions to access the API

  • accounts (Array<Integer>)

    List of accounts for which to create RightApi::Client objects



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 35

def initialize(email, password, accounts)
  @accounts ||= {}
  accounts.each do ||
    client = ::RightApi::Client.new(
      :email => email,
      :password => password,
      :account_id => 
    )
     = {
      :client => client,
      :has_children => false,
      :resource => client.accounts(:id => ).show()
    }
    begin
      child_accounts = client.child_accounts.index
      [:has_children] = true
      # NOTE: Assuming that children can not have grand children
      child_accounts.each do ||
        # TODO: Looser coupling to the Utilities class here?
         = RsUserPolicy::Utilities.id_from_href(.href).to_i
         = ::RightApi::Client.new(
          :email => email,
          :password => password,
          :account_id => 
        )
        @accounts[] = {
          :client => ,
          :has_children => false,
          :parent => ,
          :resource => 
        }
      end
    rescue ::RightApi::ApiError => e
      raise e unless e.message =~ /enterprise/ || e.message =~ /Permission denied/
    end
    @accounts[] = 
  end
end

Instance Attribute Details

#accountsObject

Returns the value of attribute accounts.



26
27
28
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 26

def accounts
  @accounts
end

Instance Method Details

#[](account_id) ⇒ Object



82
83
84
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 82

def []()
  @accounts[]
end

#each(&block) ⇒ Object



86
87
88
89
90
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 86

def each(&block)
  @accounts.each do |,|
    yield , 
  end
end

#lengthObject



74
75
76
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 74

def length
  @accounts.length
end

#sizeObject



78
79
80
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 78

def size
  length
end