Class: CredentialsManager::AccountManager
- Inherits:
-
Object
- Object
- CredentialsManager::AccountManager
- Defined in:
- credentials_manager/lib/credentials_manager/account_manager.rb
Constant Summary collapse
- DEFAULT_PREFIX =
"deliver"
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Is used for iTunes Transporter.
Instance Method Summary collapse
- #add_to_keychain ⇒ Object
-
#default_prefix? ⇒ Boolean
Is the default prefix “deliver”.
- #fetch_password_from_env ⇒ Object
-
#initialize(user: nil, password: nil, prefix: nil, note: nil) ⇒ AccountManager
constructor
A new instance of AccountManager.
-
#invalid_credentials(force: false) ⇒ Object
Call this method to ask the user to re-enter the credentials @return: Did the user decide to remove the old entry and enter a new password?.
-
#options ⇒ Object
Use env variables from this method to augment internet password item with additional data.
- #password(ask_if_missing: true) ⇒ Object
- #remove_from_keychain ⇒ Object
- #server_name ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(user: nil, password: nil, prefix: nil, note: nil) ⇒ AccountManager
Returns a new instance of AccountManager.
17 18 19 20 21 22 23 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 17 def initialize(user: nil, password: nil, prefix: nil, note: nil) @prefix = prefix || DEFAULT_PREFIX @user = user @password = password @note = note end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Is used for iTunes Transporter
11 12 13 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 11 def prefix @prefix end |
Instance Method Details
#add_to_keychain ⇒ Object
81 82 83 84 85 86 87 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 81 def add_to_keychain if Security::InternetPassword.add(server_name, user, password, ) else Security::InternetPassword.add(server_name, user, password) end end |
#default_prefix? ⇒ Boolean
Is the default prefix “deliver”
26 27 28 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 26 def default_prefix? @prefix == DEFAULT_PREFIX end |
#fetch_password_from_env ⇒ Object
41 42 43 44 45 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 41 def fetch_password_from_env password = ENV["FASTLANE_PASSWORD"] || ENV["DELIVER_PASSWORD"] return password if password.to_s.length > 0 return nil end |
#invalid_credentials(force: false) ⇒ Object
Call this method to ask the user to re-enter the credentials @return: Did the user decide to remove the old entry and enter a new password?
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 63 def invalid_credentials(force: false) puts("The login credentials for '#{user}' seem to be wrong".red) if fetch_password_from_env puts("The password was taken from the environment variable") puts("Please make sure it is correct") return false end if force || agree("Do you want to re-enter your password? (y/n)", true) puts("Removing Keychain entry for user '#{user}'...".yellow) if mac? remove_from_keychain ask_for_login return true end false end |
#options ⇒ Object
Use env variables from this method to augment internet password item with additional data. These variables are used by Xamarin Studio to authenticate Apple developers.
100 101 102 103 104 105 106 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 100 def hash = {} hash[:p] = ENV["FASTLANE_PATH"] if ENV["FASTLANE_PATH"] hash[:P] = ENV["FASTLANE_PORT"] if ENV["FASTLANE_PORT"] hash[:r] = ENV["FASTLANE_PROTOCOL"] if ENV["FASTLANE_PROTOCOL"] hash.empty? ? nil : hash end |
#password(ask_if_missing: true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 47 def password(ask_if_missing: true) if default_prefix? @password ||= fetch_password_from_env end unless @password item = Security::InternetPassword.find(server: server_name) @password ||= item.password if item end ask_for_login while ask_if_missing && @password.to_s.length == 0 return @password end |
#remove_from_keychain ⇒ Object
89 90 91 92 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 89 def remove_from_keychain Security::InternetPassword.delete(server: server_name) @password = nil end |
#server_name ⇒ Object
94 95 96 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 94 def server_name "#{@prefix}.#{user}" end |
#user ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'credentials_manager/lib/credentials_manager/account_manager.rb', line 30 def user if default_prefix? @user ||= ENV["FASTLANE_USER"] @user ||= ENV["DELIVER_USER"] @user ||= AppfileConfig.try_fetch_value(:apple_id) end ask_for_login if @user.to_s.length == 0 return @user end |