Class: Brightbox::BBConfig
- Inherits:
-
Object
- Object
- Brightbox::BBConfig
- Includes:
- Config::Accounts, Config::AuthenticationTokens, Config::Cache, Config::Clients, Config::Dirty, Config::GpgEncryptedPasswords, Config::PasswordHelper, Config::Sections, Config::ToFog, Config::TwoFactorAuth, Config::TwoFactorHelper, Logging
- Defined in:
- lib/brightbox-cli/config.rb
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
-
#account ⇒ Object
writeonly
Sets the attribute account.
-
#client_name ⇒ Object
Returns the value of attribute client_name.
Attributes included from Config::AuthenticationTokens
Attributes included from Config::TwoFactorHelper
Attributes included from Config::TwoFactorAuth
Attributes included from Config::GpgEncryptedPasswords
Instance Method Summary collapse
-
#config ⇒ Ini
The loads the configuration from disk or creates the directory if missing and caches the details.
-
#config_directory ⇒ String
The String path to the configuration directory.
-
#config_directory_exists? ⇒ Boolean
Returns
trueif theconfig_directoryexists on disk. -
#config_filename ⇒ String
The String path to the configuration file itself (in .ini format).
-
#core_setting(setting) ⇒ Object
Returns the core.
-
#debug_tokens ⇒ Object
Outputs to debug the current values of the config/client’s tokens.
-
#initialize(options = {}) ⇒ BBConfig
constructor
A new instance of BBConfig.
-
#save ⇒ Object
Write out the configuration file to disk.
- #set_core_setting(key, value) ⇒ Object
Methods included from Config::Dirty
Methods included from Config::ToFog
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
Methods included from Config::TwoFactorAuth
Methods included from Config::PasswordHelper
Methods included from Config::GpgEncryptedPasswords
#gpg_encrypted_password_filename
Methods included from Config::Cache
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ BBConfig
Returns a new instance of BBConfig.
38 39 40 41 42 43 44 45 |
# File 'lib/brightbox-cli/config.rb', line 38 def initialize( = {}) @options = prepare_dir prepare_ini @client_name = determine_client([:client_name]) @account = determine_account([:account]) @dirty = false end |
Instance Attribute Details
#account=(value) ⇒ Object (writeonly)
Sets the attribute account
27 28 29 |
# File 'lib/brightbox-cli/config.rb', line 27 def account=(value) @account = value end |
#client_name ⇒ Object
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
#config ⇒ Ini
The loads the configuration from disk or creates the directory if missing and caches the details.
77 78 79 |
# File 'lib/brightbox-cli/config.rb', line 77 def config @config_file end |
#config_directory ⇒ String
The String path to the configuration directory
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.(path) end |
#config_directory_exists? ⇒ Boolean
Returns true if the config_directory exists on disk
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_filename ⇒ String
The String path to the configuration file itself (in .ini format)
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_tokens ⇒ Object
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 |
#save ⇒ Object
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 |