s3crets 0.0.3 → 0.0.4
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.rb +0 -1
- data/lib/s3crets_merge.rb +33 -19
- metadata +4 -5
- data/lib/s3crets_dig.rb +0 -7
data/lib/s3crets/version.rb
CHANGED
data/lib/s3crets.rb
CHANGED
data/lib/s3crets_merge.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Configuratron
|
2
2
|
|
3
|
-
attr_reader :overwrite, :files_updated
|
3
|
+
attr_reader :keys, :overwrite, :files_updated
|
4
4
|
|
5
5
|
def initialize(opts={})
|
6
6
|
if opts[:secrets_file]
|
@@ -22,41 +22,55 @@ class Configuratron
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def replace_config(dir)
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
search_folder = File.expand_path(dir)
|
27
|
+
files = Dir.glob(search_folder + "/*.json")
|
27
28
|
|
28
29
|
if files.empty?
|
29
30
|
puts "Was unable to find any JSON files [#{search_folder}]"
|
30
31
|
else
|
31
|
-
|
32
32
|
Dir.glob(File.expand_path(dir) + "/*.json") do |json_file|
|
33
33
|
|
34
34
|
next if json_file =~ /.new./
|
35
35
|
|
36
|
-
|
37
|
-
node_data = JSON.parse(File.read(json_file))
|
38
|
-
rescue JSON::ParserError => e
|
39
|
-
raise RuntimeError, "JSON Parse error -> #{json_file}"
|
40
|
-
end
|
36
|
+
node_data = JSON.parse(File.read(json_file))
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
merge_hashes(@secrets, node_data)
|
39
|
+
|
40
|
+
file_to_write = get_file_name(json_file)
|
41
|
+
files_updated << file_to_write
|
42
|
+
File.open(file_to_write, 'w') do |fh|
|
43
|
+
fh.puts JSON.pretty_generate(node_data)
|
44
|
+
fh.close
|
47
45
|
end
|
46
|
+
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
51
|
private
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
# Merge source into destination in-place
|
54
|
+
# Only where they have keys in common
|
55
|
+
# Taking care not to lose keys in destination but not source
|
56
|
+
def merge_hashes(source, destination)
|
57
|
+
source.each_key do |key|
|
58
|
+
|
59
|
+
if destination.has_key?(key)
|
60
|
+
|
61
|
+
case source[key]
|
62
|
+
when Hash
|
63
|
+
merge_hashes( source[key], destination[key] )
|
64
|
+
when String
|
65
|
+
destination[key] = source[key]
|
66
|
+
else
|
67
|
+
puts "Searching through source hash for a string but found #{source[key].class}"
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
|
59
71
|
end
|
72
|
+
|
73
|
+
end
|
60
74
|
end
|
61
75
|
|
62
76
|
def get_file_name(json_file)
|
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.4
|
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-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
- bin/s3crets
|
76
76
|
- lib/s3crets.rb
|
77
77
|
- lib/s3crets/version.rb
|
78
|
-
- lib/s3crets_dig.rb
|
79
78
|
- lib/s3crets_merge.rb
|
80
79
|
- s3crets.gemspec
|
81
80
|
homepage: ''
|
@@ -93,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
92
|
version: '0'
|
94
93
|
segments:
|
95
94
|
- 0
|
96
|
-
hash: -
|
95
|
+
hash: -2921035769767889780
|
97
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
97
|
none: false
|
99
98
|
requirements:
|
@@ -102,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
101
|
version: '0'
|
103
102
|
segments:
|
104
103
|
- 0
|
105
|
-
hash: -
|
104
|
+
hash: -2921035769767889780
|
106
105
|
requirements: []
|
107
106
|
rubyforge_project:
|
108
107
|
rubygems_version: 1.8.23
|