Module: Brightbox::Config::Accounts
- Included in:
- BBConfig
- Defined in:
- lib/brightbox-cli/config/accounts.rb
Instance Method Summary collapse
- #account ⇒ Object
- #default_account ⇒ Object
- #determine_account(preferred_account) ⇒ Object
-
#find_or_set_default_account ⇒ Object
If a client does not have a default account, this will attempt to set it if there is one.
- #save_default_account(account_id) ⇒ Object
Instance Method Details
#account ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/brightbox-cli/config/accounts.rb', line 22 def account if defined?(@account) && @account @account else default_account end end |
#default_account ⇒ Object
10 11 12 13 14 15 |
# File 'lib/brightbox-cli/config/accounts.rb', line 10 def default_account return unless selected_config configured_default_account = selected_config["default_account"] return configured_default_account if configured_default_account && !configured_default_account.empty? end |
#determine_account(preferred_account) ⇒ Object
17 18 19 20 |
# File 'lib/brightbox-cli/config/accounts.rb', line 17 def determine_account(preferred_account) return preferred_account if preferred_account return config[client_name]["default_account"] unless client_name.nil? end |
#find_or_set_default_account ⇒ Object
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 find_or_set_default_account # FIXME: API clients are scoped to their account so this code should # never need to run for them. return if default_account begin service = Fog::Compute.new(to_fog) accounts = service.accounts @account = accounts.select { |acc| %w[pending active].include?(acc.status) }.first.id save_default_account(@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 save_default_account(account_id) dirty! unless account_id == selected_config["default_account"] selected_config["default_account"] = account_id end |