Class: Brightbox::BBConfig

Constant Summary

Constants included from Config::TwoFactorAuth

Config::TwoFactorAuth::ENTER_TWO_FACTOR_PROMPT

Constants included from Config::PasswordHelper

Config::PasswordHelper::ENTER_PASSWORD_PROMPT, Config::PasswordHelper::EXPIRED_TOKEN_PROMPT

Instance Attribute Summary collapse

Attributes included from Config::AuthenticationTokens

#access_token, #refresh_token

Attributes included from Config::TwoFactorHelper

#two_factor_helper_password

Attributes included from Config::TwoFactorAuth

#current_second_factor

Attributes included from Config::GpgEncryptedPasswords

#gpg_password

Instance Method Summary collapse

Methods included from Config::Dirty

#clean_up, #dirty!, #dirty?

Methods included from Config::ToFog

#to_fog

Methods included from Config::Sections

#[], #add_login, #add_section, #delete_section, #section_names

Methods included from Config::Clients

#clear_default_client, #client_alias, #client_has_alias?, #client_id, #client_named?, #default_client, #determine_client, #has_multiple_clients?, #set_default_client, #using_api_client?, #using_application?

Methods included from Config::Accounts

#account, #default_account, #determine_account, #find_or_set_default_account, #save_default_account

Methods included from Config::AuthenticationTokens

#access_token_filename, #oauth_token, #reauthenticate, #refresh_token_filename, #renew_tokens, #update_stored_tokens

Methods included from Config::TwoFactorHelper

#two_factor_helper_command

Methods included from Config::TwoFactorAuth

#discover_two_factor_pin

Methods included from Config::PasswordHelper

#discover_password

Methods included from Config::GpgEncryptedPasswords

#gpg_encrypted_password_filename

Methods included from Config::Cache

#cache_id, #cache_path

Methods included from Logging

included

Constructor Details

#initialize(options = {}) ⇒ BBConfig

Returns a new instance of BBConfig.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :directory (String)

    A path to the directory where config and cached and located. Otherwise a default of $HOME/.brightbox is used

  • :force_default_config (Boolean)
  • :client_name (String)

    The name of the client whose config section to use

  • :account (String)

    The scoped account to use overriding the saved configuration



38
39
40
41
42
43
44
45
# File 'lib/brightbox-cli/config.rb', line 38

def initialize(options = {})
  @options = options
  prepare_dir
  prepare_ini
  @client_name = determine_client(options[:client_name])
  @account = (options[:account])
  @dirty = false
end

Instance Attribute Details

#account=(value) ⇒ Object (writeonly)

Sets the attribute account

Parameters:

  • value

    the value to set the attribute account to.



27
28
29
# File 'lib/brightbox-cli/config.rb', line 27

def account=(value)
  @account = value
end

#client_nameObject

Returns the value of attribute client_name.



26
27
28
# File 'lib/brightbox-cli/config.rb', line 26

def client_name
  @client_name
end

Instance Method Details

#configIni

The loads the configuration from disk or creates the directory if missing and caches the details.

Returns:

  • (Ini)

    The raw settings from the ini configuration file



77
78
79
# File 'lib/brightbox-cli/config.rb', line 77

def config
  @config_file
end

#config_directoryString

The String path to the configuration directory

Returns:

  • (String)


50
51
52
53
54
55
# File 'lib/brightbox-cli/config.rb', line 50

def config_directory
  return @dir if @dir

  path = @options[:directory] || default_config_dir
  @dir = File.expand_path(path)
end

#config_directory_exists?Boolean

Returns true if the config_directory exists on disk

Returns:

  • (Boolean)


60
61
62
# File 'lib/brightbox-cli/config.rb', line 60

def config_directory_exists?
  File.exist?(config_directory) && File.directory?(config_directory)
end

#config_filenameString

The String path to the configuration file itself (in .ini format)

Returns:

  • (String)


67
68
69
70
71
# File 'lib/brightbox-cli/config.rb', line 67

def config_filename
  return @config_filename if @config_filename

  @config_filename = File.join(config_directory, "config")
end

#core_setting(setting) ⇒ Object

Returns the core



109
110
111
# File 'lib/brightbox-cli/config.rb', line 109

def core_setting(setting)
  config["core"][setting]
end

#debug_tokensObject

Outputs to debug the current values of the config/client’s tokens



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/brightbox-cli/config.rb', line 91

def debug_tokens
  return unless ENV["DEBUG"]

  if client_name
    debug "Client: #{client_name}"

    debug "Access token: #{access_token} (#{cached_access_token})"
    if using_application?
      debug "Refresh token: #{refresh_token} (#{cached_refresh_token}))"
    else
      debug "Refresh token: <NOT EXPECTED FOR CLIENT>"
    end
  else
    debug "No client selected"
  end
end

#saveObject

Write out the configuration file to disk



82
83
84
85
86
87
# File 'lib/brightbox-cli/config.rb', line 82

def save
  return unless dirty? && config.respond_to?(:write)

  config.write
  clean_up
end

#set_core_setting(key, value) ⇒ Object



113
114
115
116
# File 'lib/brightbox-cli/config.rb', line 113

def set_core_setting(key, value)
  dirty! unless value == core_setting(key)
  config["core"][key] = value
end