s3crets 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/s3crets/version.rb +1 -1
- data/lib/s3crets_merge.rb +21 -11
- data/test/expected_output.json +9 -0
- data/test/input/node.json +9 -0
- data/test/input/secrets +7 -0
- data/test/run_tests.sh +5 -0
- metadata +13 -5
data/lib/s3crets/version.rb
CHANGED
data/lib/s3crets_merge.rb
CHANGED
@@ -35,13 +35,15 @@ class Configuratron
|
|
35
35
|
|
36
36
|
node_data = JSON.parse(File.read(json_file))
|
37
37
|
|
38
|
-
merge_hashes(@secrets, node_data)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
modified = merge_hashes(@secrets, node_data)
|
39
|
+
|
40
|
+
if modified
|
41
|
+
file_to_write = get_file_name(json_file)
|
42
|
+
files_updated << file_to_write
|
43
|
+
File.open(file_to_write, 'w') do |fh|
|
44
|
+
fh.puts JSON.pretty_generate(node_data)
|
45
|
+
fh.close
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
@@ -53,24 +55,32 @@ class Configuratron
|
|
53
55
|
# Merge source into destination in-place
|
54
56
|
# Only where they have keys in common
|
55
57
|
# Taking care not to lose keys in destination but not source
|
58
|
+
# Returns whether or not destination was modified
|
56
59
|
def merge_hashes(source, destination)
|
57
|
-
source.each_key do |key|
|
58
60
|
|
59
|
-
|
61
|
+
modified = false
|
60
62
|
|
63
|
+
source.each_key do |key|
|
64
|
+
if destination.has_key?(key)
|
61
65
|
case source[key]
|
62
66
|
when Hash
|
63
|
-
merge_hashes( source[key], destination[key] )
|
67
|
+
modified = merge_hashes( source[key], destination[key] )
|
64
68
|
when String
|
65
69
|
destination[key] = source[key]
|
70
|
+
modified = true
|
66
71
|
else
|
67
72
|
puts "Searching through source hash for a string but found #{source[key].class}"
|
68
73
|
exit 1
|
69
74
|
end
|
70
|
-
|
71
75
|
end
|
76
|
+
end
|
72
77
|
|
78
|
+
if modified
|
79
|
+
return true
|
80
|
+
else
|
81
|
+
return false
|
73
82
|
end
|
83
|
+
|
74
84
|
end
|
75
85
|
|
76
86
|
def get_file_name(json_file)
|
data/test/input/secrets
ADDED
data/test/run_tests.sh
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3crets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -77,6 +77,10 @@ files:
|
|
77
77
|
- lib/s3crets/version.rb
|
78
78
|
- lib/s3crets_merge.rb
|
79
79
|
- s3crets.gemspec
|
80
|
+
- test/expected_output.json
|
81
|
+
- test/input/node.json
|
82
|
+
- test/input/secrets
|
83
|
+
- test/run_tests.sh
|
80
84
|
homepage: ''
|
81
85
|
licenses: []
|
82
86
|
post_install_message:
|
@@ -92,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
96
|
version: '0'
|
93
97
|
segments:
|
94
98
|
- 0
|
95
|
-
hash: -
|
99
|
+
hash: -1215962576813344020
|
96
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
101
|
none: false
|
98
102
|
requirements:
|
@@ -101,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
105
|
version: '0'
|
102
106
|
segments:
|
103
107
|
- 0
|
104
|
-
hash: -
|
108
|
+
hash: -1215962576813344020
|
105
109
|
requirements: []
|
106
110
|
rubyforge_project:
|
107
111
|
rubygems_version: 1.8.23
|
@@ -112,4 +116,8 @@ summary: s3crets looks for a YAML config file and performs a deep merge against
|
|
112
116
|
JSON file. This ensures your secrets are only merged into the files you intended. The
|
113
117
|
purpose of s3crets was to help us keep secrets out of configuration JSON, which
|
114
118
|
is kept in source control.
|
115
|
-
test_files:
|
119
|
+
test_files:
|
120
|
+
- test/expected_output.json
|
121
|
+
- test/input/node.json
|
122
|
+
- test/input/secrets
|
123
|
+
- test/run_tests.sh
|