| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | module Devops | 
					
						
							|  |  |  |   module Model | 
					
						
							|  |  |  |     class StackTemplateEc2 < StackTemplateBase | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |       # In Amazon Cloudformation the template file must be stored on an Amazon S3 bucket. | 
					
						
							|  |  |  |       attr_accessor :template_url | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  |       # types template_url: {type: String, empty: false} | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def initialize(attrs) | 
					
						
							|  |  |  |         self.template_url = attrs['template_url'] | 
					
						
							|  |  |  |         super(attrs) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def to_hash_without_id | 
					
						
							|  |  |  |         super.merge(template_url: template_url) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       def delete_template_file_from_storage | 
					
						
							|  |  |  |         raise 'Implement me' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |       def update_template_url | 
					
						
							|  |  |  |         self.template_url = generate_template_file_and_upload_to_storage(id, template_body) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-01-21 20:10:36 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |       class << self | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |         def create(attrs) | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |           model = super(attrs) | 
					
						
							|  |  |  |           model.update_template_url | 
					
						
							|  |  |  |           model | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |       private | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |         def generate_template_file_and_upload_to_storage(id, json) | 
					
						
							| 
									
										
										
										
											2016-01-27 15:44:59 +03:00
										 |  |  |           uniq_filename = "#{id}-#{SecureRandom.hex}.template" | 
					
						
							|  |  |  |           provider_instance.store_stack_template(uniq_filename, json)['url'] | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |