Class: Sfn::Planner::Aws::Translator
- Inherits:
-
SparkleFormation::Translation
- Object
- SparkleFormation::Translation
- Sfn::Planner::Aws::Translator
- Defined in:
- lib/sfn/planner/aws.rb
Overview
Customized translator to dereference template
Instance Attribute Summary collapse
-
#flagged ⇒ Array<String>
readonly
Flagged items for value replacement.
Instance Method Summary collapse
-
#apply_function(hash, funcs = []) ⇒ Hash
Apply function if possible.
-
#dereference(hash) ⇒ Hash, String
Override the parent dereference behavior to return junk value on flagged resource match.
-
#flag_ref(ref_name) ⇒ Array<String>
Flag a reference as modified.
-
#flagged?(name) ⇒ TrueClass, FalseClass
Check if resource name is flagged.
-
#initialize(*_) ⇒ Translator
constructor
Override to init flagged array.
Constructor Details
#initialize(*_) ⇒ Translator
Override to init flagged array
20 21 22 23 |
# File 'lib/sfn/planner/aws.rb', line 20 def initialize(*_) super @flagged = [] end |
Instance Attribute Details
#flagged ⇒ Array<String> (readonly)
Returns flagged items for value replacement.
17 18 19 |
# File 'lib/sfn/planner/aws.rb', line 17 def flagged @flagged end |
Instance Method Details
#apply_function(hash, funcs = []) ⇒ Hash
Note:
also allows ‘Ref’ within funcs to provide mapping replacements using the REF_MAPPING constant
Apply function if possible
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sfn/planner/aws.rb', line 49 def apply_function(hash, funcs=[]) k,v = hash.first if(hash.size == 1 && (k.start_with?('Fn') || k == 'Ref') && (funcs.empty? || funcs.include?(k))) case k when 'Fn::Join' v.last.join(v.first) when 'Fn::FindInMap' map_holder = mappings[v[0]] if(map_holder) map_item = map_holder[dereference(v[1])] if(map_item) map_item[v[2]] else raise "Failed to find mapping item! (#{v[0]} -> #{v[1]})" end else raise "Failed to find mapping! (#{v[0]})" end when 'Fn::GetAtt' func.include?('DEREF') ? dereference(hash) : hash when 'Ref' if(funcs.include?('DEREF')) dereference(hash) else {'Ref' => self.class.const_get(:REF_MAPPING).fetch(v, v)} end else hash end else hash end end |
#dereference(hash) ⇒ Hash, String
Override the parent dereference behavior to return junk value on flagged resource match
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sfn/planner/aws.rb', line 88 def dereference(hash) result = nil if(hash.is_a?(Hash)) if(hash.keys.first == 'Ref' && flagged?(hash.values.first)) result = '__MODIFIED_REFERENCE_VALUE__' elsif(hash.keys.first == 'Fn::GetAtt') if(hash.values.last.last.start_with?('Outputs.')) if(flagged?(hash.values.join('_'))) result = '__MODIFIED_REFERENCE_VALUE__' end elsif(flagged?(hash.values.first)) result = '__MODIFIED_REFERENCE_VALUE__' end end end result.nil? ? super : result end |
#flag_ref(ref_name) ⇒ Array<String>
Flag a reference as modified
29 30 31 32 |
# File 'lib/sfn/planner/aws.rb', line 29 def flag_ref(ref_name) @flagged << ref_name.to_s @flagged.uniq! end |
#flagged?(name) ⇒ TrueClass, FalseClass
Check if resource name is flagged
38 39 40 |
# File 'lib/sfn/planner/aws.rb', line 38 def flagged?(name) @flagged.include?(name.to_s) end |