cloudstack_client 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fff1252133afca0d217d2dba42a9ef41f9d0124
4
- data.tar.gz: 8004e1b1557234b62fde004cbd1461f7fc42f4fd
3
+ metadata.gz: d2b8bddf629215f194cbe11066fad1eabaf171d1
4
+ data.tar.gz: f043aa77492309917d8276dd210ae5f1ccc20809
5
5
  SHA512:
6
- metadata.gz: 0b12dc68ad181f9b03338814820d2951779ff5fe994db00ebc63128bd8bdc22c90a93e562297cc713fbea477458e144f5ff471bcac9f4e55bcad2f43ab6b9546
7
- data.tar.gz: 0379fd6f4294c0d93cfa500f56fd4133e1b1448046c0ebf20b7c20d85f87e7cae39aa5d407411ad85eec97a5645478d7dabad1e74f79959d96943cdef39f4970
6
+ metadata.gz: 945d8665611bca4dce415fd3fb749db55578a08ae647b4d9765ce7d4e4b66e354585567e14d50444f003465936af75bb40656ac53f9556e0f7f036c58d5c9314
7
+ data.tar.gz: d71dfdd42cf8521e9ef1a9a795b1271653a3a6dc337dce3b6f65b9793a483c30fe0dedd6e13f9799dfa3173712ffad807bc8a06ecb3b5f0881c95e46dc368959
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack_client (1.4.1)
4
+ cloudstack_client (1.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -24,4 +24,4 @@ DEPENDENCIES
24
24
  thor (~> 0.19)
25
25
 
26
26
  BUNDLED WITH
27
- 1.11.2
27
+ 1.12.0
@@ -35,32 +35,12 @@ module CloudstackClient
35
35
  def send_request(params)
36
36
  params['response'] = 'json'
37
37
  params['apiKey'] = @api_key
38
-
39
- params_arr = params.sort.map do |key, value|
40
- # support for maps (Arrays of Hashes)
41
- if value.is_a?(Array)
42
- map = []
43
- value.each_with_index do |items, i|
44
- items.each {|k, v| map << "#{key}[#{i}].#{k}=#{escape(v)}"}
45
- end
46
- map.sort.join("&")
47
- else
48
- "#{key}=#{escape(value)}"
49
- end
50
- end
51
-
52
38
  print_debug_output JSON.pretty_generate(params) if @debug
53
39
 
54
- data = params_arr.sort.join('&')
55
- signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
56
- signature = Base64.encode64(signature).chomp
57
- signature = CGI.escape(signature)
58
-
59
- url = "#{@api_url}?#{data}&signature=#{signature}"
40
+ data = params_to_data(params)
41
+ uri = URI.parse "#{@api_url}?#{data}&signature=#{create_signature(data)}"
60
42
 
61
- uri = URI.parse(url)
62
43
  http = Net::HTTP.new(uri.host, uri.port)
63
-
64
44
  if uri.scheme == 'https'
65
45
  http.use_ssl = true
66
46
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -111,7 +91,6 @@ module CloudstackClient
111
91
 
112
92
  max_tries.times do
113
93
  data = send_request(params)
114
-
115
94
  print "." if @verbose
116
95
 
117
96
  case data['jobstatus']
@@ -122,7 +101,6 @@ module CloudstackClient
122
101
  end
123
102
 
124
103
  STDOUT.flush if @verbose
125
-
126
104
  sleep @async_poll_interval
127
105
  end
128
106
 
@@ -139,6 +117,35 @@ module CloudstackClient
139
117
  raise InputError, "ASYNC TIMEOUT must be at least 60." if @async_timeout < 60
140
118
  end
141
119
 
120
+ def params_to_data(params)
121
+ params_arr = params.sort.map do |key, value|
122
+ case value
123
+ when String
124
+ "#{key}=#{escape(value)}"
125
+ when Array # support for maps (Arrays of Hashes)
126
+ map = []
127
+ value.each_with_index do |items, i|
128
+ items.each {|k, v| map << "#{key}[#{i}].#{k}=#{escape(v)}"}
129
+ end
130
+ map.sort.join("&")
131
+ when Hash # support for maps values of values (Hash values of Hashes)
132
+ value.each_with_index.map do |(k, v), i|
133
+ "#{key}[#{i}].key=#{escape(k)}&" +
134
+ "#{key}[#{i}].value=#{escape(v)}"
135
+ end.join("&")
136
+ else
137
+ raise ParameterError, "unsupported parameter value type \"#{value.class}\""
138
+ end
139
+ end
140
+ params_arr.sort.join('&')
141
+ end
142
+
143
+ def create_signature(data)
144
+ signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
145
+ signature = Base64.encode64(signature).chomp
146
+ CGI.escape(signature)
147
+ end
148
+
142
149
  def max_tries
143
150
  (@async_timeout / @async_poll_interval).round
144
151
  end
@@ -147,5 +154,5 @@ module CloudstackClient
147
154
  CGI.escape(input.to_s).gsub('+', '%20').gsub(' ', '%20')
148
155
  end
149
156
 
150
- end
151
- end
157
+ end # class
158
+ end # module
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake