s3crets 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module S3crets
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/s3crets_merge.rb CHANGED
@@ -22,34 +22,29 @@ class Configuratron
22
22
  end
23
23
 
24
24
  def replace_config(dir)
25
-
26
- search_folder = File.expand_path(dir)
27
- files = Dir.glob(search_folder + "/*.json")
25
+ counter = 0
26
+ search_folder = File.expand_path(dir)
27
+ files = Dir.glob(search_folder + "/*.json")
28
28
 
29
29
  if files.empty?
30
30
  puts "Was unable to find any JSON files [#{search_folder}]"
31
31
  else
32
+
32
33
  Dir.glob(File.expand_path(dir) + "/*.json") do |json_file|
33
34
 
34
35
  next if json_file =~ /.new./
35
36
 
36
- @secrets.keys.each do |k|
37
-
38
- node_data = JSON.parse(File.read(json_file))
39
-
40
- if node_data.dig(k)
41
-
42
- json = node_data.merge({
43
- k => node_data[k].merge!(@secrets[k])
44
- })
37
+ begin
38
+ node_data = JSON.parse(File.read(json_file)+".")
39
+ rescue JSON::ParserError => e
40
+ raise RuntimeError, "JSON Parse error -> #{json_file}"
41
+ end
45
42
 
46
- file_to_write = get_file_name(json_file)
47
- files_updated << file_to_write
48
- File.open(file_to_write, 'w') do |fh|
49
- fh.puts JSON.pretty_generate(json)
50
- fh.close
51
- end
52
- end
43
+ # See if keys have intersection
44
+ unless (@secrets.keys & node_data.keys).empty?
45
+ node_data.merge! @secrets.select { |k| node_data.keys.include? k }
46
+ file_to_write = get_file_name(json_file)
47
+ write_file(file_to_write,node_data)
53
48
  end
54
49
  end
55
50
  end
@@ -57,6 +52,14 @@ class Configuratron
57
52
 
58
53
  private
59
54
 
55
+ def write_file(file,data)
56
+ @files_updated << file
57
+ File.open(file, 'w') do |fh|
58
+ fh.puts JSON.pretty_generate(data)
59
+ fh.close
60
+ end
61
+ end
62
+
60
63
  def get_file_name(json_file)
61
64
  f = File.split(json_file)
62
65
  path = f[0]
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.1
4
+ version: 0.0.2
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-07 00:00:00.000000000 Z
12
+ date: 2013-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: -3663029455517111644
96
+ hash: 929723293801486723
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: -3663029455517111644
105
+ hash: 929723293801486723
106
106
  requirements: []
107
107
  rubyforge_project:
108
108
  rubygems_version: 1.8.23