class Brightbox::Config::UserApplication
Constants
- NON_BLANK_KEYS
-
FIXME: api_url should use fog’s underlying default
Attributes
Public Class Methods
Source
# File lib/brightbox-cli/config/user_application.rb, line 10 def initialize(incoming_config, client_name) @selected_config = incoming_config @client_name = client_name end
Public Instance Methods
Source
# File lib/brightbox-cli/config/user_application.rb, line 42 def fetch_refresh_token(options) password_options = { :brightbox_password => options[:password], :brightbox_support_two_factor => true, :brightbox_one_time_password => options[:one_time_password] } default_fog_options = password_auth_params.merge(password_options) connection = Fog::Compute.new(default_fog_options) begin connection.get_access_token! rescue Excon::Errors::Unauthorized raise Brightbox::Api::ApiError, "Invalid credentials" end connection end
FIXME: This calls the underlying fog methods which also resets the access token but this method does not expose that token.
Source
# File lib/brightbox-cli/config/user_application.rb, line 15 def to_fog check_required_params # Note we have to merge in refresh token at the higher level { :provider => "Brightbox", :brightbox_api_url => selected_config["api_url"], :brightbox_auth_url => selected_config["auth_url"] || selected_config["api_url"], :brightbox_client_id => client_id, :brightbox_secret => client_secret, :brightbox_support_two_factor => true, :persistent => persistent? } end
Source
# File lib/brightbox-cli/config/user_application.rb, line 33 def valid? NON_BLANK_KEYS.all? do |key| selected_config.key?(key) && !selected_config[key].to_s.empty? end end
Returns true
if the config section passed in has expected keys
@todo Implementation requires keys that are really optional
Private Instance Methods
Source
# File lib/brightbox-cli/config/user_application.rb, line 86 def check_required_params return if valid? NON_BLANK_KEYS.each do |key| unless selected_config.key?(key) && !selected_config[key].to_s.empty? raise Brightbox::BBConfigError, "#{key} option missing from config in section #{client_name}" end end end
Source
# File lib/brightbox-cli/config/user_application.rb, line 61 def client_id selected_config["client_id"] || Brightbox::EMBEDDED_APP_ID end
Source
# File lib/brightbox-cli/config/user_application.rb, line 65 def client_secret selected_config["secret"] || Brightbox::EMBEDDED_APP_SECRET end
Source
# File lib/brightbox-cli/config/user_application.rb, line 73 def password_auth_params { :provider => "Brightbox", :brightbox_api_url => selected_config["api_url"], :brightbox_auth_url => selected_config["auth_url"] || selected_config["api_url"], :brightbox_client_id => client_id, :brightbox_secret => client_secret, :brightbox_username => selected_config["username"], :brightbox_support_two_factor => true, :persistent => persistent? } end
Source
# File lib/brightbox-cli/config/user_application.rb, line 69 def persistent? selected_config["persistent"] != "false" end