Class: Establish::PasswordManager
- Inherits:
-
Object
- Object
- Establish::PasswordManager
- Defined in:
- lib/establish/password_manager.rb
Constant Summary collapse
- HOST =
"itunesconnect.apple.com"
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #ask_for_login ⇒ Object
-
#initialize ⇒ PasswordManager
constructor
A new instance of PasswordManager.
- #load_from_keychain ⇒ Object
Constructor Details
#initialize ⇒ PasswordManager
Returns a new instance of PasswordManager.
10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/establish/password_manager.rb', line 6 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/establish/password_manager.rb', line 6 def username @username end |
Instance Method Details
#ask_for_login ⇒ Object
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 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 ⇒ Object
43 44 45 46 47 48 |
# 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 |