Class: GoodData::Bricks::GoodDataMiddleware

Inherits:
Middleware
  • Object
show all
Defined in:
lib/gooddata/bricks/middleware/gooddata_middleware.rb

Instance Attribute Summary

Attributes inherited from Middleware

#app

Instance Method Summary collapse

Methods inherited from Middleware

#initialize, #load_defaults

Methods included from Utils

#returning

Constructor Details

This class inherits a constructor from GoodData::Bricks::Middleware

Instance Method Details

#call(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gooddata/bricks/middleware/gooddata_middleware.rb', line 12

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']
  verify_ssl = params['GDC_VERIFY_SSL'] == 'false' || params['GDC_VERIFY_SSL'] == false ? false : true

  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, verify_ssl: verify_ssl)
           else
             puts "Connecting as #{params['GDC_USERNAME']} to server #{server}"
             GoodData.connect(params['GDC_USERNAME'], params['GDC_PASSWORD'], server: server, verify_ssl: verify_ssl)
           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