Class: Deliver::PasswordManager

Inherits:
Object
  • Object
show all
Defined in:
lib/deliver/password_manager.rb

Overview

Handles reading out the password from the keychain or asking for login data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id_to_use = nil) ⇒ 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

Parameters:

  • id_to_use (String) (defaults to: nil)

    Apple ID (e.g. [email protected]) which should be used for this upload. if given, only the password will be asked/loaded.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deliver/password_manager.rb', line 27

def initialize(id_to_use = nil)
  self.username ||= ENV["DELIVER_USER"] || id_to_use || load_from_keychain[0]
  self.password ||= ENV["DELIVER_PASSWORD"] || load_from_keychain[1]

  if (self.username || '').length == 0 or (self.password || '').length == 0
    puts "No username or password given. You can set environment variables:"
    puts "DELIVER_USER, DELIVER_PASSWORD"

    
  end
end

Instance Attribute Details

#passwordString

Returns The password of the currently logged in user.

Returns:

  • (String)

    The password of the currently logged in user



10
11
12
# File 'lib/deliver/password_manager.rb', line 10

def password
  @password
end

#usernameString

Returns The username / email address of the currently logged in user.

Returns:

  • (String)

    The username / email address of the currently logged in user



8
9
10
# File 'lib/deliver/password_manager.rb', line 8

def username
  @username
end

Class Method Details

.shared_manager(id_to_use = nil) ⇒ Object

A singleton object, which also makes sure, to use the correct Apple ID

Parameters:

  • id_to_use (String) (defaults to: nil)

    The Apple ID email address which should be used



17
18
19
# File 'lib/deliver/password_manager.rb', line 17

def self.shared_manager(id_to_use = nil)
  @@instance ||= PasswordManager.new(id_to_use)
end

Instance Method Details

#password_seems_wrongObject

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



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

def password_seems_wrong
  return false if Helper.is_test?
  
  puts "It seems like the username or password for the account '#{self.username}' is wrong."
  reenter = agree("Do you want to re-enter your username and password? (y/n)", true)
  if reenter
    remove_from_keychain

    @username = nil
    @password = nil

    puts "You will have to re-run the recent command to use the new username/password."
    return true
  else
    return false
  end
end