Class: CredentialsManager::AccountManager

Inherits:
Object
  • Object
show all
Defined in:
lib/credentials_manager/account_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(user: nil, password: nil, prefix: nil) ⇒ AccountManager

Returns a new instance of AccountManager.

Parameters:

  • prefix (String) (defaults to: nil)

    Very optional, is used for the iTunes Transporter which uses application specofic passwords



8
9
10
11
12
13
# File 'lib/credentials_manager/account_manager.rb', line 8

def initialize(user: nil, password: nil, prefix: nil)
  @prefix = prefix || "deliver"

  @user = user
  @password = password
end

Instance Method Details

#add_to_keychainObject



58
59
60
# File 'lib/credentials_manager/account_manager.rb', line 58

def add_to_keychain
  Security::InternetPassword.add(server_name, user, password)
end

#fetch_password_from_envObject



23
24
25
# File 'lib/credentials_manager/account_manager.rb', line 23

def fetch_password_from_env
  ENV["FASTLANE_PASSWORD"] || ENV["DELIVER_PASSWORD"]
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?

Parameters:

  • force: (defaults to: false)

    if false the user is asked before it gets deleted



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/credentials_manager/account_manager.rb', line 40

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
    remove_from_keychain
    
    return true
  end
  false
end

#password(ask_if_missing: true) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/credentials_manager/account_manager.rb', line 27

def password(ask_if_missing: true)
  @password ||= fetch_password_from_env
  unless @password
    item = Security::InternetPassword.find(server: server_name)
    @password ||= item.password if item
  end
   while ask_if_missing && @password.to_s.length == 0
  return @password
end

#remove_from_keychainObject



62
63
64
65
# File 'lib/credentials_manager/account_manager.rb', line 62

def remove_from_keychain
  Security::InternetPassword.delete(server: server_name)
  @password = nil
end

#server_nameObject



67
68
69
# File 'lib/credentials_manager/account_manager.rb', line 67

def server_name
  "#{@prefix}.#{user}"
end

#userObject



15
16
17
18
19
20
21
# File 'lib/credentials_manager/account_manager.rb', line 15

def user
  @user ||= ENV["FASTLANE_USER"]
  @user ||= ENV["DELIVER_USER"]
  @user ||= AppfileConfig.try_fetch_value(:apple_id)
   if @user.to_s.length == 0
  return @user
end