@client_mtx = Mutex.new
end
- def api(resources_kind, action, data=nil)
+ def api(resources_kind, action, data=nil, tokens={})
+
profile_checkpoint
if not @api_client
# Use system CA certificates
@api_client.ssl_config.add_trust_ca('/etc/ssl/certs')
end
+ if Rails.configuration.api_response_compression
+ @api_client.transparent_gzip_decompression = true
+ end
end
end
url.sub! '/arvados/v1/../../', '/'
query = {
- 'api_token' => Thread.current[:arvados_api_token] || '',
- 'reader_tokens' => (Thread.current[:reader_tokens] || []).to_json,
+ 'api_token' => (tokens[:arvados_api_token] ||
+ Thread.current[:arvados_api_token] ||
+ ''),
+ 'reader_tokens' => ((tokens[:reader_tokens] ||
+ Thread.current[:reader_tokens] ||
+ []) +
+ [Rails.configuration.anonymous_user_token]).to_json,
}
if !data.nil?
data.each do |k,v|
elsif v == false
query[k] = 0
else
- query[k] = JSON.dump(v)
+ query[k] = Oj.dump(v, mode: :compat)
end
end
else
query["_method"] = "GET"
end
+
if @@profiling_enabled
query["_profile"] = "true"
end
header = {"Accept" => "application/json"}
- profile_checkpoint { "Prepare request #{url} #{query[:uuid]} #{query[:where]} #{query[:filters]}" }
+ profile_checkpoint { "Prepare request #{query["_method"] or "POST"} #{url} #{query[:uuid]} #{query.inspect[0,256]}" }
msg = @client_mtx.synchronize do
begin
@api_client.post(url, query, header: header)
end
end
profile_checkpoint 'API transaction'
+ if @@profiling_enabled
+ if msg.headers['X-Runtime']
+ Rails.logger.info "API server: #{msg.headers['X-Runtime']} runtime reported"
+ end
+ Rails.logger.info "Content-Encoding #{msg.headers['Content-Encoding'].inspect}, Content-Length #{msg.headers['Content-Length'].inspect}, actual content size #{msg.content.size}"
+ end
begin
resp = Oj.load(msg.content, :symbol_keys => true)
rescue Oj::ParseError
resp = nil
end
+
if not resp.is_a? Hash
raise InvalidApiResponseException.new(url, msg)
elsif msg.status_code != 200
CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s)
}.join('&')
end
+ uri
end
def arvados_logout_url(params={})