Class: OpenStax::Aws::Template
- Inherits:
-
Object
- Object
- OpenStax::Aws::Template
- Defined in:
- lib/openstax/aws/template.rb
Defined Under Namespace
Classes: TemplateInvalid
Instance Attribute Summary collapse
-
#absolute_file_path ⇒ Object
readonly
Returns the value of attribute absolute_file_path.
Class Method Summary collapse
Instance Method Summary collapse
- #basename ⇒ Object
- #body ⇒ Object
- #erb? ⇒ Boolean
- #extname ⇒ Object
- #hash ⇒ Object
- #is_sam? ⇒ Boolean
- #parameter_names ⇒ Object
- #required_capabilities ⇒ Object
- #s3_folder ⇒ Object
- #s3_key ⇒ Object
- #s3_url ⇒ Object
- #upload_once ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#absolute_file_path ⇒ Object (readonly)
Returns the value of attribute absolute_file_path.
15 16 17 |
# File 'lib/openstax/aws/template.rb', line 15 def absolute_file_path @absolute_file_path end |
Class Method Details
.from_absolute_file_path(absolute_file_path) ⇒ Object
17 18 19 |
# File 'lib/openstax/aws/template.rb', line 17 def self.from_absolute_file_path(absolute_file_path) new(absolute_file_path: absolute_file_path) end |
.from_body(body) ⇒ Object
21 22 23 |
# File 'lib/openstax/aws/template.rb', line 21 def self.from_body(body) new(body: body) end |
Instance Method Details
#basename ⇒ Object
25 26 27 |
# File 'lib/openstax/aws/template.rb', line 25 def basename File.basename(absolute_file_path) end |
#body ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/openstax/aws/template.rb', line 37 def body return @body unless @body.nil? @body = File.read(absolute_file_path) @body = ERB.new(@body).tap { |erb| erb.filename = absolute_file_path }.result if erb? @body end |
#erb? ⇒ Boolean
33 34 35 |
# File 'lib/openstax/aws/template.rb', line 33 def erb? extname == '.erb' end |
#extname ⇒ Object
29 30 31 |
# File 'lib/openstax/aws/template.rb', line 29 def extname File.extname(absolute_file_path) end |
#hash ⇒ Object
45 46 47 |
# File 'lib/openstax/aws/template.rb', line 45 def hash json_hash || yml_hash || raise("Cannot read template #{absolute_file_path}") end |
#is_sam? ⇒ Boolean
102 103 104 |
# File 'lib/openstax/aws/template.rb', line 102 def is_sam? body.match(/Transform: .?AWS::Serverless/).present? end |
#parameter_names ⇒ Object
59 60 61 |
# File 'lib/openstax/aws/template.rb', line 59 def parameter_names hash["Parameters"].try(:keys) || [] end |
#required_capabilities ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/openstax/aws/template.rb', line 63 def required_capabilities has_an_iam_resource = hash["Resources"].any? do |resource_id, resource_body| resource_body["Type"].starts_with?("AWS::IAM::") end # A bit of a cop out to claim named_iam since we haven't checked # to see if any of the IAM resources have custom names, but it will # work has_an_iam_resource ? [:named_iam] : [] end |
#s3_folder ⇒ Object
82 83 84 85 86 |
# File 'lib/openstax/aws/template.rb', line 82 def s3_folder @unique_s3_folder ||= OpenStax::Aws.configuration.fixed_s3_template_folder || Time.now.utc.strftime("%Y%m%d_%H%M%S_#{SecureRandom.hex(4)}") end |
#s3_key ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/openstax/aws/template.rb', line 74 def s3_key [ OpenStax::Aws.configuration.cfn_template_bucket_folder, s3_folder, basename ].compact.join("/") end |
#s3_url ⇒ Object
88 89 90 91 |
# File 'lib/openstax/aws/template.rb', line 88 def s3_url upload_once "https://s3.amazonaws.com/#{OpenStax::Aws.configuration.cfn_template_bucket_name}/#{s3_key}" end |
#upload_once ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/openstax/aws/template.rb', line 93 def upload_once return if @uploaded validate upload @uploaded = true end |
#valid? ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'lib/openstax/aws/template.rb', line 49 def valid? begin validate rescue TemplateInvalid return false end true end |