lastpass-ansible 1.0.2 → 1.0.4
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 +4 -4
- data/bin/lastpass-ansible +62 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a511f0b355c0eff37b212888a9f2d8f9b52045
|
4
|
+
data.tar.gz: 44520ce7b3461644dd696853473b21d89f6cba3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d867a42010278cc52237d2c9bb06609d46d6fc75171e79e9b1974129a3736b397d2cc24abe36823dd12826243c4cafcf8051c775f47f12142a7e648cc7aa24
|
7
|
+
data.tar.gz: cc479b9f2ee1afb3cdb86da7bec36a9fa9a84b6da7fa1409e3d67ffa8c4d834467bb13ea451f28baedb0b2eac2713d021cf9c63b2dea172f312da0f9bbb2ee84
|
data/bin/lastpass-ansible
CHANGED
@@ -1,35 +1,25 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# Copyright 2017 Wojciech Adam Koszek <wojciech@koszek.com>
|
3
3
|
|
4
4
|
EX_USAGE = 64
|
5
|
-
NAME =
|
6
|
-
CONFIG_NAME =
|
5
|
+
NAME = 'lastpass-ansible'
|
6
|
+
CONFIG_NAME = '.lastpass-ansible.conf'
|
7
|
+
LASTPASS_ANSIBLE_NAME = 'LASTPASS_ANSIBLE_NAME'
|
8
|
+
LASTPASS_ANSIBLE_WRONG_PASS_SIM = 'LASTPASS_ANSIBLE_WRONG_PASS_SIM'
|
9
|
+
CONFIG_FILE_INIT_CONTENT=<<_INIT
|
10
|
+
# lastpass-ansible configuration file. For more details read:
|
11
|
+
# https://github.com/wkoszek/lastpass-ansible
|
12
|
+
_INIT
|
7
13
|
|
8
14
|
def main
|
9
|
-
if `which lpass`.length
|
15
|
+
if `which lpass`.length == 0
|
10
16
|
errfail("You don't have the 'lpass' command tool")
|
11
17
|
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
if lastpass_ansible_name.nil? then
|
19
|
-
errfail("Set Lastpass Vault account name via #{var_name}")
|
20
|
-
end
|
21
|
-
|
22
|
-
stdout = IO.try_convert(STDOUT)
|
23
|
-
if stdout == nil or stdout.isatty then
|
24
|
-
errfail("Won't print Ansible Vault password to terminal")
|
25
|
-
end
|
26
|
-
|
27
|
-
var_name = "LASTPASS_ANSIBLE_WRONG_PASS_SIM"
|
28
|
-
if ENV.has_key?(var_name) then
|
29
|
-
print "WrongPassword"
|
30
|
-
exit 0
|
31
|
-
end
|
32
|
-
|
19
|
+
check_if_init
|
20
|
+
lastpass_ansible_name = lastpass_ansible_name_get
|
21
|
+
fail_if_terminal_output
|
22
|
+
maybe_simulate_wrong_password
|
33
23
|
system("lpass show --password #{lastpass_ansible_name}")
|
34
24
|
end
|
35
25
|
|
@@ -40,22 +30,62 @@ def errfail(s)
|
|
40
30
|
exit EX_USAGE
|
41
31
|
end
|
42
32
|
|
33
|
+
def check_if_init
|
34
|
+
has_init_passed = ARGV.select{|arg| arg =~ /^--init/ }.length > 0
|
35
|
+
if !has_init_passed
|
36
|
+
return
|
37
|
+
end
|
38
|
+
if File.exist?(CONFIG_NAME)
|
39
|
+
errfail("File #{CONFIG_NAME} exists!")
|
40
|
+
end
|
41
|
+
guessed_vault_name = File.basename(Dir.pwd)
|
42
|
+
File.write(CONFIG_NAME, CONFIG_FILE_INIT_CONTENT + guessed_vault_name)
|
43
|
+
print "Config file #{CONFIG_NAME} created; set password for #{guessed_vault_name} in Ansible\n"
|
44
|
+
exit 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def lastpass_ansible_name_get
|
48
|
+
lastpass_ansible_name = read_config_file_recurse(Dir.pwd)
|
49
|
+
var_name = LASTPASS_ANSIBLE_NAME
|
50
|
+
if ENV.key?(var_name)
|
51
|
+
lastpass_ansible_name = ENV[var_name]
|
52
|
+
end
|
53
|
+
if lastpass_ansible_name.nil?
|
54
|
+
errfail("Set Lastpass Vault account name via #{var_name}")
|
55
|
+
end
|
56
|
+
return lastpass_ansible_name
|
57
|
+
end
|
58
|
+
|
43
59
|
def read_config_file_recurse(directory)
|
44
|
-
path_chunks = directory.split(
|
60
|
+
path_chunks = directory.split('/')
|
45
61
|
config_file_body = nil
|
46
|
-
path_chunks.length
|
62
|
+
path_chunks.length.downto(1) do |path_index|
|
47
63
|
new_path_chunks = path_chunks
|
48
64
|
new_path_chunks[path_index] = CONFIG_NAME
|
49
|
-
cfg_file_name = new_path_chunks[0..path_index].join(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
config_file_body = File.read(cfg_file_name).strip
|
65
|
+
cfg_file_name = new_path_chunks[0..path_index].join('/')
|
66
|
+
if File.exist?(cfg_file_name)
|
67
|
+
config_file_body =
|
68
|
+
File.readlines(cfg_file_name).select{|l| l =~ /^[^#]/ }[0]
|
54
69
|
end
|
55
|
-
|
70
|
+
end
|
56
71
|
return config_file_body
|
57
72
|
end
|
58
73
|
|
74
|
+
def fail_if_terminal_output
|
75
|
+
stdout = IO.try_convert(STDOUT)
|
76
|
+
if stdout.nil? || stdout.isatty
|
77
|
+
errfail("Won't print Ansible Vault password to terminal")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def maybe_simulate_wrong_password
|
82
|
+
var_name = LASTPASS_ANSIBLE_WRONG_PASS_SIM
|
83
|
+
if ENV.key?(var_name)
|
84
|
+
print 'WrongPassword'
|
85
|
+
exit 0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
59
89
|
#--------
|
60
90
|
|
61
91
|
main
|