Class: CfnDslPipeline::Pipeline
- Inherits:
-
Object
- Object
- CfnDslPipeline::Pipeline
- Defined in:
- lib/params.rb,
lib/run-cfndsl.rb,
lib/run-syntax.rb,
lib/run-cfn_nag.rb,
lib/cfndsl-pipeline.rb
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
-
#cfn_client ⇒ Object
Returns the value of attribute cfn_client.
-
#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.
11 12 13 14 |
# File 'lib/run-syntax.rb', line 11 def initialize self.cfn_client = Aws::CloudFormation::Client.new(region: self.aws_region) self.s3_client = Aws::S3::Client.new(region: self.aws_region) end |
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def base_name @base_name end |
#cfn_client ⇒ Object
Returns the value of attribute cfn_client.
9 10 11 |
# File 'lib/run-syntax.rb', line 9 def cfn_client @cfn_client end |
#input_filename ⇒ Object
Returns the value of attribute input_filename.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def input_filename @input_filename end |
#options ⇒ Object
Returns the value of attribute options.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def @options end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def output_dir @output_dir end |
#output_file ⇒ Object
Returns the value of attribute output_file.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def output_file @output_file end |
#output_filename ⇒ Object
Returns the value of attribute output_filename.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def output_filename @output_filename end |
#s3_client ⇒ Object
Returns the value of attribute s3_client.
9 10 11 |
# File 'lib/run-syntax.rb', line 9 def s3_client @s3_client end |
#syntax_report ⇒ Object
Returns the value of attribute syntax_report.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def syntax_report @syntax_report end |
#template ⇒ Object
Returns the value of attribute template.
41 42 43 |
# File 'lib/cfndsl-pipeline.rb', line 41 def template @template end |
Instance Method Details
#build(input_filename, cfndsl_extras) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cfndsl-pipeline.rb', line 54 def build(input_filename, cfndsl_extras) abort "Input file #{input_filename} doesn't exist!" if !File.file?(input_filename) self.input_filename = "#{input_filename}" self.base_name = File.basename(input_filename, '.*') self.output_filename = File.("#{self.output_dir}/#{self.base_name}.yaml") exec_cfndsl cfndsl_extras exec_syntax_validation if self..validate_syntax exec_dump_params if self..dump_deploy_params exec_cfn_nag if self..validate_cfn_nag end |
#exec_cfn_nag ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/run-cfn_nag.rb', line 7 def exec_cfn_nag puts "Auditing template with cfn-nag..." CfnNagLogging.configure_logging({:debug => self..debug_audit}) cfn_nag = CfnNag.new(config: self..cfn_nag) result = cfn_nag.audit(cloudformation_string: self.template) if self..save_audit_report audit_report = Capture.capture do SimpleStdoutResults.new.render([{ filename: output_filename, file_results: result }]) end audit_filename = "#{self.output_dir}/#{self.base_name}.audit" File.open(File.(audit_filename), 'w').puts audit_report['stdout'] puts "Saved audit report to #{audit_filename}" if result[:failure_count]>0 puts "Audit failed. #{result[:failure_count]} error(s) found ( ಠ ʖ̯ ಠ) ".red elsif result[:violations].count>0 puts "Audit passed with #{result[:warning_count]} warnings. (._.) ".yellow else puts "Audit passed! ヽ( ゚ヮ゚)/ ヽ(´ー`)ノ".green end else ColoredStdoutResults.new.render([{ filename: "cfn-nag results:", file_results: result }]) end end |
#exec_cfndsl(cfndsl_extras) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/run-cfndsl.rb', line 7 def exec_cfndsl(cfndsl_extras) print "Generating CloudFormation template...\n" model = CfnDsl.eval_file_with_extras("#{@input_filename}", cfndsl_extras) @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
6 7 8 9 10 11 12 13 |
# File 'lib/params.rb', line 6 def exec_dump_params param_filename = "#{self.output_dir}/#{self.base_name}.params" puts "Deploy parameters written to #{param_filename}" param_file = File.open(File.(param_filename), 'w') self.syntax_report['parameters'].each do | param | param_file.puts "#{param['parameter_key']}=#{Shellwords.escape(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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/run-syntax.rb', line 16 def exec_syntax_validation print "Validating template syntax...\n" if self..estimate_cost || (self.output_file.size > 51200) puts "Filesize is greater than 51200, or cost estimation required. Validating via S3 bucket " uuid = UUID.new object_name = "#{uuid.generate}" if self..validation_bucket bucket_name = self..validation_bucket puts "Using existing S3 bucket #{bucket_name}..." bucket = self.s3_client.bucket(self..validation_bucket) else bucket_name = "arch-code-#{uuid.generate}" puts "Creating temporary S3 bucket #{bucket_name}..." bucket = self.s3_client.bucket(bucket_name) bucket.create end upload_template(bucket, object_name) self.syntax_report = s3_validate_syntax(bucket, object_name) if self..estimate_cost estimate_cost(bucket_name, object_name) end if !self..validation_bucket puts "Deleting temporary S3 bucket..." bucket.delete! end else self.syntax_report = local_validate_syntax end save_syntax_report if self..save_syntax_report end |