[ARVADOS] updated: f90679d93de9a4bf7dd741b79e9da62a4b7bd4a2
git at public.curoverse.com
git at public.curoverse.com
Mon Dec 30 17:02:37 EST 2013
Summary of changes:
apps/workbench/Gemfile | 1 +
apps/workbench/Gemfile.lock | 2 +
apps/workbench/app/models/arvados_api_client.rb | 80 ++++++++++++++---------
3 files changed, 53 insertions(+), 30 deletions(-)
via f90679d93de9a4bf7dd741b79e9da62a4b7bd4a2 (commit)
from 1e8f93a86465bce9bf6b32245ef99932c3cbfe08 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit f90679d93de9a4bf7dd741b79e9da62a4b7bd4a2
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Mon Dec 30 17:03:03 2013 -0500
Replaces shelling out to 'curl' with httpclient library.
diff --git a/apps/workbench/Gemfile b/apps/workbench/Gemfile
index 7035736..b947c81 100644
--- a/apps/workbench/Gemfile
+++ b/apps/workbench/Gemfile
@@ -52,3 +52,4 @@ gem 'andand'
gem 'RedCloth'
gem 'piwik_analytics'
+gem 'httpclient'
diff --git a/apps/workbench/Gemfile.lock b/apps/workbench/Gemfile.lock
index 26e0af1..697f15a 100644
--- a/apps/workbench/Gemfile.lock
+++ b/apps/workbench/Gemfile.lock
@@ -56,6 +56,7 @@ GEM
execjs (2.0.2)
highline (1.6.20)
hike (1.2.3)
+ httpclient (2.3.4.1)
i18n (0.6.5)
journey (1.0.4)
jquery-rails (3.0.4)
@@ -156,6 +157,7 @@ DEPENDENCIES
anjlab-bootstrap-rails (~> 2.3)
bootstrap-editable-rails
coffee-rails (~> 3.2.0)
+ httpclient
jquery-rails
less
less-rails
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 077bbbf..1504fdc 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -1,40 +1,60 @@
+require 'httpclient'
+require 'thread'
+
class ArvadosApiClient
class NotLoggedInException < StandardError
end
class InvalidApiResponseException < StandardError
end
+
+ @@client_mtx = Mutex.new
+ @@api_client = nil
+
def api(resources_kind, action, data=nil)
- arvados_api_token = Thread.current[:arvados_api_token]
- arvados_api_token = '' if arvados_api_token.nil?
- dataargs = ['--data-urlencode',
- "api_token=#{arvados_api_token}",
- '--header',
- 'Accept:application/json']
+ @@client_mtx.synchronize do
+ if not @@api_client
+ @@api_client = HTTPClient.new
+ if Rails.configuration.arvados_insecure_https
+ @@api_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+ end
+ end
+
+ api_token = Thread.current[:arvados_api_token]
+ api_token ||= ''
+
+ resources_kind = class_kind(resources_kind).pluralize if resources_kind.is_a? Class
+ url = "#{self.arvados_v1_base}/#{resources_kind}#{action}"
+
+ query = {"api_token" => api_token}
if !data.nil?
data.each do |k,v|
- dataargs << '--data-urlencode'
if v.is_a? String or v.nil?
- dataargs << "#{k}=#{v}"
- elsif v == true or v == false
- dataargs << "#{k}=#{v ? 1 : 0}"
+ query[k] = v
+ elsif v == true
+ query[k] = 1
+ elsif v == false
+ query[k] = 0
else
- dataargs << "#{k}=#{JSON.dump(v)}"
+ query[k] = JSON.dump(v)
end
end
else
- dataargs << '--data-urlencode' << '_method=GET'
- end
- json = nil
- resources_kind = class_kind(resources_kind).pluralize if resources_kind.is_a? Class
- url = "#{self.arvados_v1_base}/#{resources_kind}#{action}"
- IO.popen([ENV,
- 'curl',
- "-s#{'k' if Rails.configuration.arvados_insecure_https}",
- *dataargs,
- url],
- 'r') do |io|
- json = io.read
+ query["_method"] = "GET"
+ end
+
+ header = {"Accept" => "application/json"}
+
+ msg = @@api_client.post(url,
+ query,
+ header: header)
+
+ if msg.status_code == 401
+ raise NotLoggedInException.new
end
+
+ json = msg.content
+
begin
resp = Oj.load(json, :symbol_keys => true)
rescue Oj::ParseError
@@ -44,13 +64,13 @@ class ArvadosApiClient
raise InvalidApiResponseException.new json
end
if resp[:errors]
- if resp[:errors][0] == 'Not logged in'
- raise NotLoggedInException.new
- else
- errors = resp[:errors]
- errors = errors.join("\n\n") if errors.is_a? Array
- raise "API errors:\n\n#{errors}\n"
- end
+ #if resp[:errors][0] == 'Not logged in'
+ # raise NotLoggedInException.new
+ #else
+ # errors = resp[:errors]
+ # errors = errors.join("\n\n") if errors.is_a? Array
+ # raise "API errors:\n\n#{errors}\n"
+ #end
end
resp
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list