Method: Establish::PasswordManager#ask_for_login

Defined in:
lib/establish/password_manager.rb

#ask_for_loginObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/establish/password_manager.rb', line 20

def 
  puts "No username or password given. You can use environment variables"
  puts "ESTABLISH_USER, ESTABLISH_PASSWORD"
  puts "The login information will be stored in your keychain"

  while (self.username || '').length == 0
    self.username = ask("Username: ")
  end

  while (self.password || '').length == 0
    self.password = ask("Password: ") { |q| q.echo = "*" }
  end

  # Now we store this information in the keychain
  # Example usage taken from https://github.com/nomad/cupertino/blob/master/lib/cupertino/provisioning_portal/commands/login.rb
  if Security::InternetPassword.add(Establish::PasswordManager::HOST, self.username, self.password)
    return true
  else
    Helper.log.error "Could not store password in keychain"
    return false
  end
end