lastpass-ansible 1.0.5 → 1.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lastpass-ansible +39 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35688e5f2bd415b14d3b2c7b2ee5b78e841a4b29
4
- data.tar.gz: 5e5e44079aae726a069ebbc7d7052f5455ddf8a9
3
+ metadata.gz: dae331e54452c05743f3aa34bc0f251850c6d747
4
+ data.tar.gz: 0c5ca526c68459de23bcadc2f1728cf7998f04ba
5
5
  SHA512:
6
- metadata.gz: 89125df762f9decf1f882fe0ad8f3f3ea16add0b47dbfd2286395727a7e2c835cb0138851349232220d25e1c05a4ee43debe8ee0600e24d0801e3fe585cd1f48
7
- data.tar.gz: 31133714c8553ba645c3fe8e82d69f47d40a740c7cb306d66964f5fb23eb41d37d73bc7cd5b86262afb66e0211e9a462fafe9021c7c1076934549a97fa79cc3f
6
+ metadata.gz: 2671557e5765c266a686c90a7b33c1f64adc26383765b37cb23086d3b371496acc58b54f13fd25d66a1e66424a7079da3925099fc28cd9f0bcc7bd5c6022bead
7
+ data.tar.gz: c6851877eac2d8abcb432ae661bfb8a500fdb82d91f48f0c4ea6db43807fe7f9341890258e51ade1191a7ab267b8a1179dac4f20625c9b0883d3ef308acb4e9e
data/bin/lastpass-ansible CHANGED
@@ -6,6 +6,8 @@ NAME = 'lastpass-ansible'
6
6
  CONFIG_NAME = '.lastpass-ansible.conf'
7
7
  LASTPASS_ANSIBLE_NAME = 'LASTPASS_ANSIBLE_NAME'
8
8
  LASTPASS_ANSIBLE_WRONG_PASS_SIM = 'LASTPASS_ANSIBLE_WRONG_PASS_SIM'
9
+ LASTPASS_ANSIBLE_PASSLEN = 30
10
+ LASTPASS_ANSIBLE_PREFIX = "Ansible_Vault"
9
11
  CONFIG_FILE_INIT_CONTENT=<<_INIT
10
12
  # lastpass-ansible configuration file. For more details read:
11
13
  # https://github.com/wkoszek/lastpass-ansible
@@ -16,7 +18,8 @@ def main
16
18
  errfail("You don't have the 'lpass' command tool")
17
19
  end
18
20
 
19
- check_if_init
21
+ check_if_logged_in
22
+ initialize_if_init
20
23
  lastpass_ansible_name = lastpass_ansible_name_get
21
24
  fail_if_terminal_output
22
25
  maybe_simulate_wrong_password
@@ -30,7 +33,13 @@ def errfail(s)
30
33
  exit EX_USAGE
31
34
  end
32
35
 
33
- def check_if_init
36
+ def check_if_logged_in
37
+ if system("lpass status -q") == false
38
+ errfail("You must login first with: lpass login <login@name.com>")
39
+ end
40
+ end
41
+
42
+ def initialize_if_init
34
43
  has_init_passed = ARGV.select{|arg| arg =~ /^--init/ }.length > 0
35
44
  if !has_init_passed
36
45
  return
@@ -38,12 +47,36 @@ def check_if_init
38
47
  if File.exist?(CONFIG_NAME)
39
48
  errfail("File #{CONFIG_NAME} exists!")
40
49
  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"
50
+ initialize_project
44
51
  exit 0
45
52
  end
46
53
 
54
+ def initialize_project
55
+ guessed_site_name = guess_site_name_by_directory
56
+ if lastpass_has_password(guessed_site_name)
57
+ errfail("LassPass already has password for #{guessed_site_name}")
58
+ end
59
+ c1 = system("lpass generate #{guessed_site_name} #{LASTPASS_ANSIBLE_PASSLEN} >/dev/null 2>&1")
60
+ if c1 != true
61
+ errfail("Couldn't initialize. Maybe #{guessed_site_name} exists?")
62
+ end
63
+ system("lpass sync") # --sync=now didn't work for me for 'lpass generate'
64
+ File.write(CONFIG_NAME, CONFIG_FILE_INIT_CONTENT + guessed_site_name)
65
+ print "Config file #{CONFIG_NAME} created; set password for #{guessed_site_name} in Ansible\n"
66
+ end
67
+
68
+ def guess_site_name_by_directory
69
+ return LASTPASS_ANSIBLE_PREFIX + "/" + File.basename(Dir.pwd)
70
+ end
71
+
72
+ def lastpass_has_password(site_name)
73
+ system("lpass sync")
74
+ return `lpass ls --color=never`
75
+ .split('\n')
76
+ .select{ |out_line| out_line =~ /^#{site_name}/ }
77
+ .length > 0
78
+ end
79
+
47
80
  def lastpass_ansible_name_get
48
81
  lastpass_ansible_name = read_config_file_recurse(Dir.pwd)
49
82
  var_name = LASTPASS_ANSIBLE_NAME
@@ -51,7 +84,7 @@ def lastpass_ansible_name_get
51
84
  lastpass_ansible_name = ENV[var_name]
52
85
  end
53
86
  if lastpass_ansible_name.nil?
54
- errfail("Set Lastpass Vault account name via #{var_name}")
87
+ lastpass_ansible_name = guess_site_name_by_directory
55
88
  end
56
89
  return lastpass_ansible_name
57
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lastpass-ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Adam Koszek