Module: Brightbox::Config::PasswordHelper

Included in:
BBConfig
Defined in:
lib/brightbox-cli/config/password_helper.rb

Constant Summary collapse

ENTER_PASSWORD_PROMPT =
"Enter your password : ".freeze
EXPIRED_TOKEN_PROMPT =
"Your API credentials have expired, enter your password to update them.".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#password_helper_password=(value) ⇒ Object

Sets the attribute password_helper_password

Parameters:

  • value

    the value to set the attribute password_helper_password to.



7
8
9
# File 'lib/brightbox-cli/config/password_helper.rb', line 7

def password_helper_password=(value)
  @password_helper_password = value
end

Instance Method Details

#discover_password(password: nil, expired: false) ⇒ String

#discover_password will return the first password that can be recovered from either the passed input, encrypted storage, a helper application (if configured) or finally promping.

Parameters:

  • password (String) (defaults to: nil)

    a password given to the method

  • expired (Boolean) (defaults to: false)

    should the prompt explain tokens have expired?

Returns:

  • (String)

    the password



17
18
19
20
21
# File 'lib/brightbox-cli/config/password_helper.rb', line 17

def discover_password(password: nil, expired: false)
  password ||= gpg_password
  password ||= password_helper_password
  password ||= prompt_for_password(expired)
end