secrets_cli 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41cffe43e06f96024a6b43e14fd0275356cae792
4
- data.tar.gz: d39b1dc108e9f91b9caa8510aa63e55890bce4ee
3
+ metadata.gz: 16774bc319041eaa7626b8fa5d549e177fe32a7b
4
+ data.tar.gz: 9fe08ca8f65f426885b8c520f77b0eacb1384a9b
5
5
  SHA512:
6
- metadata.gz: ac80e54dcc81d6d8686b103526c3af194c0e6f3b9046e1703367c7a475c93146de9c1fc23317923679329e132df4598b05aba08cff918b9473f12f38dc87ac6f
7
- data.tar.gz: 41d68aaff94847923a925b202ac1f5806a315f502d7ab1361c23e5f129e041322b6174c1a567df1834a3bbf51e29d5b9c215c064028ae86baa4908d095161417
6
+ metadata.gz: 102a529eea123fae032c33f514ec6ac82acf1da7b26c093e488a2c7ec2bf40fdfda790db14d3dd197ac6e4e71d608b15dc227b69e19afe3761a09e6c837dc9e5
7
+ data.tar.gz: b2685901af34edf2ec657471648961b0b9034c9e27b75ccc291dcc4d07faad8d2d9697f905e0bdaed175204e3873e8993548e42d1316144895b3697346774896
data/exe/secrets CHANGED
@@ -5,6 +5,8 @@ require 'rubygems'
5
5
  require 'commander/import'
6
6
  require 'secrets_cli'
7
7
 
8
+ require 'pry' if ENV['SECRETS_ENV'] == 'dev'
9
+
8
10
  program :version, SecretsCli::VERSION
9
11
  program :description, 'CLI for vault'
10
12
 
@@ -25,5 +25,17 @@ module SecretsCli
25
25
  def print_verbose(message)
26
26
  puts pastel.cyan(message)
27
27
  end
28
+
29
+ def pretty_diff(diff)
30
+ diff.each_line do |line|
31
+ case line[0]
32
+ when '+' then prompt.ok(line, newline: false)
33
+ when '-' then prompt.error(line, newline: false)
34
+ else
35
+ puts line
36
+ end
37
+ end
38
+ puts
39
+ end
28
40
  end
29
41
  end
@@ -14,9 +14,22 @@ module SecretsCli
14
14
 
15
15
  def command
16
16
  secrets = super
17
+ compare(secrets)
18
+ write(secrets)
19
+ secrets
20
+ end
21
+
22
+ def compare(secrets)
23
+ diff = TTY::File.diff(secrets_file, secrets, verbose: false)
24
+ return if diff == ''
25
+ prompt.ok("There are some differences between #{secrets_file} and vault:")
26
+ pretty_diff(diff)
27
+ exit 0 unless prompt.yes?("Are you sure you want to override #{secrets_file}?")
28
+ end
29
+
30
+ def write(secrets)
17
31
  print_verbose("Writing to #{secrets_file}")
18
32
  File.open(File.join(secrets_dir, secrets_file), 'w') { |file| file.write(secrets) }
19
- secrets
20
33
  end
21
34
  end
22
35
  end
@@ -13,6 +13,7 @@ module SecretsCli
13
13
 
14
14
  def call
15
15
  return if !options.without_prompt && !are_you_sure?
16
+ compare
16
17
  super
17
18
  end
18
19
 
@@ -23,8 +24,18 @@ module SecretsCli
23
24
  secrets
24
25
  end
25
26
 
27
+ def compare
28
+ secrets = ::Vault.logical.read(secrets_full_storage_key)
29
+ secrets = secrets.nil? ? ' ' : secrets.data[SECRETS_FIELD]
30
+ diff = TTY::File.diff(secrets, secrets_file, verbose: false)
31
+ return if diff == ''
32
+ prompt.ok("There are some differences between #{secrets_file} and vault:")
33
+ pretty_diff(diff)
34
+ exit 0 unless prompt.yes?("Are you sure you want to override #{secrets_full_storage_key}?")
35
+ end
36
+
26
37
  def are_you_sure?
27
- prompt.yes?("Are you sure you want to write #{secrets_file} to #{secrets_full_storage_key}", default: 'Y')
38
+ prompt.yes?("Are you sure you want to write #{secrets_file} to #{secrets_full_storage_key}")
28
39
  end
29
40
  end
30
41
  end
@@ -13,8 +13,9 @@ module SecretsCli
13
13
  attr_reader :secrets_storage_key
14
14
 
15
15
  def command
16
- secret = ::Vault.logical.read(secrets_full_storage_key)
17
- secret.data[SECRETS_FIELD]
16
+ secrets = ::Vault.logical.read(secrets_full_storage_key)
17
+ error!("There are no secrets in #{secrets_full_storage_key}") if secrets.nil?
18
+ secrets.data[SECRETS_FIELD]
18
19
  end
19
20
  end
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module SecretsCli
2
- VERSION = '1.3.3'
2
+ VERSION = '1.4.0'
3
3
  end
data/lib/secrets_cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'tty-prompt'
3
+ require 'tty-file'
3
4
  require 'open3'
4
5
  require 'singleton'
5
6
  require 'vault'
data/secrets_cli.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'pry'
33
33
 
34
34
  spec.add_runtime_dependency 'commander'
35
- spec.add_runtime_dependency 'tty-prompt', '~> 0.4.0'
35
+ spec.add_runtime_dependency 'tty-prompt'
36
+ spec.add_runtime_dependency 'tty-file'
36
37
  spec.add_runtime_dependency 'vault', '~> 0.5.0'
37
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secrets_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,16 +84,30 @@ dependencies:
84
84
  name: tty-prompt
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.4.0
89
+ version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.4.0
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tty-file
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: vault
99
113
  requirement: !ruby/object:Gem::Requirement