Skip to content

Commit 7fdc12d

Browse files
committed
Merge branch 'master' of github.com:chipchilders/cloudstack_ruby_client
2 parents 6abfcf9 + 1ff56fc commit 7fdc12d

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

lib/cloudstack_ruby_client/base_client.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ def initialize(api_url, api_key, secret_key, use_ssl=nil, open_timeout=20)
99
end
1010

1111
def request(params)
12-
params['response'] = 'json'
13-
params['apiKey'] = @api_key
14-
12+
params[:response] = 'json'
13+
params[:apiKey] = @api_key
14+
1515
data = params.map{ |k,v| "#{k.to_s}=#{CGI.escape(v.to_s).gsub(/\+|\ /, "%20")}" }.sort.join('&')
16-
1716
signature = OpenSSL::HMAC.digest 'sha1', @secret_key, data.downcase
1817
signature = Base64.encode64(signature).chomp
19-
signature = CGI.escape(signature)
2018

21-
url = "#{@api_url}?#{data}&signature=#{signature}"
19+
method = 'POST' if params[:userdata] and params[:userdata].size > 2048
20+
if method == 'POST'
21+
params[:signature] = signature
22+
url = @api_url
23+
else
24+
signature = CGI.escape(signature)
25+
url = "#{@api_url}?#{data}&signature=#{signature}"
26+
end
27+
2228
uri = URI.parse(url)
2329
http = Net::HTTP.new(uri.host, uri.port)
2430
http.use_ssl = @use_ssl
2531
http.open_timeout = @open_timeout # fail the connection faster if can't open socket
2632
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
27-
request = Net::HTTP::Get.new(uri.request_uri)
33+
34+
if method == 'POST'
35+
request = Net::HTTP::Post.new(uri.request_uri)
36+
request.set_form_data(params)
37+
else
38+
request = Net::HTTP::Get.new(uri.request_uri)
39+
end
2840

2941
http.request(request)
3042
end

lib/cloudstack_ruby_client/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def wait_for_async_job(job, timeout=nil)
7272
protected
7373

7474
def auth_request(params, command)
75-
params['response'] = 'json'
76-
params['command'] = command
75+
params[:response] = 'json'
76+
params[:command] = command
7777
data = params.map{ |k,v| "#{k.to_s}=#{CGI.escape(v.to_s).gsub(/\+|\ /, "%20")}" }.sort.join('&')
7878

7979
url = "#{@api_url}?#{data}"

lib/cloudstack_ruby_client/client_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def #{arg}(args={});
9494
} +
9595

9696
%Q{
97-
params = {'command' => command};
97+
params = {:command => command};
9898
params.merge!(args) unless args.empty?;
9999
100100
response = request(params);

0 commit comments

Comments
 (0)