ms_rest_azure 0.1.2 → 0.2.0
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 +4 -4
- data/lib/ms_rest_azure/azure_service_client.rb +43 -67
- data/lib/ms_rest_azure/polling_state.rb +5 -0
- data/lib/ms_rest_azure/version.rb +1 -1
- data/ms_rest_azure.gemspec +3 -3
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b02ce265675df7683f3fb48e1f1fd1ec1d0e60b
|
4
|
+
data.tar.gz: 027a5fe53ebc63894274461aa81786a4f735c6b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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
|
-
|
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,
|
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,
|
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
|
-
|
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
|
-
|
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,
|
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,
|
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,
|
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
|
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(
|
144
|
-
result = get_async_with_custom_deserialization(
|
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(
|
170
|
-
result = get_async_with_custom_deserialization(
|
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
|
-
|
203
|
-
|
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 [
|
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(
|
221
|
-
result = get_async_with_custom_deserialization(
|
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
|
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(
|
243
|
-
result = get_async_common(
|
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
|
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(
|
263
|
-
result = get_async_common(
|
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
|
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(
|
276
|
-
fail ValidationError, '
|
277
|
-
|
278
|
-
|
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 =
|
301
|
-
|
302
|
-
|
303
|
-
|
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
|
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(
|
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,
|
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
|
|
data/ms_rest_azure.gemspec
CHANGED
@@ -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
|
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
|
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.
|
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.
|
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:
|
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
|
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
|
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
|
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
|
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.
|
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.
|
124
|
+
version: '0.2'
|
125
125
|
description: Azure Client Library for Ruby.
|
126
126
|
email: azsdkteam@microsoft.com
|
127
127
|
executables: []
|