Class: Brightbox::Config::UserApplication
- Inherits:
-
Object
- Object
- Brightbox::Config::UserApplication
- Defined in:
- lib/brightbox-cli/config/user_application.rb
Constant Summary collapse
- NON_BLANK_KEYS =
FIXME: api_url should use fog’s underlying default
%w[api_url username].freeze
Instance Attribute Summary collapse
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#selected_config ⇒ Object
Returns the value of attribute selected_config.
Instance Method Summary collapse
-
#fetch_refresh_token(options) ⇒ Object
FIXME: This calls the underlying fog methods which also resets the access token but this method does not expose that token.
-
#initialize(incoming_config, client_name) ⇒ UserApplication
constructor
A new instance of UserApplication.
- #to_fog ⇒ Object
-
#valid? ⇒ Boolean
Returns
trueif the config section passed in has expected keys.
Constructor Details
#initialize(incoming_config, client_name) ⇒ UserApplication
Returns a new instance of UserApplication.
10 11 12 13 |
# 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 |
Instance Attribute Details
#client_name ⇒ Object
Returns the value of attribute client_name.
8 9 10 |
# File 'lib/brightbox-cli/config/user_application.rb', line 8 def client_name @client_name end |
#selected_config ⇒ Object
Returns the value of attribute selected_config.
8 9 10 |
# File 'lib/brightbox-cli/config/user_application.rb', line 8 def selected_config @selected_config end |
Instance Method Details
#fetch_refresh_token(options) ⇒ Object
FIXME: This calls the underlying fog methods which also resets the access token but this method does not expose that token.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/brightbox-cli/config/user_application.rb', line 42 def fetch_refresh_token() = { :brightbox_password => [:password], :brightbox_support_two_factor => true, :brightbox_one_time_password => [:one_time_password] } = password_auth_params.merge() connection = Fog::Compute.new() begin connection.get_access_token! rescue Excon::Errors::Unauthorized raise Brightbox::Api::ApiError, "Invalid credentials" end connection end |
#to_fog ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
#valid? ⇒ Boolean
TODO:
Implementation requires keys that are really optional
Returns true if the config section passed in has expected keys
33 34 35 36 37 |
# 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 |