Class: CredentialsManager::PasswordManager
- Inherits:
-
Object
- Object
- CredentialsManager::PasswordManager
- Defined in:
- lib/credentials_manager/password_manager.rb
Overview
Handles reading out the password from the keychain or asking for login data
Instance Attribute Summary collapse
-
#password ⇒ String
The password of the currently logged in user.
-
#username ⇒ String
The username / email address of the currently logged in user.
Class Method Summary collapse
- .logout ⇒ Object
-
.shared_manager(id_to_use = nil, ask_if_missing = true) ⇒ Object
A singleton object, which also makes sure, to use the correct Apple ID.
Instance Method Summary collapse
-
#initialize(id_to_use = nil, ask_if_missing = true) ⇒ PasswordManager
constructor
A new instance of PasswordManager.
-
#password_seems_wrong ⇒ Object
This method is called, when the iTunes backend returns that the login data is wrong This will ask the user, if he wants to re-enter the password.
Constructor Details
#initialize(id_to_use = nil, ask_if_missing = true) ⇒ PasswordManager
A new instance of PasswordManager.
This already check the Keychain if there is a username and password stored. If that’s not the case, it will ask for login data via stdin
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/credentials_manager/password_manager.rb', line 44 def initialize(id_to_use = nil, ask_if_missing = true) self.username ||= id_to_use || ENV["DELIVER_USER"] || AppfileConfig.try_fetch_value(:apple_id) || load_from_keychain[0] self.password ||= ENV["DELIVER_PASSWORD"] || load_from_keychain[1] if (self.username || '').length == 0 or (self.password || '').length == 0 if ask_if_missing puts "No username or password given. You can set environment variables:" puts "DELIVER_USER, DELIVER_PASSWORD" ask_for_login end end end |
Instance Attribute Details
#password ⇒ String
Returns The password of the currently logged in user.
11 12 13 |
# File 'lib/credentials_manager/password_manager.rb', line 11 def password @password end |
#username ⇒ String
Returns The username / email address of the currently logged in user.
9 10 11 |
# File 'lib/credentials_manager/password_manager.rb', line 9 def username @username end |
Class Method Details
.logout ⇒ Object
33 34 35 |
# File 'lib/credentials_manager/password_manager.rb', line 33 def self.logout @instance = nil end |
.shared_manager(id_to_use = nil, ask_if_missing = true) ⇒ Object
A singleton object, which also makes sure, to use the correct Apple ID
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/credentials_manager/password_manager.rb', line 19 def self.shared_manager(id_to_use = nil, ask_if_missing = true) @instance ||= {} return @instance[id_to_use] if @instance[id_to_use] if id_to_use @instance[id_to_use] ||= PasswordManager.new(id_to_use, ask_if_missing) else # No user given, let's see if we have a previously used one return @instance.values.first if @instance.values.count > 0 # Create a new one @instance[id_to_use] ||= PasswordManager.new(id_to_use, ask_if_missing) end end |
Instance Method Details
#password_seems_wrong ⇒ Object
This method is called, when the iTunes backend returns that the login data is wrong This will ask the user, if he wants to re-enter the password
61 62 63 64 65 |
# File 'lib/credentials_manager/password_manager.rb', line 61 def password_seems_wrong puts "It seems like the username or password for the account '#{self.username}' is wrong.".red puts "Please open the Keychain app, switch to `Passwords` and search for `deliver.`".red puts "You can then either remove the outdated entry or directly update it.".red end |