establish 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/establish/password_manager.rb +26 -0
- data/lib/establish/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67cc578f9c2613d233891e81ab3b66c0d2bffeb03c406b5e0c8ae0ae3359bef9
|
4
|
+
data.tar.gz: 496168e5fab860f3778b5a5abb982eedcd7002c435ade237088b4060187fa57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 475a202295cbd697b06d5eeec012328961443285b0e3be93f0936aa149c2656f14ac994376a9b4c349cc1ff6ada39ea64271d8d45dc923c4ef7dcf192c5c135b
|
7
|
+
data.tar.gz: 78bbb82503f934a91b65dc2270006ab27de004880718e2a6e45807e4f2db85f7039941122b92712b34c28c1903ab7878a8a2c728fb1d8732ab9a2e9a4f1024c6
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'security'
|
2
|
+
require 'highline/import' # to hide the entered password
|
2
3
|
|
3
4
|
module Establish
|
4
5
|
class PasswordManager
|
@@ -11,8 +12,33 @@ module Establish
|
|
11
12
|
self.username ||= ENV["ESTABLISH_USER"] || self.load_from_keychain[0]
|
12
13
|
self.password ||= ENV["ESTABLISH_PASSWORD"] || self.load_from_keychain[1]
|
13
14
|
|
15
|
+
if (self.username || '').length == 0 or (self.password || '').length == 0
|
16
|
+
ask_for_login
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
20
|
+
def ask_for_login
|
21
|
+
puts "No username or password given. You can use environment variables"
|
22
|
+
puts "ESTABLISH_USER, ESTABLISH_PASSWORD"
|
23
|
+
puts "The login information will be stored in your keychain"
|
24
|
+
|
25
|
+
while (self.username || '').length == 0
|
26
|
+
self.username = ask("Username: ")
|
27
|
+
end
|
28
|
+
|
29
|
+
while (self.password || '').length == 0
|
30
|
+
self.password = ask("Password: ") { |q| q.echo = "*" }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Now we store this information in the keychain
|
34
|
+
# Example usage taken from https://github.com/nomad/cupertino/blob/master/lib/cupertino/provisioning_portal/commands/login.rb
|
35
|
+
if Security::InternetPassword.add(Establish::PasswordManager::HOST, self.username, self.password)
|
36
|
+
return true
|
37
|
+
else
|
38
|
+
Helper.log.error "Could not store password in keychain"
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
16
42
|
|
17
43
|
def load_from_keychain
|
18
44
|
pass = Security::InternetPassword.find(:server => Establish::PasswordManager::HOST)
|
data/lib/establish/version.rb
CHANGED