Sha256: f61b29d3360c2722bc5c5f131fa2ac1b2d15d4d62fb31cb3eeb879fb5722c00d
Contents?: true
Size: 1.9 KB
Versions: 28
Compression:
Stored size: 1.9 KB
Contents
module Brightbox module Config module Accounts def save_default_account(account_id) dirty! unless account_id == selected_config["default_account"] selected_config['default_account'] = account_id end # # # def default_account if selected_config configured_default_account = selected_config["default_account"] if configured_default_account && !configured_default_account.empty? configured_default_account else nil end else nil end end def determine_account(preferred_account) return preferred_account if preferred_account return config[client_name]["default_account"] unless client_name.nil? end def account if defined?(@account) && @account @account else default_account end end # If a client does not have a default account, this will attempt to set it # if there is one. # # @note This queries the API whenever a default is not set so creates # excess traffic for certain use cases on all commands. # def find_or_set_default_account # FIXME: API clients are scoped to their account so this code should # never need to run for them. unless 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 end end end end
Version data entries
28 entries across 28 versions & 1 rubygems