Method: Sfn::CommandModule::Base::InstanceMethods#provider_for
- Defined in:
- lib/sfn/command_module/base.rb
#provider_for(location = nil) ⇒ Sfn::Provider Also known as: provider
Build provider connection for given location
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sfn/command_module/base.rb', line 25 def provider_for(location=nil) key = ['provider', location].compact.map(&:to_s).join('_') if(location) credentials = config.get(:locations, location) unless(credentials) raise ArgumentError.new "Failed to locate provider credentials for location `#{location}`!" end else credentials = config[:credentials] end begin memoize(key) do result = Sfn::Provider.new( :miasma => credentials, :async => false, :fetch => false ) result.connection.data[:stack_types] = ( [ (result.connection.class.const_get(:RESOURCE_MAPPING).detect do |klass, info| info[:api] == :orchestration end || []).first ] + custom_stack_types ).compact.uniq retry_config = config.fetch(:retry, config.fetch(:retries, {}) ) result.connection.data[:retry_ui] = ui result.connection.data[:location] = location.to_s result.connection.data[:locations] = config.fetch(:locations, {}) result.connection.data[:retry_type] = retry_config.fetch(:type, :exponential) result.connection.data[:retry_interval] = retry_config.fetch(:interval, 5) result.connection.data[:retry_max] = retry_config.fetch(:max_attempts, 20) result end rescue => e ui.error 'Failed to create remote API connection. Please validate configuration!' ui.error "Connection failure reason - #{e.class} - #{e}" raise end end |