cfhighlander 0.2.1.alpha.43 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,177 +0,0 @@
1
- require 'yaml'
2
-
3
- module Cfhighlander
4
-
5
- module Model
6
-
7
- class Component
8
-
9
- attr_accessor :component_dir,
10
- :config,
11
- :highlander_dsl_path,
12
- :cfndsl_path,
13
- :highlander_dsl,
14
- :cfndsl_content,
15
- :mappings,
16
- :name,
17
- :template,
18
- :version,
19
- :distribution_bucket,
20
- :distribution_prefix,
21
- :component_files,
22
- :cfndsl_ext_files,
23
- :lambda_src_files
24
-
25
- attr_reader :cfn_model, :outputs
26
-
27
- def initialize(template_meta, component_name)
28
- @template = template_meta
29
- @name = component_name
30
- @component_dir = template_meta.template_location
31
- @mappings = {}
32
- @version = template_meta.template_version
33
- @distribution_bucket = nil
34
- @distribution_prefix = nil
35
- @component_files = []
36
- @cfndsl_ext_files = []
37
- @lambda_src_files = []
38
- end
39
-
40
- # load component configuration files
41
- def load_config()
42
- @config = {} if @config.nil?
43
- Dir["#{@component_dir}/*.config.yaml"].each do |config_file|
44
- puts "INFO Loading config for #{@name}: read file:#{config_file} "
45
- partial_config = YAML.load(File.read(config_file))
46
- unless partial_config.nil?
47
- @config.extend(partial_config)
48
- @component_files << config_file
49
- end
50
- end
51
- end
52
-
53
- # load extensions
54
- def loadDepandantExt()
55
- @highlander_dsl.dependson_components.each do |requirement|
56
- requirement.component_loaded.cfndsl_ext_files.each do |file|
57
- cfndsl_ext_files << file
58
- end
59
- end
60
- end
61
-
62
- # evaluate components template
63
- # @param [Hash] config_override
64
- def load(config_override = nil)
65
- if @component_dir.start_with? 'http'
66
- raise StandardError, 'http(s) sources not supported yet'
67
- end
68
-
69
- legacy_cfhighlander_path = "#{@component_dir}/#{@template.template_name}.highlander.rb"
70
- if File.exist? legacy_cfhighlander_path
71
- STDERR.puts "DEPRECATED: #{legacy_cfhighlander_path} - Use *.cfhiglander.rb"
72
- @highlander_dsl_path = legacy_cfhighlander_path
73
- else
74
- @highlander_dsl_path = "#{@component_dir}/#{@template.template_name}.cfhighlander.rb"
75
- end
76
-
77
- @cfndsl_path = "#{@component_dir}/#{@template.template_name}.cfndsl.rb"
78
- candidate_mappings_path = "#{@component_dir}/*.mappings.yaml"
79
- candidate_dynamic_mappings_path = "#{@component_dir}/#{@template.template_name}.mappings.rb"
80
-
81
- @cfndsl_ext_files += Dir["#{@component_dir}/ext/cfndsl/*.rb"]
82
- @lambda_src_files += Dir["#{@component_dir}/lambdas/**/*"].find_all {|p| not File.directory? p}
83
- @component_files += @cfndsl_ext_files
84
- @component_files += @lambda_src_files
85
-
86
- @config = {} if @config.nil?
87
-
88
- @config.extend config_override unless config_override.nil?
89
- @config['component_version'] = @version unless @version.nil?
90
- @config['component_name'] = @name
91
- @config['template_name'] = @template.template_name
92
- @config['template_version'] = @template.template_version
93
-
94
-
95
- Dir[candidate_mappings_path].each do |mapping_file|
96
- mappings = YAML.load(File.read(mapping_file))
97
- @component_files << mapping_file
98
- mappings.each do |name, map|
99
- @mappings[name] = map
100
- end unless mappings.nil?
101
- end
102
-
103
- if File.exist? candidate_dynamic_mappings_path
104
- require candidate_dynamic_mappings_path
105
- @component_files << candidate_dynamic_mappings_path
106
- end
107
-
108
- # 1st pass - parse the file
109
- @component_files << @highlander_dsl_path
110
- @highlander_dsl = eval(File.read(@highlander_dsl_path), binding)
111
- # set version if not defined
112
- @highlander_dsl.ComponentVersion(@version) unless @version.nil?
113
-
114
-
115
- if @highlander_dsl.description.nil?
116
- if template.template_name == @name
117
- description = "#{@name}@#{template.template_version} - v#{@highlander_dsl.version}"
118
- else
119
- description = "#{@name} - v#{@highlander_dsl.version}"
120
- description += " (#{template.template_name}@#{template.template_version})"
121
- end
122
-
123
- @highlander_dsl.Description(description)
124
- end
125
-
126
- # set (override) distribution options
127
- @highlander_dsl.DistributionBucket(@distribution_bucket) unless @distribution_bucket.nil?
128
- @highlander_dsl.DistributionPrefix(@distribution_prefix) unless @distribution_prefix.nil?
129
-
130
- if File.exist? @cfndsl_path
131
- @component_files << @cfndsl_path
132
- @cfndsl_content = File.read(@cfndsl_path)
133
- @cfndsl_content.strip!
134
- # if there is CloudFormation do [content] end extract only contents
135
- ### Regex \s is whitespace
136
- match_data = /^CloudFormation do\s(.*)end\s?$/m.match(@cfndsl_content)
137
- if not match_data.nil?
138
- @cfndsl_content = match_data[1]
139
- end
140
-
141
- else
142
- @cfndsl_content = ''
143
- end
144
-
145
- loadDepandantExt()
146
- end
147
-
148
- # evaluates cfndsl with current config
149
- def eval_cfndsl
150
- compiler = Cfhighlander::Compiler::ComponentCompiler.new self
151
- @cfn_model = compiler.evaluateCloudFormation().as_json
152
- @outputs = (
153
- if @cfn_model.key? 'Outputs'
154
- then
155
- @cfn_model['Outputs'].map {|k, v| ComponentOutput.new self, k, v}
156
- else
157
- []
158
- end
159
- )
160
- end
161
- end
162
-
163
- class ComponentOutput
164
-
165
- attr_reader :component, :name, :value
166
-
167
- def initialize(component, name, value)
168
- @component = component
169
- @name = name
170
- @value = value
171
- end
172
- end
173
-
174
- end
175
-
176
- end
177
-
@@ -1,25 +0,0 @@
1
- module Cfhighlander
2
-
3
- module Model
4
-
5
- class TemplateMetadata
6
-
7
- @template_name
8
- @template_version
9
- @template_location
10
-
11
- attr_reader :template_location,
12
- :template_version,
13
- :template_name
14
-
15
- def initialize(template_name:, template_version:, template_location:)
16
- @template_name = template_name
17
- @template_version = template_version
18
- @template_location = template_location
19
- end
20
-
21
- end
22
-
23
- end
24
-
25
- end