Class: Lono::Cfn::Download
Instance Method Summary
collapse
#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts
#rollback_complete?, #testing_update?
#find_stack_set, #stack_set_exists?
#find_stack, #stack_exists?
#initialize, #reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#convert_to_yaml(body) ⇒ Object
35
36
37
|
# File 'lib/lono/cfn/download.rb', line 35
def convert_to_yaml(body)
json?(body) ? YAML.dump(JSON.parse(body)) : body
end
|
#download_path ⇒ Object
43
44
45
|
# File 'lib/lono/cfn/download.rb', line 43
def download_path
"#{Lono.config.output_path}/#{@blueprint}/templates/#{@blueprint}.yml"
end
|
#download_stack ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/lono/cfn/download.rb', line 22
def download_stack
source = @options[:source]
if source
open(source).read
else
resp = cfn.get_template(
stack_name: @stack,
template_stage: "Original"
)
resp.template_body
end
end
|
#download_template ⇒ Object
15
16
17
18
19
20
|
# File 'lib/lono/cfn/download.rb', line 15
def download_template
body = download_stack
body = convert_to_yaml(body)
FileUtils.mkdir_p(File.dirname(download_path))
IO.write(download_path, body)
end
|
#json?(body) ⇒ Boolean
39
40
41
|
# File 'lib/lono/cfn/download.rb', line 39
def json?(body)
!!JSON.parse(body) rescue false
end
|
#name ⇒ Object
47
48
49
|
# File 'lib/lono/cfn/download.rb', line 47
def name
@options[:name] || @stack
end
|
#run ⇒ Object
8
9
10
11
12
13
|
# File 'lib/lono/cfn/download.rb', line 8
def run
pretty_path = download_path.sub("#{Lono.root}/", '')
puts "Downloading template to: #{pretty_path}"
return if @options[:noop]
download_template
end
|