dh-proteus 0.1.4 → 0.1.7

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: 930202b74f9134b4fb637892037c7f2f4449571c3d0ca48bd4b19f05bd5567dc
4
- data.tar.gz: e05fc63704777527d50a7e693268b00f0caea3d5c8ba58e62b6f2328b1425d5b
3
+ metadata.gz: d58675d1b1f45f3ca5711e42b3b52ab646b19e94c387d60184495a72e962a443
4
+ data.tar.gz: 39db3dcd0b1d7945ff90226ebbe42ccbb0d95020501af66a1f46ba467ed949b9
5
5
  SHA512:
6
- metadata.gz: 5151d852874d76fdd54aee52ed5946f8f8a900e2a29fb5ae85ed76e5fb990cb20014c3adf2a2c5a840fb10f5d06aec8ed0a418f3e39f1e875a76d234c43fae63
7
- data.tar.gz: 35315dffe3c11aba65d0e4fff11a3b548615ea76b8605825b9fc6e19cf5562aac1f11a29fbec7fd471181f4baf19738e5c51bcfd538d263de9b5c3640583cf09
6
+ metadata.gz: f08aa1849fffa7c13f4ea7399d6ae4522dac58cea95926dffe36428a946c08c9bc48cc661802c783a060072ec6bf5293c3396f5af2794e6b076e0c039b0e4a2d
7
+ data.tar.gz: 366e2801c64b8c9967744e716b441882bf31c18eca254926ecbd3f6e990553f53d7b202ac11b014c769db5a4fb2f7c9dabea017a15a8310739a19b9084e9d063
data/Gemfile.lock CHANGED
@@ -1,27 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proteus (0.1.3)
4
+ dh-proteus (0.1.4)
5
5
  activesupport (~> 5.1.1)
6
6
  aws-sdk-elasticsearchservice (~> 1.4.0)
7
7
  aws-sdk-rds (~> 1.11.0)
8
8
  aws-sdk-route53 (~> 1.7.0)
9
9
  erubis (~> 2.7.0)
10
- hcl-checker (~> 1.0.5)
11
10
  thor (~> 0.20.0)
12
11
 
13
12
  GEM
14
13
  remote: https://rubygems.org/
15
14
  specs:
16
- activesupport (5.1.1)
15
+ activesupport (5.1.7)
17
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
17
+ i18n (>= 0.7, < 2)
19
18
  minitest (~> 5.1)
20
19
  tzinfo (~> 1.1)
21
- aws-partitions (1.60.0)
22
- aws-sdk-core (3.15.0)
20
+ aws-eventstream (1.0.3)
21
+ aws-partitions (1.189.0)
22
+ aws-sdk-core (3.59.0)
23
+ aws-eventstream (~> 1.0, >= 1.0.2)
23
24
  aws-partitions (~> 1.0)
24
- aws-sigv4 (~> 1.0)
25
+ aws-sigv4 (~> 1.1)
25
26
  jmespath (~> 1.0)
26
27
  aws-sdk-elasticsearchservice (1.4.0)
27
28
  aws-sdk-core (~> 3)
@@ -32,16 +33,17 @@ GEM
32
33
  aws-sdk-route53 (1.7.0)
33
34
  aws-sdk-core (~> 3)
34
35
  aws-sigv4 (~> 1.0)
35
- aws-sigv4 (1.0.2)
36
+ aws-sigv4 (1.1.0)
37
+ aws-eventstream (~> 1.0, >= 1.0.2)
36
38
  coderay (1.1.1)
37
- concurrent-ruby (1.0.5)
39
+ concurrent-ruby (1.1.5)
38
40
  diff-lcs (1.3)
39
41
  erubis (2.7.0)
40
- hcl-checker (1.0.5)
41
- i18n (0.8.1)
42
- jmespath (1.3.1)
42
+ i18n (1.6.0)
43
+ concurrent-ruby (~> 1.0)
44
+ jmespath (1.4.0)
43
45
  method_source (0.8.2)
44
- minitest (5.10.3)
46
+ minitest (5.11.3)
45
47
  pry (0.10.4)
46
48
  coderay (~> 1.1.0)
47
49
  method_source (~> 0.8.1)
@@ -61,9 +63,9 @@ GEM
61
63
  rspec-support (~> 3.8.0)
62
64
  rspec-support (3.8.0)
63
65
  slop (3.6.0)
64
- thor (0.20.0)
66
+ thor (0.20.3)
65
67
  thread_safe (0.3.6)
66
- tzinfo (1.2.3)
68
+ tzinfo (1.2.5)
67
69
  thread_safe (~> 0.1)
68
70
 
69
71
  PLATFORMS
@@ -71,7 +73,7 @@ PLATFORMS
71
73
 
72
74
  DEPENDENCIES
73
75
  bundler (~> 2.0)
74
- proteus!
76
+ dh-proteus!
75
77
  pry
76
78
  rake (~> 10.0)
77
79
  rspec (~> 3.0)
data/dh-proteus.gemspec CHANGED
@@ -43,7 +43,6 @@ Gem::Specification.new do |spec|
43
43
  spec.add_runtime_dependency 'activesupport', '~> 5.1.1'
44
44
  spec.add_runtime_dependency 'thor', '~> 0.20.0'
45
45
  spec.add_runtime_dependency 'erubis', '~> 2.7.0'
46
- spec.add_runtime_dependency 'hcl-checker', '~> 1.0.5'
47
46
  spec.add_runtime_dependency 'aws-sdk-rds', '~> 1.11.0'
48
47
  spec.add_runtime_dependency 'aws-sdk-route53', '~> 1.7.0'
49
48
  spec.add_runtime_dependency 'aws-sdk-elasticsearchservice', '~> 1.4.0'
@@ -39,7 +39,6 @@ module Proteus
39
39
  #{"-destroy" if options[:destroy]} \
40
40
  -input=false \
41
41
  -refresh=true \
42
- -module-depth=-1 \
43
42
  -var-file=#{var_file(context, environment)} \
44
43
  -out=#{plan_file(context, environment)} \
45
44
  #{aws_profile} #{limit(options[:limit])} \
@@ -0,0 +1,75 @@
1
+ module Proteus
2
+ module Modules
3
+ class DefaultsParser
4
+ attr_reader :variables
5
+
6
+ def initialize(input)
7
+ @hcl = input
8
+ @variables = {}
9
+ end
10
+
11
+ def parse_variables
12
+ lines = @hcl.split("\n")
13
+ lines.reject! { |l| l.start_with?("#") }
14
+
15
+ lines.each_with_index do |line, index|
16
+ if line =~ /^variable/
17
+ # ignore mandatory variables
18
+ if line =~ /{/ && line =~ /}/
19
+ next
20
+ end
21
+
22
+ variable_lines = find_variable_range(lines, index)
23
+
24
+ if variable_lines && variable_lines.any?
25
+ variable = evaluate_variable(variable_lines)
26
+
27
+ @variables.merge!({variable[:name] => variable[:value]}) unless variable.nil?
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ protected
34
+
35
+ # finds range of lines relevant to a single variable.
36
+ # returns nil if the default value is non scalar
37
+ def find_variable_range(lines, start_index)
38
+ closing_brace_index = 0
39
+
40
+ lines[start_index..-1].each_with_index do |line, idx|
41
+
42
+ # ignore maps and lists
43
+ if line =~ /default/ && (line =~ /\[/ || line =~ /\{/)
44
+ return nil
45
+ end
46
+
47
+ if line =~ /^\}$/
48
+ closing_brace_index = idx
49
+ break
50
+ end
51
+ end
52
+
53
+ lines[start_index..start_index + closing_brace_index]
54
+ end
55
+
56
+ def evaluate_variable(lines)
57
+ variable = {}
58
+
59
+ variable[:name] = lines[0].match(/variable "(.+)"/)[1]
60
+ lines.each do |line|
61
+ next if line =~ /type/ || line =~ /description/
62
+
63
+ if match_data = line.match(/=(.+)/)
64
+ variable[:value] = match_data[1].gsub('"','').lstrip.rstrip
65
+ break
66
+ end
67
+ end
68
+
69
+ return variable if variable.key?(:value)
70
+
71
+ nil
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,7 +1,8 @@
1
1
  require 'proteus/helpers/path_helpers'
2
2
  require 'proteus/helpers/string_helpers'
3
- require 'hcl/checker'
3
+ require 'proteus/modules/defaults_parser'
4
4
  require 'yaml'
5
+ require 'fileutils'
5
6
 
6
7
  module Proteus
7
8
  module Modules
@@ -147,15 +148,12 @@ module Proteus
147
148
  end
148
149
 
149
150
  def parse_defaults
150
- defaults = []
151
+ return [] unless File.file?(File.join(module_path(@context, @name), 'io.tf'))
151
152
 
152
- return defaults unless File.file?(File.join(module_path(@context, @name), 'io.tf'))
153
- HCL::Checker.parse(File.read(File.join(module_path(@context, @name), 'io.tf')))['variable'].each do |variable, values|
154
- if values
155
- defaults.push(variable) if values.has_key?('default')
156
- end
157
- end
158
- return defaults
153
+ defaults_parser = DefaultsParser.new(File.read(File.join(module_path(@context, @name), 'io.tf')))
154
+ defaults_parser.parse_variables
155
+
156
+ return defaults_parser.variables
159
157
  end
160
158
 
161
159
  def global_resources
@@ -97,21 +97,28 @@ module Proteus
97
97
  def scope_resources(manifest:, scope:)
98
98
  scoped = []
99
99
  manifest.each_line do |line|
100
- if matches = line.match(/resource( +)"(?<resource_type>[a-z0-9_]+)"( +)"(?<resource_name>[a-zA-Z0-9_\-]+)"( +)(\{)/)
101
- say "MATCHED RESOURCE: #{line}", :green
100
+ if line.include?('proteus:noscope')
101
+ say "NOT SCOPING: #{line}", :green
102
+ scoped << line.gsub(/( *)#( *)proteus:noscope/, '')
103
+ next
104
+ end
105
+
106
+ if matches = line.match(/(?<rd>resource|data)( +)"(?<resource_type>[a-z0-9_]+)"( +)"(?<resource_name>[a-zA-Z0-9_\-]+)"( *)(\{)/)
102
107
  matches = matches.named_captures.with_indifferent_access
103
- scoped << "resource \"#{matches[:resource_type]}\" \"#{scope}_#{matches[:resource_name]}\" {"
108
+ say "MATCHED RESOURCE: #{matches[:rd].upcase}", :green
109
+ scoped << "#{matches[:rd]} \"#{matches[:resource_type]}\" \"#{scope}_#{matches[:resource_name]}\" {"
104
110
  say "CHANGED TO: #{scoped.last}", :green
105
- elsif matches = line.match(/(?<pre>.*(\{|\())(?<data>data\.)?(?<resource_type>(?<provider>aws|kubernetes|helm|tls_private_key|null_resource)[a-z_0-9]*)\.(?<resource_name>[a-z0-9_]+)(?<attribute>(?<wildcard>.\*)?\.[a-z_]+)?(?<post>.*)?/)
106
- matches = matches.named_captures.with_indifferent_access
111
+ elsif matches = line.match(/^(?<pre>\s+)?(?<left>[a-z_]+)(?<eq>[= ]+)(?<lbracket>\[)?(?<lparen>"\${)?(?<funcbeg>([a-z]+\()*)?(?<data>data\.)?(?<resource_type>[a-z_0-9]+)\.(?<resource_name>[a-z_0-9-]+)\.(?<wildcard>\*.)?(?<resource_attribute>[a-z_]+)(?<rparen>}")?(?<post>.*)?/)
107
112
 
108
- if !matches[:data]
113
+ matches = matches.named_captures.with_indifferent_access
114
+ #if !matches[:data]
109
115
  say "MATCHED REFERENCE: #{line}", :green
110
- scoped << "#{matches[:pre]}#{matches[:resource_type]}.#{scope}_#{matches[:resource_name]}#{matches[:attribute]}#{matches[:post]}"
111
- say "CHANGED TO: #{scoped.last}", :green
112
- else
113
- scoped << line
114
- end
116
+ scoped << "#{matches[:pre]}#{matches[:left]}#{matches[:eq]}#{matches[:lbracket]}#{matches[:lparen]}#{matches[:funcbeg]}#{matches[:data]}#{matches[:resource_type]}.#{scope}_#{matches[:resource_name]}.#{matches[:wildcard]}#{matches[:resource_attribute]}#{matches[:rparen]}#{matches[:post]}"
117
+ say "CHANGED TO: #{scoped.last}", :green
118
+ elsif matches = line.match(/(?<resource>(?<data>data\.)?(?<resource_type>(?<provider>aws|helm|local)[a-z_0-9]+)\.(?<resource_name>[a-z\-_0-9]+)\.(?<resource_attribute>[a-z_]+))/)
119
+ say "MATCHED RESOURCE REFERENCE: #{line}", :green
120
+ scoped << line.gsub(matches[:resource], "#{matches[:data]}#{matches[:resource_type]}.#{scope}_#{matches[:resource_name]}.#{matches[:resource_attribute]}")
121
+ say "CHANGED TO: #{scoped.last}", :green
115
122
  else
116
123
  scoped << line
117
124
  end
@@ -26,8 +26,8 @@ module Proteus
26
26
 
27
27
  def render_defaults(context, demo: false)
28
28
  @defaults.inject("") do |memo, default|
29
- if context.has_key?(default)
30
- memo << "#{demo ? "# " : ""}#{default} = \"#{context[default]}\"\n"
29
+ if context.has_key?(default[0])
30
+ memo << "#{demo ? "# " : ""}#{default[0]} = \"#{context[default[0]]}\"\n"
31
31
  else
32
32
  memo
33
33
  end
@@ -1,5 +1,5 @@
1
1
  module Proteus
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.7"
3
3
  end
4
4
 
5
5
  if $0 == __FILE__
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dh-proteus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Albrecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-04 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.7.0
111
- - !ruby/object:Gem::Dependency
112
- name: hcl-checker
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 1.0.5
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 1.0.5
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: aws-sdk-rds
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +206,7 @@ files:
220
206
  - lib/proteus/helpers/path_helpers.rb
221
207
  - lib/proteus/helpers/string_helpers.rb
222
208
  - lib/proteus/init.rb
209
+ - lib/proteus/modules/defaults_parser.rb
223
210
  - lib/proteus/modules/manager.rb
224
211
  - lib/proteus/modules/terraform_module.rb
225
212
  - lib/proteus/templates/partial.rb