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 +4 -4
- data/Gemfile.lock +18 -16
- data/dh-proteus.gemspec +0 -1
- data/lib/proteus/commands/plan.rb +0 -1
- data/lib/proteus/modules/defaults_parser.rb +75 -0
- data/lib/proteus/modules/terraform_module.rb +7 -9
- data/lib/proteus/templates/partial.rb +18 -11
- data/lib/proteus/templates/template_binding.rb +2 -2
- data/lib/proteus/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d58675d1b1f45f3ca5711e42b3b52ab646b19e94c387d60184495a72e962a443
|
4
|
+
data.tar.gz: 39db3dcd0b1d7945ff90226ebbe42ccbb0d95020501af66a1f46ba467ed949b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
15
|
+
activesupport (5.1.7)
|
17
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (
|
17
|
+
i18n (>= 0.7, < 2)
|
19
18
|
minitest (~> 5.1)
|
20
19
|
tzinfo (~> 1.1)
|
21
|
-
aws-
|
22
|
-
aws-
|
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.
|
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
|
36
|
+
aws-sigv4 (1.1.0)
|
37
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
36
38
|
coderay (1.1.1)
|
37
|
-
concurrent-ruby (1.
|
39
|
+
concurrent-ruby (1.1.5)
|
38
40
|
diff-lcs (1.3)
|
39
41
|
erubis (2.7.0)
|
40
|
-
|
41
|
-
|
42
|
-
jmespath (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.
|
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.
|
66
|
+
thor (0.20.3)
|
65
67
|
thread_safe (0.3.6)
|
66
|
-
tzinfo (1.2.
|
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'
|
@@ -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 '
|
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
|
-
|
151
|
+
return [] unless File.file?(File.join(module_path(@context, @name), 'io.tf'))
|
151
152
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
101
|
-
say "
|
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
|
-
|
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(
|
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
|
-
|
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[:
|
111
|
-
say "CHANGED TO:
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
data/lib/proteus/version.rb
CHANGED
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
|
+
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-
|
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
|