50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require 'securerandom'
 | |
| 
 | |
| module Devops
 | |
|   module Model
 | |
|     class StackTemplateEc2 < StackTemplateBase
 | |
| 
 | |
|       # In Amazon Cloudformation the template file must be stored on an Amazon S3 bucket.
 | |
|       attr_accessor :template_url
 | |
| 
 | |
|       def initialize(attrs)
 | |
|         self.template_url = attrs['template_url']
 | |
|         super(attrs)
 | |
|       end
 | |
| 
 | |
|       def to_hash_without_id
 | |
|         super.merge(template_url: template_url)
 | |
|       end
 | |
| 
 | |
|       def update_template_url
 | |
|         uniq_filename = "#{id}-#{SecureRandom.hex}.template"
 | |
|         s3_file = provider_instance.store_stack_template(uniq_filename, template_body)
 | |
|         self.template_url = s3_file['url']
 | |
|       end
 | |
| 
 | |
|       def parse_parameters
 | |
|         template_hash = JSON.parse(template_body)
 | |
|         return {} unless template_hash['Parameters']
 | |
| 
 | |
|         parameters = {}
 | |
|         template_hash['Parameters'].each do |param_name, param_info|
 | |
|           # use String always for now
 | |
|           parameters[param_name] = {'type' => 'String', 'description' => param_info['Description']}
 | |
|         end
 | |
|         parameters
 | |
|       rescue
 | |
|         {}
 | |
|       end
 | |
| 
 | |
|       class << self
 | |
|         def create(attrs)
 | |
|           model = super(attrs)
 | |
|           model.update_template_url
 | |
|           model
 | |
|         end
 | |
|       end
 | |
| 
 | |
|     end
 | |
|   end
 | |
| end
 |