Sha256: eecbcb96123612e880af1ed77704a1fece6c0369cf1ca1c6fef30c7d5d1adf38

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2015 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_relative 'base_middleware'

module GoodData
  module Bricks
    class GoodDataMiddleware < Bricks::Middleware
      def call(params)
        params = params.to_hash
        logger = params['GDC_LOGGER']
        token_name = 'GDC_SST'
        protocol_name = 'CLIENT_GDC_PROTOCOL'
        server_name = 'CLIENT_GDC_HOSTNAME'
        project_id = params['GDC_PROJECT_ID']

        server = if params[protocol_name] && params[server_name]
                   "#{params[protocol_name]}://#{params[server_name]}"
                 end

        client = if params['GDC_USERNAME'].nil? || params['GDC_PASSWORD'].nil?
                   puts "Connecting with SST to server #{server}"
                   raise 'SST (SuperSecureToken) not present in params' if params[token_name].nil?
                   GoodData.connect(sst_token: params[token_name], server: server)
                 else
                   puts "Connecting as #{params['GDC_USERNAME']} to server #{server}"
                   GoodData.connect(params['GDC_USERNAME'], params['GDC_PASSWORD'], server: server)
                 end
        project = client.projects(project_id)
        GoodData.project = project
        GoodData.logger = logger
        returning_value = @app.call(params.merge('GDC_GD_CLIENT' => client, 'gdc_project' => project))
        begin
          client.disconnect
        rescue
          puts 'Tried to disconnect. Was unsuccesfull. Proceeding anyway.'
        end
        returning_value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gooddata-bricks-0.3.0 lib/gooddata/bricks/middleware/gooddata_middleware.rb