Module: Brightbox::Config::Accounts

Included in:
BBConfig
Defined in:
lib/brightbox-cli/config/accounts.rb

Instance Method Summary collapse

Instance Method Details

#accountObject



22
23
24
25
26
27
28
# File 'lib/brightbox-cli/config/accounts.rb', line 22

def 
  if defined?(@account) && @account
    @account
  else
    
  end
end

#default_accountObject



10
11
12
13
14
15
# File 'lib/brightbox-cli/config/accounts.rb', line 10

def 
  return unless selected_config

   = selected_config["default_account"]
  return  if  && !.empty?
end

#determine_account(preferred_account) ⇒ Object



17
18
19
20
# File 'lib/brightbox-cli/config/accounts.rb', line 17

def ()
  return  if 
  return config[client_name]["default_account"] unless client_name.nil?
end

#find_or_set_default_accountObject

Note:

This queries the API whenever a default is not set so creates excess traffic for certain use cases on all commands.

If a client does not have a default account, this will attempt to set it if there is one.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/brightbox-cli/config/accounts.rb', line 36

def 
  # FIXME: API clients are scoped to their account so this code should
  #   never need to run for them.
  return if 

  begin
    service = Fog::Compute.new(to_fog)
    accounts = service.accounts

    @account = accounts.select { |acc| %w[pending active].include?(acc.status) }.first.id
    (@account) if @account
  rescue Brightbox::BBConfigError
    # We can't get a suitable fog connection so we can't select an
    # account
  rescue Excon::Errors::Unauthorized
    # This is a helper, if it fails let the other code warn and prompt
  end
end

#save_default_account(account_id) ⇒ Object



4
5
6
7
8
# File 'lib/brightbox-cli/config/accounts.rb', line 4

def ()
  dirty! unless  == selected_config["default_account"]

  selected_config["default_account"] = 
end