secret_config 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/secret_config.rb +1 -0
- data/lib/secret_config/cli.rb +86 -57
- data/lib/secret_config/registry.rb +6 -2
- data/lib/secret_config/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a8839c538b55ac74ff2db06cf2f25e1f711d005fd31f55f1308389c5224875
|
4
|
+
data.tar.gz: 630667a4ff3ad4bf2a8e61786454fc2375c575235ea78aabac5743575f00a966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b4fe728607bb924254839bc437d2a3615b532725d6a95d78be8adb44e6edb637ca8ff7f2011f031344163b7d7f838e976dde432c37bff3aec0ce6ca7fe8ff2
|
7
|
+
data.tar.gz: 7b5e7496f1e3a78766903ab4a5cbb319c4bfb411b2d61b09c15d65720cf0f80ce68fd95146e87c68779c43f9ba468b0af3a8dae0312dfc94e57a6c1f2598e067
|
data/README.md
CHANGED
data/lib/secret_config.rb
CHANGED
data/lib/secret_config/cli.rb
CHANGED
@@ -11,6 +11,7 @@ module SecretConfig
|
|
11
11
|
attr_reader :path, :region, :provider,
|
12
12
|
:export, :no_filter,
|
13
13
|
:import, :key_id, :key_alias, :random_size, :prune, :overwrite,
|
14
|
+
:diff_path, :import_path,
|
14
15
|
:fetch_key, :delete_key, :set_key, :set_value, :delete_path,
|
15
16
|
:copy_path, :diff,
|
16
17
|
:console,
|
@@ -43,6 +44,8 @@ module SecretConfig
|
|
43
44
|
@fetch_key = nil
|
44
45
|
@delete_key = nil
|
45
46
|
@delete_path = nil
|
47
|
+
@diff_path = nil
|
48
|
+
@import_path = nil
|
46
49
|
|
47
50
|
if argv.empty?
|
48
51
|
puts parser
|
@@ -58,15 +61,15 @@ module SecretConfig
|
|
58
61
|
elsif console
|
59
62
|
run_console
|
60
63
|
elsif export
|
61
|
-
run_export(export, filtered: !no_filter)
|
62
|
-
elsif import && prune
|
63
|
-
run_import_and_prune(import)
|
64
|
+
run_export(export, path, filtered: !no_filter)
|
64
65
|
elsif import
|
65
|
-
run_import(import)
|
66
|
-
elsif
|
67
|
-
|
66
|
+
run_import(import, path, prune)
|
67
|
+
elsif import_path
|
68
|
+
run_import_path(import_path, path, prune)
|
68
69
|
elsif diff
|
69
|
-
run_diff(diff)
|
70
|
+
run_diff(diff, path)
|
71
|
+
elsif diff_path
|
72
|
+
run_diff_path(diff, path)
|
70
73
|
elsif set_key
|
71
74
|
run_set(set_key, set_value)
|
72
75
|
elsif fetch_key
|
@@ -90,22 +93,26 @@ module SecretConfig
|
|
90
93
|
secret_config [options]
|
91
94
|
BANNER
|
92
95
|
|
93
|
-
opts.on "-e", "--export [FILE_NAME]", "Export configuration to a file or stdout if no file_name supplied." do |file_name|
|
96
|
+
opts.on "-e", "--export [FILE_NAME]", "Export configuration to a file or stdout if no file_name supplied. --path SOURCE_PATH is required." do |file_name|
|
94
97
|
@export = file_name || STDOUT
|
95
98
|
end
|
96
99
|
|
97
|
-
opts.on "-i", "--import [FILE_NAME]", "Import configuration from a file or stdin if no file_name supplied." do |file_name|
|
100
|
+
opts.on "-i", "--import [FILE_NAME]", "Import configuration from a file or stdin if no file_name supplied. --path TARGET_PATH is required." do |file_name|
|
98
101
|
@import = file_name || STDIN
|
99
102
|
end
|
100
103
|
|
101
|
-
opts.on "--
|
102
|
-
@
|
104
|
+
opts.on "--import-path SOURCE_PATH", "Import configuration from the configuration on another path. --path TARGET_PATH is required." do |path|
|
105
|
+
@import_path = path
|
103
106
|
end
|
104
107
|
|
105
|
-
opts.on "--diff [FILE_NAME]", "Compare configuration from a file or stdin if no file_name supplied." do |file_name|
|
108
|
+
opts.on "--diff [FILE_NAME]", "Compare configuration from a file or stdin if no file_name supplied. --path TARGET_PATH is required." do |file_name|
|
106
109
|
@diff = file_name
|
107
110
|
end
|
108
111
|
|
112
|
+
opts.on "--diff-path SOURCE_PATH", "Diff configuration with the configuration on another path. --path TARGET_PATH is required." do |path|
|
113
|
+
@diff_path = path
|
114
|
+
end
|
115
|
+
|
109
116
|
opts.on "-s", "--set KEY=VALUE", "Set one key to value. Example: --set mysql/database=localhost" do |param|
|
110
117
|
@set_key, @set_value = param.split("=")
|
111
118
|
unless @set_key && @set_value
|
@@ -129,7 +136,7 @@ module SecretConfig
|
|
129
136
|
@console = true
|
130
137
|
end
|
131
138
|
|
132
|
-
opts.on "-p", "--path PATH", "Path
|
139
|
+
opts.on "-p", "--path PATH", "Path in central configuration to use." do |path|
|
133
140
|
@path = path
|
134
141
|
end
|
135
142
|
|
@@ -141,7 +148,7 @@ module SecretConfig
|
|
141
148
|
@no_filter = true
|
142
149
|
end
|
143
150
|
|
144
|
-
opts.on "--prune", "During import delete all existing keys for which there is no key in the import file." do
|
151
|
+
opts.on "--prune", "During import delete all existing keys for which there is no key in the import file. Only applies to --import and --import-path." do
|
145
152
|
@prune = true
|
146
153
|
end
|
147
154
|
|
@@ -185,71 +192,57 @@ module SecretConfig
|
|
185
192
|
end
|
186
193
|
end
|
187
194
|
|
188
|
-
def run_export(file_name, filtered: true)
|
195
|
+
def run_export(file_name, path, filtered: true)
|
196
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
197
|
+
|
189
198
|
config = fetch_config(path, filtered: filtered)
|
190
199
|
write_config_file(file_name, config)
|
191
200
|
|
192
201
|
puts("Exported #{path} from #{provider} to #{file_name}") if file_name.is_a?(String)
|
193
202
|
end
|
194
203
|
|
195
|
-
def run_import(file_name)
|
196
|
-
|
204
|
+
def run_import(file_name, path, prune = false)
|
205
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
197
206
|
|
198
|
-
|
207
|
+
config = read_config_file(file_name)
|
208
|
+
import_config(config, path, prune)
|
199
209
|
|
200
|
-
puts("Imported #{file_name} to #{
|
210
|
+
puts("Imported #{file_name} to #{path} on provider: #{provider}") if file_name.is_a?(String)
|
201
211
|
end
|
202
212
|
|
203
|
-
def
|
204
|
-
|
205
|
-
delete_keys = current_values.keys - Utils.flatten(config, path).keys
|
213
|
+
def run_import_path(source_path, path, prune = false)
|
214
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
206
215
|
|
207
|
-
unless delete_keys.empty?
|
208
|
-
puts "Going to delete the following keys:"
|
209
|
-
delete_keys.each { |key| puts " #{key}" }
|
210
|
-
sleep(5)
|
211
|
-
end
|
212
|
-
|
213
|
-
set_config(config, path, current_values)
|
214
|
-
|
215
|
-
delete_keys.each do |key|
|
216
|
-
puts "Deleting: #{key}"
|
217
|
-
provider_instance.delete(key)
|
218
|
-
end
|
219
|
-
|
220
|
-
puts("Imported #{file_name} to #{provider} at #{path}") if file_name.is_a?(String)
|
221
|
-
end
|
222
|
-
|
223
|
-
def run_copy(source_path, target_path)
|
224
216
|
config = fetch_config(source_path, filtered: false)
|
217
|
+
import_config(config, path, prune)
|
225
218
|
|
226
|
-
|
227
|
-
|
228
|
-
puts "Copied #{source_path} to #{target_path} using #{provider}"
|
219
|
+
puts("Imported #{source_path} to #{path} on provider: #{provider}")
|
229
220
|
end
|
230
221
|
|
231
|
-
def run_diff(file_name)
|
222
|
+
def run_diff(file_name, path)
|
223
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
224
|
+
|
232
225
|
file_config = read_config_file(file_name)
|
233
226
|
file = Utils.flatten(file_config, path)
|
234
227
|
|
235
228
|
registry_config = fetch_config(path, filtered: false)
|
236
229
|
registry = Utils.flatten(registry_config, path)
|
237
230
|
|
238
|
-
(
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
end
|
231
|
+
puts("Comparing #{file_name} to #{path} on provider: #{provider}") if file_name.is_a?(String)
|
232
|
+
diff_config(file, registry)
|
233
|
+
end
|
234
|
+
|
235
|
+
def run_diff_path(source_path, path)
|
236
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
237
|
+
|
238
|
+
source_config = fetch_config(source_path, filtered: false)
|
239
|
+
source = Utils.flatten(source_config, path)
|
240
|
+
|
241
|
+
target_config = fetch_config(path, filtered: false)
|
242
|
+
target = Utils.flatten(target_config, path)
|
251
243
|
|
252
|
-
puts("
|
244
|
+
puts("Comparing #{source_path} to #{path} on provider: #{provider}")
|
245
|
+
diff_config(source, target)
|
253
246
|
end
|
254
247
|
|
255
248
|
def run_console
|
@@ -309,6 +302,42 @@ module SecretConfig
|
|
309
302
|
sort_hash_by_key!(config)
|
310
303
|
end
|
311
304
|
|
305
|
+
# Diffs two configs and displays the results
|
306
|
+
def diff_config(source, target)
|
307
|
+
(source.keys + target.keys).sort.uniq.each do |key|
|
308
|
+
if target.key?(key)
|
309
|
+
if source.key?(key)
|
310
|
+
value = source[key].to_s
|
311
|
+
# Ignore filtered values
|
312
|
+
puts "* #{key}: #{target[key]} => #{source[key]}" if (value != target[key].to_s) && (value != FILTERED)
|
313
|
+
else
|
314
|
+
puts "- #{key}"
|
315
|
+
end
|
316
|
+
elsif source.key?(key)
|
317
|
+
puts "+ #{key}: #{source[key]}"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def import_config(config, path, prune = false)
|
323
|
+
raise(ArgumentError, "Missing required option --path") unless path
|
324
|
+
|
325
|
+
delete_keys = prune ? current_values.keys - Utils.flatten(config, path).keys : []
|
326
|
+
|
327
|
+
unless delete_keys.empty?
|
328
|
+
puts "Going to delete the following keys:"
|
329
|
+
delete_keys.each { |key| puts " #{key}" }
|
330
|
+
sleep(5)
|
331
|
+
end
|
332
|
+
|
333
|
+
set_config(config, path, current_values)
|
334
|
+
|
335
|
+
delete_keys.each do |key|
|
336
|
+
puts "Deleting: #{key}"
|
337
|
+
provider_instance.delete(key)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
312
341
|
def read_file(file_name_or_io)
|
313
342
|
return file_name_or_io.read unless file_name_or_io.is_a?(String)
|
314
343
|
|
@@ -41,10 +41,10 @@ module SecretConfig
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Returns [String] configuration value for the supplied key
|
44
|
-
def fetch(key, default:
|
44
|
+
def fetch(key, default: :no_default_supplied, type: :string, encoding: nil)
|
45
45
|
value = self[key]
|
46
46
|
if value.nil?
|
47
|
-
raise(MissingMandatoryKey, "Missing configuration value for #{path}/#{key}") if default
|
47
|
+
raise(MissingMandatoryKey, "Missing configuration value for #{path}/#{key}") if default == :no_default_supplied
|
48
48
|
|
49
49
|
value = default.respond_to?(:call) ? default.call : default
|
50
50
|
end
|
@@ -138,6 +138,10 @@ module SecretConfig
|
|
138
138
|
%w[true 1 t].include?(value.to_s.downcase)
|
139
139
|
when :symbol
|
140
140
|
value.to_sym unless value.nil? || value.to_s.strip == ""
|
141
|
+
when :json
|
142
|
+
value.nil? ? nil : JSON.parse(value)
|
143
|
+
else
|
144
|
+
raise(ArgumentError, "Unrecognized type:#{type}")
|
141
145
|
end
|
142
146
|
end
|
143
147
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|