Class: Bora::Resolver::Cfn
- Inherits:
-
Object
- Object
- Bora::Resolver::Cfn
- Defined in:
- lib/bora/resolver/cfn.rb
Constant Summary collapse
- StackDoesNotExist =
Class.new(StandardError)
- ValueNotFound =
Class.new(StandardError)
- InvalidParameter =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(stack) ⇒ Cfn
constructor
A new instance of Cfn.
- #resolve(uri) ⇒ Object
Constructor Details
#initialize(stack) ⇒ Cfn
Returns a new instance of Cfn.
10 11 12 13 |
# File 'lib/bora/resolver/cfn.rb', line 10 def initialize(stack) @stack = stack @stack_cache = {} end |
Instance Method Details
#resolve(uri) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bora/resolver/cfn.rb', line 15 def resolve(uri) stack_name = uri.host section, name = uri.path.split('/').reject(&:empty?) if !stack_name || !section || !name || section != 'outputs' raise InvalidParameter, "Invalid parameter substitution: #{uri}" end stack_name, uri_region = stack_name.split('.') region = uri_region || @stack.region param_stack = @stack_cache[stack_name] || Bora::Cfn::Stack.new(stack_name, region) unless param_stack.exists? raise StackDoesNotExist, "Output #{name} not found in stack #{stack_name} as the stack does not exist" end outputs = param_stack.outputs || [] matching_output = outputs.find { |output| output.key == name } unless matching_output raise ValueNotFound, "Output #{name} not found in stack #{stack_name}" end matching_output.value end |