secrets_cli 1.10.0 → 1.11.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
  SHA256:
3
- metadata.gz: a7c1d5dacd65932996391d02598e8f06d76a7d4f844cdf06b0a2de0ddad05f6e
4
- data.tar.gz: 5fe3a3f7002d3f3b1922ad6db4f4d2f485eab1c2fb48d4405aec7893fcebfbca
3
+ metadata.gz: 6af10caecd588872e7b6b71370738b48f7724ea57780e3f25617723e5bbd7c1a
4
+ data.tar.gz: 3547a5dac42ca6ae752e6fd60fbf330e3da9b85d00a685b7deb9cff01805aff2
5
5
  SHA512:
6
- metadata.gz: 90fa5d1a00f982fc2bcb49348a960bca4a0756ac9f814536ebaba2131b53d8439cd4b80460515df53e1612fbc7325122164f0627c86a3625e8db6d754c85bc58
7
- data.tar.gz: 22a9d89f6d11560f5761b287fbd6c46ada673607bcbc0ca51c407c59b50ff0bf82a64b2a43274d0abd0be4df48e908a2792a374ba753b38110140ac70b2ba108
6
+ metadata.gz: 3efd83f8f1abcfc6d61188531be16e7e9f9e93386a89b27c9bb56f2dd6710e5e6ec05282008fd5702e17652a3455ae1934696e14aad774942f0957e6ec022cca
7
+ data.tar.gz: e923815d6e97e9b0f1cf36216863cc16cfa71f7a43eca53263eb47df4148d4deed60e47827d1482e782d53a01fe52cc9fc49aaf397dee3b9cdca7094f98cf032
data/README.md CHANGED
@@ -28,7 +28,7 @@ The following environment variables need to be set:
28
28
 
29
29
  For `vault` itself:
30
30
 
31
- VAULT_ADDR - this is an address to your vault server
31
+ VAULT_ADDR - address to your vault server (can also be set through config)
32
32
  VAULT_CACERT - if you have a self issued certificate, point this environment variable to the location of the root CA file
33
33
 
34
34
  For `secrets_cli`:
@@ -57,8 +57,10 @@ supply the config through options.
57
57
  Example of the `.secrets`:
58
58
 
59
59
  ---
60
- :secrets_file: config/application.yml # file where your secrets are kept, depending on your environment gem (figaro, dotenv, etc)
61
- :secrets_storage_key: rails/my_project/ # vault 'storage_key' where your secrets will be kept.
60
+ :secrets_file: config/application.yml # Required; file where your secrets are kept, depending on your environment gem (figaro, dotenv, etc)
61
+ :secrets_storage_key: rails/my_project/ # Required; vault 'storage_key' where your secrets will be kept.
62
+ development: # Any configuration can be nested under environment
63
+ :vault_addr: https://myvault.com # Optional; vault url (default: VAULT_ADDR environment variable)
62
64
 
63
65
  ### Policies
64
66
 
@@ -99,7 +101,7 @@ This will allow you to edit secrets on the fly. You choose which editor to use b
99
101
 
100
102
  The same flags apply for editing as for reading:
101
103
 
102
- $ EDIOTR='atom -w' secrets edit -e production
104
+ $ EDITOR='atom -w' secrets edit -e production
103
105
 
104
106
  ### Pull
105
107
 
@@ -111,6 +113,8 @@ To pull from a different environment, also supply the `-e` flag and the `-f` fla
111
113
 
112
114
  $ secrets pull -e production -f config/application.production.yml
113
115
 
116
+ You can also supply the `--ci_mode` or `-y` flag to disable prompts and outputs.
117
+
114
118
  ### Push
115
119
 
116
120
  $ secrets push
data/exe/secrets CHANGED
@@ -17,6 +17,7 @@ command :init do |c|
17
17
  c.summary = 'Use to initialize project, create .secrets file'
18
18
  c.option '-f', '--secrets_file STRING', String, 'Define secrets file'
19
19
  c.option '-k', '--secrets_storage_key STRING', String, 'Define secrets storage_key'
20
+ c.option '-a', '--vault_addr STRING', String, 'Vault url'
20
21
  c.action do |_args, options|
21
22
  SecretsCli::Init.new(options).call
22
23
  end
data/lib/secrets_cli.rb CHANGED
@@ -11,6 +11,7 @@ require 'secrets_cli/check/secrets'
11
11
  require 'secrets_cli/check/vault'
12
12
  require 'secrets_cli/prompts/secrets_file'
13
13
  require 'secrets_cli/prompts/secrets_storage_key'
14
+ require 'secrets_cli/prompts/vault_addr'
14
15
  require 'secrets_cli/vault/base'
15
16
  require 'secrets_cli/vault/auth'
16
17
  require 'secrets_cli/vault/list'
@@ -20,6 +21,8 @@ require 'secrets_cli/vault/push'
20
21
  require 'secrets_cli/vault/edit'
21
22
  require 'secrets_cli/version'
22
23
 
24
+ # require 'pry'
25
+
23
26
  module SecretsCli
24
27
  SECRETS_CONFIG_FILE = '.secrets'.freeze
25
28
  SECRETS_FIELD = :secrets
@@ -10,7 +10,7 @@ module SecretsCli
10
10
  end
11
11
 
12
12
  def call
13
- error! 'Missing VAULT_ADDR env' if ENV['VAULT_ADDR'].nil?
13
+ error! 'Missing vault_addr' if config.vault_addr.nil?
14
14
  error! 'Missing VAULT_AUTH_METHOD env' if missing_auth_method?
15
15
  case auth_method
16
16
  when 'app_id'
@@ -3,24 +3,35 @@ module SecretsCli
3
3
  attr_reader :environment, :verbose
4
4
 
5
5
  def initialize(options)
6
- @environment = options.environment || ENV['RAILS_ENV'] || ENV['NODE_ENV'] || 'development'
6
+ @environment = (options.environment || ENV['RAILS_ENV'] || ENV['NODE_ENV'] || 'development').to_sym
7
7
  @verbose = options.verbose
8
8
  end
9
9
 
10
10
  def config
11
- @config ||= YAML.load_file(SECRETS_CONFIG_FILE)
11
+ @config ||=
12
+ Psych.load(File.read(SECRETS_CONFIG_FILE), symbolize_names: true)
12
13
  end
13
14
 
14
15
  def secrets_file
15
- config[:secrets_file]
16
+ fetch(:secrets_file)
16
17
  end
17
18
 
18
19
  def secrets_storage_key
19
- config[:secrets_storage_key]
20
+ fetch(:secrets_storage_key)
21
+ end
22
+
23
+ def vault_addr
24
+ fetch(:vault_addr) || ENV['VAULT_ADDR']
20
25
  end
21
26
 
22
27
  def self.write(config)
23
28
  File.open(SECRETS_CONFIG_FILE, 'w') { |file| file.write(config.to_yaml) }
24
29
  end
30
+
31
+ private
32
+
33
+ def fetch(var)
34
+ config.fetch(environment, {}).fetch(var, nil) || config[var]
35
+ end
25
36
  end
26
37
  end
@@ -17,10 +17,11 @@ module SecretsCli
17
17
  private
18
18
 
19
19
  def config
20
- {
21
- secrets_file: secrets_file,
22
- secrets_storage_key: secrets_storage_key
23
- }
20
+ {}.tap do |hash|
21
+ hash[:secrets_file] = secrets_file
22
+ hash[:secrets_storage_key] = secrets_storage_key
23
+ hash[:vault_addr] = vault_addr if vault_addr
24
+ end
24
25
  end
25
26
 
26
27
  def secrets_file
@@ -32,5 +33,9 @@ module SecretsCli
32
33
  storage_key << '/' unless storage_key.end_with?('/')
33
34
  storage_key
34
35
  end
36
+
37
+ def vault_addr
38
+ @vault_addr ||= options.vault_addr || SecretsCli::Prompts::VaultAddr.new.call
39
+ end
35
40
  end
36
41
  end
@@ -0,0 +1,11 @@
1
+ module SecretsCli
2
+ module Prompts
3
+ class VaultAddr
4
+ include SecretsCli::Helpers
5
+
6
+ def call
7
+ prompt.ask('What is the vault address? (if not supplied VAULT_ADDR env will be used)')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -21,13 +21,13 @@ module SecretsCli
21
21
  def command
22
22
  case auth_method
23
23
  when 'github'
24
- ::Vault.auth.github(auth_token)
24
+ vault.auth.github(auth_token)
25
25
  when 'token'
26
- ::Vault.auth.token(auth_token)
26
+ vault.auth.token(auth_token)
27
27
  when 'app_id'
28
- ::Vault.auth.app_id(auth_app_id, auth_user_id)
28
+ vault.auth.app_id(auth_app_id, auth_user_id)
29
29
  when 'approle'
30
- ::Vault.auth.approle(auth_role_id, auth_secret_id)
30
+ vault.auth.approle(auth_role_id, auth_secret_id)
31
31
  else
32
32
  error! "Unknown auth method #{auth_method}"
33
33
  end.auth.policies
@@ -12,6 +12,7 @@ module SecretsCli
12
12
  def call
13
13
  options.verbose ? prompt.ok(command) : command
14
14
  rescue => exception
15
+ # require 'pry'; binding.pry
15
16
  error!(exception.message)
16
17
  end
17
18
 
@@ -21,8 +22,12 @@ module SecretsCli
21
22
  raise NotImplementedError
22
23
  end
23
24
 
25
+ def vault
26
+ @vault ||= ::Vault::Client.new(address: config.vault_addr)
27
+ end
28
+
24
29
  def secrets_full_storage_key
25
- File.join(secrets_storage_key, config.environment)
30
+ File.join(secrets_storage_key, config.environment.to_s)
26
31
  end
27
32
 
28
33
  def compare(first, second)
@@ -12,10 +12,10 @@ module SecretsCli
12
12
  attr_reader :secrets_storage_key
13
13
 
14
14
  def command
15
- secrets = ::Vault.logical.read(secrets_full_storage_key)
15
+ secrets = vault.logical.read(secrets_full_storage_key)
16
16
  new_secrets = ask_editor(content(secrets))
17
17
  compare(content(secrets), new_secrets)
18
- ::Vault.logical.write(secrets_full_storage_key, SECRETS_FIELD => new_secrets)
18
+ vault.logical.write(secrets_full_storage_key, SECRETS_FIELD => new_secrets)
19
19
  new_secrets
20
20
  end
21
21
 
@@ -13,7 +13,7 @@ module SecretsCli
13
13
  attr_reader :secrets_storage_key
14
14
 
15
15
  def command
16
- ::Vault.logical.list(secrets_storage_key).join("\n")
16
+ vault.logical.list(secrets_storage_key).join("\n")
17
17
  end
18
18
  end
19
19
  end
@@ -20,22 +20,22 @@ module SecretsCli
20
20
  private
21
21
 
22
22
  def command
23
- ::Vault.logical.write(secrets_full_storage_key, SECRETS_FIELD => secrets)
23
+ vault.logical.write(secrets_full_storage_key, SECRETS_FIELD => secrets)
24
24
  secrets
25
25
  end
26
26
 
27
27
  def compare
28
- secrets = ::Vault.logical.read(secrets_full_storage_key)
28
+ secrets = vault.logical.read(secrets_full_storage_key)
29
29
  secrets = secrets.nil? ? ' ' : secrets.data[SECRETS_FIELD]
30
30
  diff = TTY::File.diff(secrets, secrets_file, verbose: false)
31
31
  return if diff == ''
32
32
  prompt.ok("There are some differences between #{secrets_file} and vault:")
33
33
  pretty_diff(diff)
34
- exit 0 unless prompt.yes?("Are you sure you want to override #{secrets_full_storage_key}?")
34
+ exit 0 unless prompt.yes?("Are you sure you want to override #{config.vault_addr} #{secrets_full_storage_key}?")
35
35
  end
36
36
 
37
37
  def are_you_sure?
38
- prompt.yes?("Are you sure you want to write #{secrets_file} to #{secrets_full_storage_key}")
38
+ prompt.yes?("Are you sure you want to write #{secrets_file} to #{config.vault_addr} #{secrets_full_storage_key}")
39
39
  end
40
40
  end
41
41
  end
@@ -13,8 +13,8 @@ module SecretsCli
13
13
  attr_reader :secrets_storage_key
14
14
 
15
15
  def command
16
- secrets = ::Vault.logical.read(secrets_full_storage_key)
17
- error!("There are no secrets in #{secrets_full_storage_key}") if secrets.nil?
16
+ secrets = vault.logical.read(secrets_full_storage_key)
17
+ error!("There are no secrets in #{config.vault_addr} #{secrets_full_storage_key}") if secrets.nil?
18
18
  secrets.data[SECRETS_FIELD]
19
19
  end
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module SecretsCli
2
- VERSION = '1.10.0'
2
+ VERSION = '1.11.0'
3
3
  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.10.0
4
+ version: 1.11.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: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,6 +149,7 @@ files:
149
149
  - lib/secrets_cli/init.rb
150
150
  - lib/secrets_cli/prompts/secrets_file.rb
151
151
  - lib/secrets_cli/prompts/secrets_storage_key.rb
152
+ - lib/secrets_cli/prompts/vault_addr.rb
152
153
  - lib/secrets_cli/vault/auth.rb
153
154
  - lib/secrets_cli/vault/base.rb
154
155
  - lib/secrets_cli/vault/edit.rb
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  version: '0'
180
181
  requirements: []
181
182
  rubyforge_project:
182
- rubygems_version: 2.7.3
183
+ rubygems_version: 2.7.6
183
184
  signing_key:
184
185
  specification_version: 4
185
186
  summary: This is a CLI for easier use of https://www.vaultproject.io/