ms_rest_azure 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 358a159d41187ee8dbebdf93b8dd886576f8a0cb
4
- data.tar.gz: fc7302b082c0bf3bfe38afcf1ce9edb8d39e1ecb
3
+ metadata.gz: 6b02ce265675df7683f3fb48e1f1fd1ec1d0e60b
4
+ data.tar.gz: 027a5fe53ebc63894274461aa81786a4f735c6b6
5
5
  SHA512:
6
- metadata.gz: 55e84dd3e4435da36b1adbc19394b3c8d358bb0d643f6833f108c1b52e137c6b2928fd6ef75c39f81971cc234dafad0443e9f246904684d5a58396c1bdaf0c17
7
- data.tar.gz: c096ce9729717f63d526b430aad10ff7ba93d8e5d69f2ab4231eff1e7d759b7d57de88476f8366cd8b002c32f5d5950ba99767acf7d2a67e999063718cdd8f69
6
+ metadata.gz: aff4289214fe7169448cd59f4d4570f609e6a8beee79282edabb39e1cf71b8b730421697214453fce6c124c20dec491e4b78a8981217072476dfeac59ab8f50d
7
+ data.tar.gz: fe7b6aa721bafe96825a5763e2bd2f5d396f2bd213a2b712af88748d48d656fbc6d218e7403f929b213663ee4a4c30623e142d2900b8f3edcdfac7aed3005948
@@ -17,11 +17,10 @@ module MsRestAzure
17
17
  #
18
18
  # Retrieves the result of 'PUT' operation. Perfroms polling of required.
19
19
  # @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
20
- # @param custom_headers [Hash] custom HTTP headers to apply to HTTP requests.
21
20
  # @param custom_deserialization_block [Proc] custom logic for response deserialization.
22
21
  #
23
22
  # @return [MsRest::HttpOperationResponse] the response.
24
- def get_put_operation_result(azure_response, custom_headers, custom_deserialization_block)
23
+ def get_put_operation_result(azure_response, custom_deserialization_block)
25
24
  fail MsRest::ValidationError, 'Azure response cannot be nil' if azure_response.nil?
26
25
 
27
26
  status_code = azure_response.response.status
@@ -31,17 +30,18 @@ module MsRestAzure
31
30
  end
32
31
 
33
32
  polling_state = PollingState.new(azure_response, @long_running_operation_retry_timeout)
34
- operation_url = azure_response.request.url_prefix.to_s
33
+ request = azure_response.request
35
34
 
36
35
  if (!AsyncOperationStatus.is_terminal_status(polling_state.status))
37
36
  task = Concurrent::TimerTask.new do
38
37
  begin
39
38
  if !polling_state.azure_async_operation_header_link.nil?
40
- update_state_from_azure_async_operation_header(polling_state, custom_headers)
39
+ update_state_from_azure_async_operation_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state)
41
40
  elsif !polling_state.location_header_link.nil?
42
- update_state_from_location_header_on_put(polling_state, custom_headers, custom_deserialization_block)
41
+ update_state_from_location_header_on_put(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state, custom_deserialization_block)
43
42
  else
44
- update_state_from_get_resource_operation(operation_url, polling_state, custom_headers, custom_deserialization_block)
43
+ get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, 'get', query_params: request.query_params)
44
+ update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
45
45
  end
46
46
 
47
47
  if (AsyncOperationStatus.is_terminal_status(polling_state.status))
@@ -65,7 +65,8 @@ module MsRestAzure
65
65
  end
66
66
 
67
67
  if (AsyncOperationStatus.is_successful_status(polling_state.status) && polling_state.resource.nil?)
68
- update_state_from_get_resource_operation(operation_url, polling_state, custom_headers, custom_deserialization_block)
68
+ get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, 'get', query_params: request.query_params)
69
+ update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
69
70
  end
70
71
 
71
72
  if (AsyncOperationStatus.is_failed_status(polling_state.status))
@@ -78,11 +79,10 @@ module MsRestAzure
78
79
  #
79
80
  # Retrieves the result of 'POST' or 'DELETE' operations. Perfroms polling of required.
80
81
  # @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
81
- # @param custom_headers [Proc] custom method for polling.
82
82
  # @param custom_deserialization_block [Proc] custom logic for response deserialization.
83
83
  #
84
84
  # @return [MsRest::HttpOperationResponse] the response.
85
- def get_post_or_delete_operation_result(azure_response, custom_headers, custom_deserialization_block)
85
+ def get_post_or_delete_operation_result(azure_response, custom_deserialization_block)
86
86
  fail MsRest::ValidationError, 'Azure response cannot be nil' if azure_response.nil?
87
87
  fail MsRest::ValidationError, 'Azure response cannot have empty response object' if azure_response.response.nil?
88
88
 
@@ -93,14 +93,15 @@ module MsRestAzure
93
93
  end
94
94
 
95
95
  polling_state = PollingState.new(azure_response, @long_running_operation_retry_timeout)
96
-
96
+ request = azure_response.request
97
+
97
98
  if (!AsyncOperationStatus.is_terminal_status(polling_state.status))
98
99
  task = Concurrent::TimerTask.new do
99
100
  begin
100
101
  if !polling_state.azure_async_operation_header_link.nil?
101
- update_state_from_azure_async_operation_header(polling_state, custom_headers)
102
+ update_state_from_azure_async_operation_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state)
102
103
  elsif !polling_state.location_header_link.nil?
103
- update_state_from_location_header_on_post_or_delete(polling_state, custom_headers, custom_deserialization_block)
104
+ update_state_from_location_header_on_post_or_delete(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state, custom_deserialization_block)
104
105
  else
105
106
  task.shutdown
106
107
  fail AzureOperationError, 'Location header is missing from long running operation'
@@ -135,13 +136,12 @@ module MsRestAzure
135
136
 
136
137
  #
137
138
  # Updates polling state based on location header for PUT HTTP requests.
138
- # @param operation_url [String] The url retrieve data from.
139
+ # @param request [MsRest::HttpOperationRequest] The url retrieve data from.
139
140
  # @param polling_state [MsRestAzure::PollingState] polling state to update.
140
- # @param custom_headers [Hash] custom headers to apply to HTTP request.
141
141
  # @param custom_deserialization_block [Proc] custom deserialization method for parsing response.
142
142
  #
143
- def update_state_from_get_resource_operation(operation_url, polling_state, custom_headers, custom_deserialization_block)
144
- result = get_async_with_custom_deserialization(operation_url, custom_headers, custom_deserialization_block)
143
+ def update_state_from_get_resource_operation(request, polling_state, custom_deserialization_block)
144
+ result = get_async_with_custom_deserialization(request, custom_deserialization_block)
145
145
 
146
146
  fail AzureOperationError, 'The response from long running operation does not contain a body' if result.response.body.nil? || result.response.body.empty?
147
147
 
@@ -163,11 +163,11 @@ module MsRestAzure
163
163
 
164
164
  #
165
165
  # Updates polling state based on location header for PUT HTTP requests.
166
+ # @param request [MsRest::HttpOperationRequest] The url retrieve data from.
166
167
  # @param polling_state [MsRestAzure::PollingState] polling state to update.
167
- # @param custom_headers [Hash] custom headers to apply to HTTP request.
168
168
  # @param custom_deserialization_block [Proc] custom deserialization method for parsing response.
169
- def update_state_from_location_header_on_put(polling_state, custom_headers, custom_deserialization_block)
170
- result = get_async_with_custom_deserialization(polling_state.location_header_link, custom_headers, custom_deserialization_block)
169
+ def update_state_from_location_header_on_put(request, polling_state, custom_deserialization_block)
170
+ result = get_async_with_custom_deserialization(request, custom_deserialization_block)
171
171
 
172
172
  polling_state.update_response(result.response)
173
173
  polling_state.request = result.response
@@ -199,9 +199,8 @@ module MsRestAzure
199
199
  #
200
200
  # Updates polling state from Azure async operation header.
201
201
  # @param polling_state [MsRestAzure::PollingState] polling state.
202
- # @param custom_headers [Hash] custom headers to apply to HTTP request.
203
- def update_state_from_azure_async_operation_header(polling_state, custom_headers)
204
- result = get_async_with_async_operation_deserialization(polling_state.azure_async_operation_header_link, custom_headers)
202
+ def update_state_from_azure_async_operation_header(request, polling_state)
203
+ result = get_async_with_async_operation_deserialization(request)
205
204
 
206
205
  fail AzureOperationError, 'The response from long running operation does not contain a body' if result.body.nil? || result.body.status.nil?
207
206
 
@@ -214,11 +213,10 @@ module MsRestAzure
214
213
 
215
214
  #
216
215
  # Updates polling state based on location header for POST and DELETE HTTP requests.
217
- # @param polling_state [MsRestAzure::PollingState] [description]
218
- # @param custom_headers [Hash] custom headers to apply to HTTP requests.
216
+ # @param polling_state [MsRest::HttpOperationRequest] [description]
219
217
  # @param custom_deserialization_block [Proc] custom deserialization method for parsing response.
220
- def update_state_from_location_header_on_post_or_delete(polling_state, custom_headers, custom_deserialization_block)
221
- result = get_async_with_custom_deserialization(polling_state.location_header_link, custom_headers, custom_deserialization_block)
218
+ def update_state_from_location_header_on_post_or_delete(request, polling_state, custom_deserialization_block)
219
+ result = get_async_with_custom_deserialization(request, custom_deserialization_block)
222
220
 
223
221
  polling_state.update_response(result.response)
224
222
  polling_state.request = result.request
@@ -234,13 +232,12 @@ module MsRestAzure
234
232
 
235
233
  #
236
234
  # Retrives data by given URL.
237
- # @param operation_url [String] the URL.
238
- # @param custom_headers [String] headers to apply to the HTTP request.
235
+ # @param request [MsRest::HttpOperationRequest] the URL.
239
236
  # @param custom_deserialization_block [Proc] function to perform deserialization of the HTTP response.
240
237
  #
241
238
  # @return [MsRest::HttpOperationResponse] the response.
242
- def get_async_with_custom_deserialization(operation_url, custom_headers, custom_deserialization_block)
243
- result = get_async_common(operation_url, custom_headers)
239
+ def get_async_with_custom_deserialization(request, custom_deserialization_block)
240
+ result = get_async_common(request)
244
241
 
245
242
  if (!result.body.nil? && !custom_deserialization_block.nil?)
246
243
  begin
@@ -255,12 +252,11 @@ module MsRestAzure
255
252
 
256
253
  #
257
254
  # Retrives data by given URL.
258
- # @param operation_url [String] the URL.
259
- # @param custom_headers [String] headers to apply to the HTTP request.
255
+ # @param request [MsRest::HttpOperationRequest] the URL.
260
256
  #
261
257
  # @return [MsRest::HttpOperationResponse] the response.
262
- def get_async_with_async_operation_deserialization(operation_url, custom_headers)
263
- result = get_async_common(operation_url, custom_headers)
258
+ def get_async_with_async_operation_deserialization(request)
259
+ result = get_async_common(request)
264
260
 
265
261
  result.body = AsyncOperationStatus.deserialize_object(result.body)
266
262
  result
@@ -268,55 +264,35 @@ module MsRestAzure
268
264
 
269
265
  #
270
266
  # Retrives data by given URL.
271
- # @param operation_url [String] the URL.
272
- # @param custom_headers [String] headers to apply to the HTTP request.
267
+ # @param request [MsRest::HttpOperationRequest] the URL.
273
268
  #
274
269
  # @return [MsRest::HttpOperationResponse] the response.
275
- def get_async_common(operation_url, custom_headers)
276
- fail ValidationError, 'Operation url cannot be nil' if operation_url.nil?
277
-
278
- url = URI(operation_url.gsub(' ', '%20'))
279
-
280
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
281
-
282
- # Create HTTP transport object
283
- connection = Faraday.new(:url => url) do |faraday|
284
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
285
- faraday.use :cookie_jar
286
- faraday.adapter Faraday.default_adapter
287
- end
288
-
289
- request_headers = Hash.new
290
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
291
- request_headers['Content-Type'] = 'application/json'
292
-
293
- unless custom_headers.nil?
294
- custom_headers.each do |key, value|
295
- request_headers[key] = value
296
- end
297
- end
270
+ def get_async_common(request)
271
+ fail ValidationError, 'Request cannot be nil' if request.nil?
272
+
273
+ request.middlewares = [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]]
274
+ request.headers.merge!({'x-ms-client-request-id' => SecureRandom.uuid, 'Content-Type' => 'application/json'})
298
275
 
299
276
  # Send Request
300
- http_response = connection.get do |request|
301
- request.headers = request_headers
302
- @credentials.sign_request(request) unless @credentials.nil?
303
- end
304
-
277
+ http_response = request.run_promise do |req|
278
+ @credentials.sign_request(req) unless @credentials.nil?
279
+ end.execute.value!
280
+
305
281
  status_code = http_response.status
306
282
 
307
283
  if (status_code != 200 && status_code != 201 && status_code != 202 && status_code != 204)
308
284
  json_error_data = JSON.load(http_response.body)
309
285
  error_data = CloudErrorData.deserialize_object(json_error_data)
310
286
 
311
- fail AzureOperationError.new connection, http_response, error_data, "Long running operation failed with status #{status_code}"
287
+ fail AzureOperationError.new request, http_response, error_data, "Long running operation failed with status #{status_code}"
312
288
  end
313
289
 
314
- result = MsRest::HttpOperationResponse.new(connection, http_response, http_response.body)
290
+ result = MsRest::HttpOperationResponse.new(request, http_response, http_response.body)
315
291
 
316
292
  begin
317
293
  result.body = JSON.load(http_response.body) unless http_response.body.to_s.empty?
318
294
  rescue Exception => e
319
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, http_response.body)
295
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, result)
320
296
  end
321
297
 
322
298
  result
@@ -91,6 +91,11 @@ module MsRestAzure
91
91
  def get_operation_error
92
92
  AzureOperationError.new @request, @response, @error_data, "Long running operation failed with status #{@status}"
93
93
  end
94
+
95
+ def get_request(options = {})
96
+ link = @azure_async_operation_header_link || @location_header_link
97
+ MsRest::HttpOperationRequest.new(nil, link, 'get', options)
98
+ end
94
99
 
95
100
  private
96
101
 
@@ -3,5 +3,5 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for license information.
4
4
 
5
5
  module MsRestAzure
6
- VERSION = '0.1.2'
6
+ VERSION = '0.2.0'
7
7
  end
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.9'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.3.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.3'
30
30
 
31
31
  spec.add_runtime_dependency 'json', '~> 1.7'
32
32
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
33
- spec.add_runtime_dependency 'faraday', '~> 0.9.1'
33
+ spec.add_runtime_dependency 'faraday', '~> 0.9'
34
34
  spec.add_runtime_dependency 'faraday-cookie_jar', '~> 0.0.6'
35
- spec.add_runtime_dependency 'ms_rest', '~> 0.1.0'
35
+ spec.add_runtime_dependency 'ms_rest', '~> 0.2'
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms_rest_azure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.3.0
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.3.0
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.9.1
89
+ version: '0.9'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.9.1
96
+ version: '0.9'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: faraday-cookie_jar
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.1.0
117
+ version: '0.2'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.1.0
124
+ version: '0.2'
125
125
  description: Azure Client Library for Ruby.
126
126
  email: azsdkteam@microsoft.com
127
127
  executables: []