Class: Jets::Cfn::Stack::Template

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/jets/cfn/stack/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Constructor Details

#initialize(options = {}) ⇒ Template

Returns a new instance of Template.



9
10
11
12
13
# File 'lib/jets/cfn/stack/template.rb', line 9

def initialize(options = {})
  @options = options
  @path = Jets::Names.parent_template_path
  @stack_name = Jets::Names.parent_stack_name
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/jets/cfn/stack/template.rb', line 8

def path
  @path
end

#stack_nameObject (readonly)

Returns the value of attribute stack_name.



8
9
10
# File 'lib/jets/cfn/stack/template.rb', line 8

def stack_name
  @stack_name
end

Instance Method Details

#bodyObject

Only use filesystem on initial bootstrap



33
34
35
# File 'lib/jets/cfn/stack/template.rb', line 33

def body
  IO.read(path)
end

#template_optionObject



15
16
17
18
19
20
21
# File 'lib/jets/cfn/stack/template.rb', line 15

def template_option
  if upload_to_s3?
    {template_url: url}
  else
    {template_body: body}
  end
end

#urlObject

uploads to s3 lazily on first call



24
25
26
27
28
29
# File 'lib/jets/cfn/stack/template.rb', line 24

def url
  s3_key = "jets/cfn/#{File.basename(path)}"
  object = s3_resource.bucket(s3_bucket).object(s3_key)
  object.upload_file(path)
  "https://s3.amazonaws.com/#{s3_bucket}/#{s3_key}"
end