ms_rest_azure 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +5 -0
- data/README.md +1 -1
- data/lib/ms_rest_azure/async_operation_status.rb +2 -1
- data/lib/ms_rest_azure/azure_service_client.rb +18 -23
- data/lib/ms_rest_azure/polling_state.rb +21 -2
- data/lib/ms_rest_azure/resource.rb +55 -61
- data/lib/ms_rest_azure/sub_resource.rb +18 -35
- data/lib/ms_rest_azure/version.rb +1 -1
- data/ms_rest_azure.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a38496ee61b6d8aae2c6014a39ea693cd14c5a
|
4
|
+
data.tar.gz: 0df39d7496a44bd6602792d88e2ddd066dad5409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8613403ac1c8b3057992513a0b640f088525b70a8d3a1ffb9c907ef89d5571966316b4232902633b27f27eaa73666e7480a7b535d2c5961ab06a7f5f634dde2c
|
7
|
+
data.tar.gz: 0349cec779491afc9bec38e9769a90014c439a59d041a86ef89b55fa9ce38165df8613b3f39878ca2fd726d4d9dd044899a34164c43f8962980f652fe1d076f1
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
##2016.07.14 ms_rest_azure version 0.3.0
|
2
|
+
* Embracing latest ms_rest version [0.3.0](https://rubygems.org/gems/ms_rest)
|
3
|
+
|
4
|
+
##2016.05.19 ms_rest_azure version 0.2.3
|
5
|
+
* Support patch for long running operations. See [#1011](https://github.com/Azure/autorest/pull/1011), [#1056](https://github.com/Azure/autorest/pull/1056)
|
data/README.md
CHANGED
@@ -38,7 +38,7 @@ To start working on the gem the only additional dev dependecy is required - rspe
|
|
38
38
|
Reference it in the gemfile and also add this line to your client's gemspec file:
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
spec.add_runtime_dependency 'ms_rest_azure', '~> 0.
|
41
|
+
spec.add_runtime_dependency 'ms_rest_azure', '~> 0.3.0'
|
42
42
|
```
|
43
43
|
|
44
44
|
Don't forget to correct the version.
|
@@ -7,13 +7,14 @@ module MsRestAzure
|
|
7
7
|
# Defines values for AsyncOperationStatus enum.
|
8
8
|
#
|
9
9
|
class AsyncOperationStatus
|
10
|
+
ACCEPTED = 'Accepted'
|
10
11
|
IN_PROGRESS_STATUS = 'InProgress'
|
11
12
|
RUNNING = 'Running'
|
12
13
|
SUCCESS_STATUS = 'Succeeded'
|
13
14
|
FAILED_STATUS = 'Failed'
|
14
15
|
CANCELED_STATUS = 'Canceled'
|
15
16
|
|
16
|
-
ALL_STATUSES = [FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS, IN_PROGRESS_STATUS, RUNNING]
|
17
|
+
ALL_STATUSES = [ACCEPTED, FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS, IN_PROGRESS_STATUS, RUNNING]
|
17
18
|
FAILED_STATUSES = [FAILED_STATUS, CANCELED_STATUS]
|
18
19
|
TERMINAL_STATUSES = [FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS]
|
19
20
|
|
@@ -20,6 +20,7 @@ module MsRestAzure
|
|
20
20
|
# @param custom_deserialization_block [Proc] custom logic for response deserialization.
|
21
21
|
#
|
22
22
|
# @return [MsRest::HttpOperationResponse] the response.
|
23
|
+
#
|
23
24
|
def get_long_running_operation_result(azure_response, custom_deserialization_block)
|
24
25
|
check_for_status_code_failure(azure_response)
|
25
26
|
|
@@ -36,7 +37,7 @@ module MsRestAzure
|
|
36
37
|
elsif !polling_state.location_header_link.nil?
|
37
38
|
update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state, custom_deserialization_block)
|
38
39
|
elsif http_method === :put
|
39
|
-
get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, query_params: request.query_params)
|
40
|
+
get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers})
|
40
41
|
update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
|
41
42
|
else
|
42
43
|
task.shutdown
|
@@ -64,7 +65,7 @@ module MsRestAzure
|
|
64
65
|
end
|
65
66
|
|
66
67
|
if (http_method === :put || http_method === :patch) && AsyncOperationStatus.is_successful_status(polling_state.status) && polling_state.resource.nil?
|
67
|
-
get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, query_params: request.query_params)
|
68
|
+
get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers})
|
68
69
|
update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
|
69
70
|
end
|
70
71
|
|
@@ -75,29 +76,10 @@ module MsRestAzure
|
|
75
76
|
polling_state.get_operation_response
|
76
77
|
end
|
77
78
|
|
78
|
-
# @TODO Update name of the method to get_put_or_patch_operation_result when introducing breaking change / updating major version of gem
|
79
|
-
# Retrieves the result of 'PUT' or 'PATCH' operation. Performs polling of required.
|
80
|
-
# @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
|
81
|
-
# @param custom_deserialization_block [Proc] custom logic for response deserialization.
|
82
|
-
#
|
83
|
-
# @return [MsRest::HttpOperationResponse] the response.
|
84
|
-
def get_put_operation_result(azure_response, custom_deserialization_block)
|
85
|
-
get_long_running_operation_result(azure_response, custom_deserialization_block)
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# Retrieves the result of 'POST' or 'DELETE' operations. Performs polling of required.
|
90
|
-
# @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
|
91
|
-
# @param custom_deserialization_block [Proc] custom logic for response deserialization.
|
92
|
-
#
|
93
|
-
# @return [MsRest::HttpOperationResponse] the response.
|
94
|
-
def get_post_or_delete_operation_result(azure_response, custom_deserialization_block)
|
95
|
-
get_long_running_operation_result(azure_response, custom_deserialization_block)
|
96
|
-
end
|
97
|
-
|
98
79
|
#
|
99
80
|
# Verifies for unexpected polling status code
|
100
81
|
# @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
|
82
|
+
#
|
101
83
|
def check_for_status_code_failure(azure_response)
|
102
84
|
fail MsRest::ValidationError, 'Azure response cannot be nil' if azure_response.nil?
|
103
85
|
fail MsRest::ValidationError, 'Azure response cannot have empty response object' if azure_response.response.nil?
|
@@ -122,8 +104,12 @@ module MsRestAzure
|
|
122
104
|
|
123
105
|
fail AzureOperationError, 'The response from long running operation does not contain a body' if result.response.body.nil? || result.response.body.empty?
|
124
106
|
|
107
|
+
# On non flattened resource, we should find provisioning_state inside 'properties'
|
125
108
|
if result.body.respond_to?(:properties) && result.body.properties.respond_to?(:provisioning_state) && !result.body.properties.provisioning_state.nil?
|
126
109
|
polling_state.status = result.body.properties.provisioning_state
|
110
|
+
# On flattened resource, we should find provisioning_state at the top level
|
111
|
+
elsif result.body.respond_to?(:provisioning_state) && !result.body.provisioning_state.nil?
|
112
|
+
polling_state.status = result.body.provisioning_state
|
127
113
|
else
|
128
114
|
polling_state.status = AsyncOperationStatus::SUCCESS_STATUS
|
129
115
|
end
|
@@ -143,6 +129,7 @@ module MsRestAzure
|
|
143
129
|
# @param request [MsRest::HttpOperationRequest] The url retrieve data from.
|
144
130
|
# @param polling_state [MsRestAzure::PollingState] polling state to update.
|
145
131
|
# @param custom_deserialization_block [Proc] custom deserialization method for parsing response.
|
132
|
+
#
|
146
133
|
def update_state_from_location_header(request, polling_state, custom_deserialization_block)
|
147
134
|
result = get_async_with_custom_deserialization(request, custom_deserialization_block)
|
148
135
|
|
@@ -171,6 +158,7 @@ module MsRestAzure
|
|
171
158
|
#
|
172
159
|
# Updates polling state from Azure async operation header.
|
173
160
|
# @param polling_state [MsRestAzure::PollingState] polling state.
|
161
|
+
#
|
174
162
|
def update_state_from_azure_async_operation_header(request, polling_state)
|
175
163
|
result = get_async_with_async_operation_deserialization(request)
|
176
164
|
|
@@ -181,6 +169,8 @@ module MsRestAzure
|
|
181
169
|
polling_state.response = result.response
|
182
170
|
polling_state.request = result.request
|
183
171
|
polling_state.resource = nil
|
172
|
+
|
173
|
+
polling_state
|
184
174
|
end
|
185
175
|
|
186
176
|
#
|
@@ -189,6 +179,7 @@ module MsRestAzure
|
|
189
179
|
# @param custom_deserialization_block [Proc] function to perform deserialization of the HTTP response.
|
190
180
|
#
|
191
181
|
# @return [MsRest::HttpOperationResponse] the response.
|
182
|
+
#
|
192
183
|
def get_async_with_custom_deserialization(request, custom_deserialization_block)
|
193
184
|
result = get_async_common(request)
|
194
185
|
|
@@ -208,10 +199,12 @@ module MsRestAzure
|
|
208
199
|
# @param request [MsRest::HttpOperationRequest] the URL.
|
209
200
|
#
|
210
201
|
# @return [MsRest::HttpOperationResponse] the response.
|
202
|
+
#
|
211
203
|
def get_async_with_async_operation_deserialization(request)
|
212
204
|
result = get_async_common(request)
|
213
205
|
|
214
206
|
result.body = AsyncOperationStatus.deserialize_object(result.body)
|
207
|
+
|
215
208
|
result
|
216
209
|
end
|
217
210
|
|
@@ -220,11 +213,13 @@ module MsRestAzure
|
|
220
213
|
# @param request [MsRest::HttpOperationRequest] the URL.
|
221
214
|
#
|
222
215
|
# @return [MsRest::HttpOperationResponse] the response.
|
216
|
+
#
|
223
217
|
def get_async_common(request)
|
224
218
|
fail ValidationError, 'Request cannot be nil' if request.nil?
|
225
219
|
|
226
220
|
request.middlewares = [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]]
|
227
|
-
request.headers.merge!({'x-ms-client-request-id' => SecureRandom.uuid
|
221
|
+
request.headers.merge!({'x-ms-client-request-id' => SecureRandom.uuid}) unless request.headers.key?('x-ms-client-request-id')
|
222
|
+
request.headers.merge!({'Content-Type' => 'application/json'}) unless request.headers.key?('Content-Type')
|
228
223
|
|
229
224
|
# Send Request
|
230
225
|
http_response = request.run_promise do |req|
|
@@ -35,8 +35,12 @@ module MsRestAzure
|
|
35
35
|
update_response(azure_response.response)
|
36
36
|
@resource = azure_response.body
|
37
37
|
|
38
|
+
# On non flattened resource, we should find provisioning_state inside 'properties'
|
38
39
|
if (!@resource.nil? && @resource.respond_to?(:properties) && @resource.properties.respond_to?(:provisioning_state) && !@resource.properties.provisioning_state.nil?)
|
39
40
|
@status = @resource.properties.provisioning_state
|
41
|
+
# On flattened resource, we should find provisioning_state at the top level
|
42
|
+
elsif !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil?
|
43
|
+
@status = @resource.provisioning_state
|
40
44
|
else
|
41
45
|
case @response.status
|
42
46
|
when 202
|
@@ -56,7 +60,7 @@ module MsRestAzure
|
|
56
60
|
def get_delay
|
57
61
|
return @retry_timeout unless @retry_timeout.nil?
|
58
62
|
|
59
|
-
if
|
63
|
+
if !response.nil? && !response.headers['Retry-After'].nil?
|
60
64
|
return response.headers['Retry-After'].to_i
|
61
65
|
end
|
62
66
|
|
@@ -69,7 +73,7 @@ module MsRestAzure
|
|
69
73
|
def update_response(response)
|
70
74
|
@response = response
|
71
75
|
|
72
|
-
|
76
|
+
unless response.nil?
|
73
77
|
@azure_async_operation_header_link = response.headers['Azure-AsyncOperation'] unless response.headers['Azure-AsyncOperation'].nil?
|
74
78
|
@location_header_link = response.headers['Location'] unless response.headers['Location'].nil?
|
75
79
|
end
|
@@ -94,6 +98,7 @@ module MsRestAzure
|
|
94
98
|
|
95
99
|
def get_request(options = {})
|
96
100
|
link = @azure_async_operation_header_link || @location_header_link
|
101
|
+
options[:connection] = create_connection(options[:base_uri])
|
97
102
|
MsRest::HttpOperationRequest.new(nil, link, :get, options)
|
98
103
|
end
|
99
104
|
|
@@ -101,6 +106,20 @@ module MsRestAzure
|
|
101
106
|
|
102
107
|
# @return [Integer] retry timeout.
|
103
108
|
attr_accessor :retry_timeout
|
109
|
+
|
110
|
+
attr_accessor :connection
|
111
|
+
|
112
|
+
def create_connection(base_url)
|
113
|
+
@connection ||= Faraday.new(:url => base_url) do |faraday|
|
114
|
+
[[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]].each{ |args| faraday.use(*args) }
|
115
|
+
faraday.adapter Faraday.default_adapter
|
116
|
+
faraday.headers = request.headers
|
117
|
+
logging = ENV['AZURE_HTTP_LOGGING'] || request.log
|
118
|
+
if logging
|
119
|
+
faraday.response :logger, nil, { :bodies => logging == 'full' }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
104
123
|
end
|
105
124
|
|
106
125
|
end
|
@@ -23,67 +23,61 @@ module MsRestAzure
|
|
23
23
|
# @return [Hash{String => String}] the tags attached to resources (optional).
|
24
24
|
attr_accessor :tags
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
26
|
+
def self.mapper
|
27
|
+
{
|
28
|
+
required: false,
|
29
|
+
serialized_name: 'Resource',
|
30
|
+
type: {
|
31
|
+
name: 'Composite',
|
32
|
+
class_name: 'Resource',
|
33
|
+
model_properties: {
|
34
|
+
id: {
|
35
|
+
required: false,
|
36
|
+
serialized_name: 'id',
|
37
|
+
type: {
|
38
|
+
name: 'String'
|
39
|
+
}
|
40
|
+
},
|
41
|
+
name: {
|
42
|
+
required: false,
|
43
|
+
read_only: true,
|
44
|
+
serialized_name: 'name',
|
45
|
+
type: {
|
46
|
+
name: 'String'
|
47
|
+
}
|
48
|
+
},
|
49
|
+
type: {
|
50
|
+
required: false,
|
51
|
+
read_only: true,
|
52
|
+
serialized_name: 'type',
|
53
|
+
type: {
|
54
|
+
name: 'String'
|
55
|
+
}
|
56
|
+
},
|
57
|
+
location: {
|
58
|
+
required: false,
|
59
|
+
serialized_name: 'location',
|
60
|
+
type: {
|
61
|
+
name: 'String'
|
62
|
+
}
|
63
|
+
},
|
64
|
+
tags: {
|
65
|
+
required: false,
|
66
|
+
serialized_name: 'tags',
|
67
|
+
type: {
|
68
|
+
name: 'Dictionary',
|
69
|
+
value: {
|
70
|
+
required: false,
|
71
|
+
serialized_name: 'StringElementType',
|
72
|
+
type: {
|
73
|
+
name: 'String'
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
51
81
|
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Deserializes given hash object into resource.
|
55
|
-
# @param object [Hash] resource in hash representation to deserialize.
|
56
|
-
#
|
57
|
-
# @return [Resource] deserialized resource.
|
58
|
-
def self.deserialize_object(object)
|
59
|
-
return if object.nil?
|
60
|
-
output_object = Resource.new
|
61
|
-
|
62
|
-
deserialized_property = object['id']
|
63
|
-
output_object.id = deserialized_property
|
64
|
-
|
65
|
-
deserialized_property = object['name']
|
66
|
-
output_object.name = deserialized_property
|
67
|
-
|
68
|
-
deserialized_property = object['type']
|
69
|
-
output_object.type = deserialized_property
|
70
|
-
|
71
|
-
deserialized_property = object['location']
|
72
|
-
output_object.location = deserialized_property
|
73
|
-
|
74
|
-
deserialized_property = object['tags']
|
75
|
-
output_object.tags = deserialized_property
|
76
|
-
|
77
|
-
output_object.validate
|
78
|
-
output_object
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Validates the resource. Throws error if there is any property is incorrect.
|
83
|
-
#
|
84
|
-
def validate
|
85
|
-
fail MsRest::ValidationError, 'Location cannot be nil in the Resource object' if @location.nil?
|
86
|
-
end
|
87
|
-
|
88
82
|
end
|
89
83
|
end
|
@@ -11,41 +11,24 @@ module MsRestAzure
|
|
11
11
|
# @return [String] the id of the subresource.
|
12
12
|
attr_accessor :id
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
# @return [SubResource] deserialized subresource.
|
34
|
-
def self.deserialize_object(object)
|
35
|
-
return if object.nil?
|
36
|
-
output_object = SubResource.new
|
37
|
-
|
38
|
-
deserialized_property = object['id']
|
39
|
-
output_object.id = deserialized_property
|
40
|
-
|
41
|
-
output_object.validate
|
42
|
-
output_object
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# Validates the subresource. Throws error if there is any property is incorrect.
|
47
|
-
#
|
48
|
-
def validate
|
14
|
+
def self.mapper
|
15
|
+
{
|
16
|
+
required: false,
|
17
|
+
serialized_name: 'SubResource',
|
18
|
+
type: {
|
19
|
+
name: 'Composite',
|
20
|
+
class_name: 'SubResource',
|
21
|
+
model_properties: {
|
22
|
+
id: {
|
23
|
+
required: false,
|
24
|
+
serialized_name: 'id',
|
25
|
+
type: {
|
26
|
+
name: 'String'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
49
32
|
end
|
50
33
|
end
|
51
34
|
end
|
data/ms_rest_azure.gemspec
CHANGED
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
33
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.3.0'
|
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.3.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: 2016-
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.3.0
|
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.3.0
|
125
125
|
description: Azure Client Library for Ruby.
|
126
126
|
email: azsdkteam@microsoft.com
|
127
127
|
executables: []
|
@@ -130,6 +130,7 @@ extra_rdoc_files: []
|
|
130
130
|
files:
|
131
131
|
- ".gitignore"
|
132
132
|
- ".travis.yml"
|
133
|
+
- ChangeLog.md
|
133
134
|
- Gemfile
|
134
135
|
- LICENSE.txt
|
135
136
|
- README.md
|