module Brightbox::Config::PasswordHelper
Constants
- ENTER_PASSWORD_PROMPT
- EXPIRED_TOKEN_PROMPT
Attributes
Public Instance Methods
Source
# 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
{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.
@param password [String] a password given to the method @param expired [Boolean] should the prompt explain tokens have expired? @return [String] the password
Private Instance Methods
Source
# File lib/brightbox-cli/config/password_helper.rb, line 40 def password_helper_call info "INFO: Calling password helper to obtain password" begin cmd = password_helper_command.split(/\s+/) IO.popen(cmd, "r") do |io| io.readline.chomp end rescue Errno::ENOENT nil end end
Source
# File lib/brightbox-cli/config/password_helper.rb, line 25 def password_helper_command return config[client_name]["password_helper_command"] unless client_name.nil? end
Source
# File lib/brightbox-cli/config/password_helper.rb, line 30 def password_helper_password if defined?(@password_helper_password) && !@password_helper_password.nil? return @password_helper_password end @password_helper_password = if password_helper_command password_helper_call end end
Return the password from the helper if it’s possible
Source
# File lib/brightbox-cli/config/password_helper.rb, line 53 def prompt_for_password(expired) require "highline" highline = HighLine.new highline.say(EXPIRED_TOKEN_PROMPT) if expired # FIXME: Capture interupts if user aborts highline.ask(ENTER_PASSWORD_PROMPT) { |q| q.echo = false } end
This asks the user to input their password