Sha256: 1184e27592d6ed46a317da25697a7d6446d12ea1785c6e9d6630d4fe6b1ea832

Contents?: true

Size: 1.57 KB

Versions: 46

Compression:

Stored size: 1.57 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require 'aws-sdk-s3'
require_relative 'base_middleware'

module GoodData
  module Bricks
    class AWSMiddleware < Bricks::Middleware
      def call(params)
        params = params.to_hash
        if params.key?('aws_client')
          GoodData.logger.info('Setting up AWS-S3 connection')
          raise 'Unable to connect to AWS. Parameter "aws_client" seems to be empty' unless params['aws_client']
          raise 'Unable to connect to AWS. Parameter "access_key_id" is missing' if params['aws_client']['access_key_id'].blank?
          raise 'Unable to connect to AWS. Parameter "secret_access_key" is missing' if params['aws_client']['secret_access_key'].blank?
          params['aws_client'] = rewrite_for_aws_sdk_v2(params['aws_client'])
          symbolized_config = GoodData::Helpers.symbolize_keys(params['aws_client'])
          s3 = Aws::S3::Resource.new(symbolized_config)
          params['aws_client']['s3_client'] = s3
        end
        @app.call(params)
      end

      private

      def rewrite_for_aws_sdk_v2(config)
        config['region'] = 'us-west-2' unless config['region']
        if config['use_ssl']
          fail 'Parameter use_ssl has been deprecated. Version 2 of the AWS ' \
            'SDK uses SSL everywhere. To disable SSL you must ' \
            'configure an endpoint that uses http://.'
        end
        config
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
gooddata-1.3.6-java lib/gooddata/bricks/middleware/aws_middleware.rb
gooddata-1.3.6 lib/gooddata/bricks/middleware/aws_middleware.rb
gooddata-1.3.5-java lib/gooddata/bricks/middleware/aws_middleware.rb
gooddata-1.3.5 lib/gooddata/bricks/middleware/aws_middleware.rb
gooddata-1.3.4-java lib/gooddata/bricks/middleware/aws_middleware.rb
gooddata-1.3.4 lib/gooddata/bricks/middleware/aws_middleware.rb