class Establish::PasswordManager
Constants
- HOST
Attributes
password[RW]
username[RW]
Public Class Methods
new()
click to toggle source
# File lib/establish/password_manager.rb, line 10 def initialize self.username ||= ENV["ESTABLISH_USER"] || self.load_from_keychain[0] self.password ||= ENV["ESTABLISH_PASSWORD"] || self.load_from_keychain[1] if (self.username || '').length == 0 or (self.password || '').length == 0 ask_for_login end end
Public Instance Methods
ask_for_login()
click to toggle source
# File lib/establish/password_manager.rb, line 20 def ask_for_login 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
load_from_keychain()
click to toggle source
# File lib/establish/password_manager.rb, line 43 def load_from_keychain pass = Security::InternetPassword.find(:server => Establish::PasswordManager::HOST) return [pass.attributes['acct'], pass.password] if pass return [nil, nil] end