Class: PasswordHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/carthage_cache_ftps/helper/password_helper.rb

Constant Summary collapse

UI =
FastlaneCore::UI

Instance Method Summary collapse

Instance Method Details

#password(host, username) ⇒ Object

[View source]

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/carthage_cache_ftps/helper/password_helper.rb', line 11

def password(host, username)
  password = ENV["CARTHAGE_CACHE_FTPS_PASSWORD"]
  unless password
    item = Security::InternetPassword.find(server: server_name(host, username))
    password = item.password if item
  end

  unless password
    if !UI.interactive?
      UI.error "Neither the CARTHAGE_CACHE_FTPS_PASSWORD environment variable nor the local keychain contained a password."
      UI.error "Bailing out instead of asking for a password, since this is non-interactive mode."
      UI.user_error!("Try setting the CARTHAGE_CACHE_FTPS_PASSWORD environment variable, or temporarily enable interactive mode to store a password.")
    else
      UI.important "Enter the passphrase that should be used to login to the ftps"
      UI.important "This passphrase is specific per host and username and will be stored in your local keychain"
      password = Fastlane::Helper::CarthageCacheFtpsHelper.ask_password(confirm: false)
      store_password(host, username, password)
    end
  end

  return password
end

#server_name(host, username) ⇒ Object

[View source]

7
8
9
# File 'lib/fastlane/plugin/carthage_cache_ftps/helper/password_helper.rb', line 7

def server_name(host, username)
  ["carthage_cache_ftps", host, username].join("_")
end

#store_password(host, username, password) ⇒ Object

[View source]

34
35
36
# File 'lib/fastlane/plugin/carthage_cache_ftps/helper/password_helper.rb', line 34

def store_password(host, username, password)
  Security::InternetPassword.add(server_name(host, username), "", password)
end