Class: CfnDslPipeline::Pipeline
- Inherits:
-
Object
- Object
- CfnDslPipeline::Pipeline
- Defined in:
- lib/params.rb,
lib/exec_cfndsl.rb,
lib/exec_syntax.rb,
lib/exec_cfn_nag.rb,
lib/cfndsl-pipeline.rb
Overview
Main pipeline
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
-
#input_filename ⇒ Object
Returns the value of attribute input_filename.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#output_filename ⇒ Object
Returns the value of attribute output_filename.
-
#s3_client ⇒ Object
Returns the value of attribute s3_client.
-
#syntax_report ⇒ Object
Returns the value of attribute syntax_report.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #build(input_filename, cfndsl_extras) ⇒ Object
- #exec_cfn_nag ⇒ Object
- #exec_cfndsl(cfndsl_extras) ⇒ Object
- #exec_dump_params ⇒ Object
- #exec_syntax_validation ⇒ Object
-
#initialize(output_dir, options) ⇒ Pipeline
constructor
A new instance of Pipeline.
Constructor Details
#initialize(output_dir, options) ⇒ Pipeline
Returns a new instance of Pipeline.
12 13 14 |
# File 'lib/exec_syntax.rb', line 12 def initialize self.s3_client = Aws::S3::Client.new(region: aws_region) end |
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def base_name @base_name end |
#input_filename ⇒ Object
Returns the value of attribute input_filename.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def input_filename @input_filename end |
#options ⇒ Object
Returns the value of attribute options.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def @options end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def output_dir @output_dir end |
#output_file ⇒ Object
Returns the value of attribute output_file.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def output_file @output_file end |
#output_filename ⇒ Object
Returns the value of attribute output_filename.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def output_filename @output_filename end |
#s3_client ⇒ Object
Returns the value of attribute s3_client.
10 11 12 |
# File 'lib/exec_syntax.rb', line 10 def s3_client @s3_client end |
#syntax_report ⇒ Object
Returns the value of attribute syntax_report.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def syntax_report @syntax_report end |
#template ⇒ Object
Returns the value of attribute template.
42 43 44 |
# File 'lib/cfndsl-pipeline.rb', line 42 def template @template end |
Instance Method Details
#build(input_filename, cfndsl_extras) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cfndsl-pipeline.rb', line 55 def build(input_filename, cfndsl_extras) abort "Input file #{input_filename} doesn't exist!" unless File.file?(input_filename) self.input_filename = input_filename.to_s self.base_name = File.basename(input_filename, '.*') self.output_filename = File.("#{output_dir}/#{base_name}.yaml") exec_cfndsl cfndsl_extras exec_syntax_validation if .validate_syntax exec_dump_params if .dump_deploy_params exec_cfn_nag if .validate_cfn_nag end |
#exec_cfn_nag ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/exec_cfn_nag.rb', line 10 def exec_cfn_nag puts 'Auditing template with cfn-nag...' configure_cfn_nag_logging cfn_nag = CfnNag.new(config: .cfn_nag) result = cfn_nag.audit(cloudformation_string: template) save_report result display_report result show_summary result end |
#exec_cfndsl(cfndsl_extras) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/exec_cfndsl.rb', line 10 def exec_cfndsl(cfndsl_extras) puts 'Generating CloudFormation template...' model = CfnDsl.eval_file_with_extras(@input_filename.to_s, cfndsl_extras, (.debug_cfndsl ? STDOUT : nil)) @template = JSON.parse(model.to_json).to_yaml File.open(@output_filename, 'w') do |file| file.puts @template end @output_file = File.open(@output_filename) puts "#{@output_file.size} bytes written to #{@output_filename}" end |
#exec_dump_params ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/params.rb', line 8 def exec_dump_params param_filename = "#{output_dir}/#{base_name}.params" puts "Deploy parameters written to #{param_filename}" param_file = File.open(File.(param_filename), 'w') syntax_report['parameters'].each do |param| param_file.puts "#{param['parameter_key']}=#{param['default_value']}" end end |
#exec_syntax_validation ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/exec_syntax.rb', line 16 def exec_syntax_validation puts 'Validating template syntax...' if .estimate_cost || (output_file.size > 51_200) puts 'Filesize is greater than 51200, or cost estimation required. Validating via S3 bucket ' uuid = UUID.new bucket = determine_bucket object_name = uuid.generate.to_s upload_template(bucket, object_name) self.syntax_report = s3_validate_syntax(bucket, object_name) estimate_cost(bucket_name, object_name) unless .validation_bucket puts 'Deleting temporary S3 bucket...' bucket.delete! end else self.syntax_report = local_validate_syntax end save_syntax_report end |