credentials_manager 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d6ff9dc2af11593ae49731751920d7a7afce656
4
- data.tar.gz: 977a5df300bc4b5432a057faadf28f2610101cb3
3
+ metadata.gz: bde8f7bd1ba5585cdc09b030cf1a935ecb739b73
4
+ data.tar.gz: 11c73c6983ec77346a8bc1a3121344c09cc8bda8
5
5
  SHA512:
6
- metadata.gz: b834015d4b6264222aa4a24298d96ed674ad4c210ca81a431a1ef1d36b74dc2fb3da1338b7f78864571060e49b36f2f460f6311a16961a63944d6cac290bdd36
7
- data.tar.gz: 786be1a4dadf3eeea22ec908fcd9edd620ec3e8ee8a9b56cb67da3c27deaef4aed48740c446b95161d2251359e3c67a74269f4601916b6d4efac1c2b8aaff1e1
6
+ metadata.gz: 909d88cb900f568044e9c527a00c71eb3edaa78cdf981c7e41dd2dab3d48c3c7db256067d7ddcc25314706012c97af7d9c1a33ba9dec6e8a26eb38f84fed3e7f
7
+ data.tar.gz: 5ece03d37c9779e87827c6c7105086ee46cc9660b43b5016baeccfac2a6a4a4aec18cf9c7df34fb0b104ea9d22c0d1a974b0190a891808cd091299be9301b98f
@@ -1,8 +1,8 @@
1
1
  require 'credentials_manager/password_manager'
2
+ require 'credentials_manager/account_manager'
2
3
 
3
4
  # Third Party code
4
5
  require 'colored'
5
6
 
6
7
  module CredentialsManager
7
-
8
8
  end
@@ -0,0 +1,73 @@
1
+ require 'security'
2
+ require 'highline/import' # to hide the entered password
3
+
4
+ module CredentialsManager
5
+ class AccountManager
6
+ def initialize(user: nil, password: nil)
7
+ @user = user
8
+ @password = password
9
+ end
10
+
11
+ def user
12
+ @user ||= ENV["FASTLANE_USER"]
13
+ @user ||= ENV["DELIVER_USER"]
14
+ @user ||= AppfileConfig.try_fetch_value(:apple_id)
15
+ ask_for_login if @user.to_s.length == 0
16
+ return @user
17
+ end
18
+
19
+ def password
20
+ @password ||= ENV["FASTLANE_PASSWORD"]
21
+ @password ||= ENV["DELIVER_PASSWORD"]
22
+ unless @password
23
+ item = Security::InternetPassword.find(server: server_name)
24
+ @password ||= item.password if item
25
+ end
26
+ ask_for_login if @password.to_s.length == 0
27
+ return @password
28
+ end
29
+
30
+ # Call this method to ask the user to re-enter the credentials
31
+ # @param force: if false the user is asked before it gets deleted
32
+ def invalid_credentials(force: false)
33
+ puts "The login credentials for '#{user}' seem to be wrong".red
34
+ if force || agree("Do you want to re-enter your password? (y/n)", true)
35
+ puts "Removing Keychain entry for user '#{user}'...".yellow
36
+ remove_from_keychain
37
+ ask_for_login
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def ask_for_login
44
+ puts "-------------------------------------------------------------------------------------".green
45
+ puts "The login information you enter will be stored in your Mac OS Keychain".green
46
+ puts "More information about it on GitHub: https://github.com/fastlane/CredentialsManager".green
47
+ puts "-------------------------------------------------------------------------------------".green
48
+
49
+ @user = ask("Username: ") while @user.to_s.length == 0
50
+ while @password.to_s.length == 0
51
+ @password = ask("Password (for #{@user}): ") { |q| q.echo = "*" }
52
+ end
53
+
54
+ return true if ENV["FASTLANE_DONT_STORE_PASSWORD"]
55
+
56
+ # Now we store this information in the keychain
57
+ if Security::InternetPassword.add(server_name, user, password)
58
+ return true
59
+ else
60
+ puts "Could not store password in keychain".red
61
+ return false
62
+ end
63
+ end
64
+
65
+ def remove_from_keychain
66
+ Security::InternetPassword.delete(server: server_name)
67
+ end
68
+
69
+ def server_name
70
+ "deliver.#{user}"
71
+ end
72
+ end
73
+ end
@@ -16,20 +16,28 @@ module CredentialsManager
16
16
 
17
17
  def self.default_path
18
18
  ["./fastlane/Appfile", "./Appfile"].each do |current|
19
- return current if File.exists?current
19
+ return current if File.exist? current
20
20
  end
21
21
  nil
22
22
  end
23
23
 
24
24
  def initialize(path = nil)
25
- path ||= self.class.default_path
25
+ path ||= self.class.default_path
26
26
 
27
- raise "Could not find Appfile at path '#{path}'".red unless File.exists?(path)
27
+ raise "Could not find Appfile at path '#{path}'".red unless File.exist?(path)
28
28
 
29
29
  full_path = File.expand_path(path)
30
30
  Dir.chdir(File.expand_path('..', path)) do
31
+ # rubocop:disable Lint/Eval
31
32
  eval(File.read(full_path))
33
+ # rubocop:enable Lint/Eval
32
34
  end
35
+
36
+ fallback_to_default_values
37
+ end
38
+
39
+ def fallback_to_default_values
40
+ data[:apple_id] ||= ENV["FASTLANE_USER"] || ENV["DELIVER_USER"]
33
41
  end
34
42
 
35
43
  def data
@@ -39,39 +47,19 @@ module CredentialsManager
39
47
  # Setters
40
48
 
41
49
  def app_identifier(*args, &block)
42
- if block_given?
43
- value = yield
44
- else
45
- value = args.shift
46
- end
47
- data[:app_identifier] = value if value
50
+ setter(:app_identifier, *args, &block)
48
51
  end
49
52
 
50
53
  def apple_id(*args, &block)
51
- if block_given?
52
- value = yield
53
- else
54
- value = args.shift
55
- end
56
- data[:apple_id] = value if value
54
+ setter(:apple_id, *args, &block)
57
55
  end
58
56
 
59
57
  def team_id(*args, &block)
60
- if block_given?
61
- value = yield
62
- else
63
- value = args.shift
64
- end
65
- data[:team_id] = value if value
58
+ setter(:team_id, *args, &block)
66
59
  end
67
60
 
68
61
  def team_name(*args, &block)
69
- if block_given?
70
- value = yield
71
- else
72
- value = args.shift
73
- end
74
- data[:team_name] = value if value
62
+ setter(:team_name, *args, &block)
75
63
  end
76
64
 
77
65
  # Override Appfile configuration for a specific lane.
@@ -109,5 +97,16 @@ module CredentialsManager
109
97
  block.call
110
98
  end
111
99
  end
100
+
101
+ private
102
+
103
+ def setter(key, *args, &_block)
104
+ if block_given?
105
+ value = yield
106
+ else
107
+ value = args.shift
108
+ end
109
+ data[key] = value if value
110
+ end
112
111
  end
113
112
  end
@@ -35,14 +35,13 @@ module CredentialsManager
35
35
  end
36
36
 
37
37
  # A new instance of PasswordManager.
38
- #
38
+ #
39
39
  # This already check the Keychain if there is a username and password stored.
40
40
  # If that's not the case, it will ask for login data via stdin
41
41
  # @param id_to_use (String) Apple ID (e.g. user@apple.com) which should be used for this upload.
42
42
  # if given, only the password will be asked/loaded.
43
43
  # @param ask_if_missing (boolean) true by default: if no credentials are found, should the user be asked?
44
44
  def initialize(id_to_use = nil, ask_if_missing = true)
45
-
46
45
  self.username ||= id_to_use || ENV["DELIVER_USER"] || AppfileConfig.try_fetch_value(:apple_id) || load_from_keychain[0]
47
46
  self.password ||= ENV["DELIVER_PASSWORD"] || load_from_keychain[1]
48
47
 
@@ -65,56 +64,55 @@ module CredentialsManager
65
64
  end
66
65
 
67
66
  private
68
- def ask_for_login
69
- puts "-------------------------------------------------------------------------------------".green
70
- puts "The login information you enter will be stored in your Mac OS Keychain".green
71
- puts "More information about that on GitHub: https://github.com/fastlane/CredentialsManager".green
72
- puts "-------------------------------------------------------------------------------------".green
73
67
 
74
- username_was_there = self.username
68
+ def ask_for_login
69
+ puts "-------------------------------------------------------------------------------------".green
70
+ puts "The login information you enter will be stored in your Mac OS Keychain".green
71
+ puts "More information about that on GitHub: https://github.com/fastlane/CredentialsManager".green
72
+ puts "-------------------------------------------------------------------------------------".green
75
73
 
76
- while (self.username || '').length == 0
77
- self.username = ask("Username: ")
78
- end
74
+ username_was_there = self.username
79
75
 
80
- self.password ||= load_from_keychain[1] # maybe there was already something stored in the keychain
76
+ self.username = ask("Username: ") while (self.username || '').length == 0
81
77
 
82
- if (self.password || '').length > 0
83
- return true
84
- else
85
- while (self.password || '').length == 0
86
- text = "Password: "
87
- text = "Password (for #{self.username}): " if username_was_there
88
- self.password = ask(text) { |q| q.echo = "*" }
89
- end
78
+ self.password ||= load_from_keychain[1] # maybe there was already something stored in the keychain
90
79
 
91
- # Now we store this information in the keychain
92
- # Example usage taken from https://github.com/nomad/cupertino/blob/master/lib/cupertino/provisioning_portal/commands/login.rb
93
- unless ENV["FASTLANE_DONT_STORE_PASSWORD"]
94
- if Security::InternetPassword.add(hostname, self.username, self.password)
95
- return true
96
- else
97
- puts "Could not store password in keychain".red
98
- return false
99
- end
80
+ if (self.password || '').length > 0
81
+ return true
82
+ else
83
+ while (self.password || '').length == 0
84
+ text = "Password: "
85
+ text = "Password (for #{self.username}): " if username_was_there
86
+ self.password = ask(text) { |q| q.echo = "*" }
87
+ end
88
+
89
+ # Now we store this information in the keychain
90
+ # Example usage taken from https://github.com/nomad/cupertino/blob/master/lib/cupertino/provisioning_portal/commands/login.rb
91
+ unless ENV["FASTLANE_DONT_STORE_PASSWORD"]
92
+ if Security::InternetPassword.add(hostname, self.username, self.password)
93
+ return true
94
+ else
95
+ puts "Could not store password in keychain".red
96
+ return false
100
97
  end
101
98
  end
102
99
  end
100
+ end
103
101
 
104
- def remove_from_keychain
105
- puts "Removing keychain item: #{hostname}".yellow
106
- Security::InternetPassword.delete(:server => hostname)
107
- end
108
-
109
- def load_from_keychain
110
- pass = Security::InternetPassword.find(:server => hostname)
111
-
112
- return [pass.attributes['acct'], pass.password] if pass
113
- return [nil, nil]
114
- end
102
+ def remove_from_keychain
103
+ puts "Removing keychain item: #{hostname}".yellow
104
+ Security::InternetPassword.delete(server: hostname)
105
+ end
115
106
 
116
- def hostname
117
- [HOST, self.username].join('.')
118
- end
107
+ def load_from_keychain
108
+ pass = Security::InternetPassword.find(server: hostname)
109
+
110
+ return [pass.attributes['acct'], pass.password] if pass
111
+ return [nil, nil]
112
+ end
113
+
114
+ def hostname
115
+ [HOST, self.username].join('.')
116
+ end
119
117
  end
120
118
  end
@@ -1,3 +1,3 @@
1
1
  module CredentialsManager
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credentials_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-22 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -118,6 +118,7 @@ files:
118
118
  - LICENSE
119
119
  - README.md
120
120
  - lib/credentials_manager.rb
121
+ - lib/credentials_manager/account_manager.rb
121
122
  - lib/credentials_manager/appfile_config.rb
122
123
  - lib/credentials_manager/password_manager.rb
123
124
  - lib/credentials_manager/version.rb