azure_mgmt_resources 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/azure_mgmt_resources.gemspec +2 -7
  3. data/lib/azure_mgmt_resources.rb +21 -18
  4. data/lib/azure_mgmt_resources/deployment_operations.rb +54 -135
  5. data/lib/azure_mgmt_resources/deployments.rb +314 -305
  6. data/lib/azure_mgmt_resources/models/basic_dependency.rb +1 -3
  7. data/lib/azure_mgmt_resources/models/dependency.rb +4 -6
  8. data/lib/azure_mgmt_resources/models/deployment.rb +1 -3
  9. data/lib/azure_mgmt_resources/models/deployment_extended.rb +8 -9
  10. data/lib/azure_mgmt_resources/models/deployment_extended_filter.rb +1 -3
  11. data/lib/azure_mgmt_resources/models/deployment_list_result.rb +4 -6
  12. data/lib/azure_mgmt_resources/models/deployment_mode.rb +2 -1
  13. data/lib/azure_mgmt_resources/models/deployment_operation.rb +1 -3
  14. data/lib/azure_mgmt_resources/models/deployment_operation_properties.rb +1 -3
  15. data/lib/azure_mgmt_resources/models/deployment_operations_list_result.rb +4 -6
  16. data/lib/azure_mgmt_resources/models/deployment_properties.rb +3 -5
  17. data/lib/azure_mgmt_resources/models/deployment_properties_extended.rb +9 -11
  18. data/lib/azure_mgmt_resources/models/deployment_validate_result.rb +1 -3
  19. data/lib/azure_mgmt_resources/models/generic_resource.rb +1 -3
  20. data/lib/azure_mgmt_resources/models/generic_resource_filter.rb +1 -3
  21. data/lib/azure_mgmt_resources/models/parameters_link.rb +2 -4
  22. data/lib/azure_mgmt_resources/models/plan.rb +1 -3
  23. data/lib/azure_mgmt_resources/models/policy_assignment.rb +72 -0
  24. data/lib/azure_mgmt_resources/models/policy_assignment_list_result.rb +86 -0
  25. data/lib/azure_mgmt_resources/models/policy_assignment_properties.rb +74 -0
  26. data/lib/azure_mgmt_resources/models/policy_definition.rb +72 -0
  27. data/lib/azure_mgmt_resources/models/policy_definition_properties.rb +74 -0
  28. data/lib/azure_mgmt_resources/models/provider.rb +4 -6
  29. data/lib/azure_mgmt_resources/models/provider_list_result.rb +4 -6
  30. data/lib/azure_mgmt_resources/models/provider_resource_type.rb +1 -3
  31. data/lib/azure_mgmt_resources/models/resource_group.rb +8 -9
  32. data/lib/azure_mgmt_resources/models/resource_group_filter.rb +1 -3
  33. data/lib/azure_mgmt_resources/models/resource_group_list_result.rb +11 -12
  34. data/lib/azure_mgmt_resources/models/resource_group_properties.rb +1 -3
  35. data/lib/azure_mgmt_resources/models/resource_list_result.rb +11 -12
  36. data/lib/azure_mgmt_resources/models/resource_management_error.rb +3 -4
  37. data/lib/azure_mgmt_resources/models/resource_management_error_with_details.rb +23 -35
  38. data/lib/azure_mgmt_resources/models/resource_provider_operation_definition.rb +1 -3
  39. data/lib/azure_mgmt_resources/models/resource_provider_operation_detail_list_result.rb +4 -6
  40. data/lib/azure_mgmt_resources/models/resource_provider_operation_display_properties.rb +1 -3
  41. data/lib/azure_mgmt_resources/models/resources_move_info.rb +1 -3
  42. data/lib/azure_mgmt_resources/models/tag_count.rb +1 -3
  43. data/lib/azure_mgmt_resources/models/tag_details.rb +4 -6
  44. data/lib/azure_mgmt_resources/models/tag_value.rb +1 -3
  45. data/lib/azure_mgmt_resources/models/tags_list_result.rb +11 -12
  46. data/lib/azure_mgmt_resources/models/target_resource.rb +1 -3
  47. data/lib/azure_mgmt_resources/models/template_link.rb +2 -4
  48. data/lib/azure_mgmt_resources/module_definition.rb +5 -3
  49. data/lib/azure_mgmt_resources/policy_assignments.rb +922 -0
  50. data/lib/azure_mgmt_resources/policy_definitions.rb +208 -0
  51. data/lib/azure_mgmt_resources/providers.rb +90 -219
  52. data/lib/azure_mgmt_resources/resource_groups.rb +166 -434
  53. data/lib/azure_mgmt_resources/resource_management_client.rb +25 -10
  54. data/lib/azure_mgmt_resources/resource_provider_operation_details.rb +88 -43
  55. data/lib/azure_mgmt_resources/resources.rb +162 -366
  56. data/lib/azure_mgmt_resources/tags.rb +110 -264
  57. data/lib/azure_mgmt_resources/version.rb +5 -3
  58. metadata +12 -86
  59. data/.travis.yml +0 -3
  60. data/Gemfile +0 -14
  61. data/lib/azure_mgmt_resources/models/resource_group_extended.rb +0 -113
  62. data/lib/azure_mgmt_resources/models/resource_group_extended_filter.rb +0 -63
  63. data/lib/azure_mgmt_resources/models/resource_group_format_resource_properties.rb +0 -54
@@ -0,0 +1,208 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Resources
7
+ #
8
+ # PolicyDefinitions
9
+ #
10
+ class PolicyDefinitions
11
+ include Azure::ARM::Resources::Models
12
+ include MsRestAzure
13
+
14
+ #
15
+ # Creates and initializes a new instance of the PolicyDefinitions class.
16
+ # @param client service class for accessing basic functionality.
17
+ #
18
+ def initialize(client)
19
+ @client = client
20
+ end
21
+
22
+ # @return reference to the ResourceManagementClient
23
+ attr_reader :client
24
+
25
+ #
26
+ # Create or update policy definition.
27
+ #
28
+ # @param policy_definition_name [String] The policy definition name.
29
+ # @param parameters [PolicyDefinition] The policy definition properties
30
+ # @param [Hash{String => String}] The hash of custom headers need to be
31
+ # applied to HTTP request.
32
+ #
33
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
34
+ # response.
35
+ #
36
+ def create_or_update(policy_definition_name, parameters, custom_headers = nil)
37
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
38
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
39
+ parameters.validate unless parameters.nil?
40
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
41
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
42
+ request_headers = {}
43
+
44
+ # Set Headers
45
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
46
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
47
+
48
+ # Serialize Request
49
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
50
+ unless parameters.nil?
51
+ parameters = PolicyDefinition.serialize_object(parameters)
52
+ end
53
+ request_content = JSON.generate(parameters, quirks_mode: true)
54
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
55
+ options = {
56
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
57
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
58
+ query_params: {'api-version' => @client.api_version},
59
+ body: request_content,
60
+ headers: request_headers.merge(custom_headers || {})
61
+ }
62
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :put, options)
63
+ promise = request.run_promise do |req|
64
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
65
+ end
66
+
67
+ promise = promise.then do |http_response|
68
+ status_code = http_response.status
69
+ response_content = http_response.body
70
+ unless status_code == 201
71
+ error_model = JSON.load(response_content)
72
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
73
+ end
74
+
75
+ # Create Result
76
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
77
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
78
+ # Deserialize Response
79
+ if status_code == 201
80
+ begin
81
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
82
+ unless parsed_response.nil?
83
+ parsed_response = PolicyDefinition.deserialize_object(parsed_response)
84
+ end
85
+ result.body = parsed_response
86
+ rescue Exception => e
87
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
88
+ end
89
+ end
90
+
91
+ result
92
+ end
93
+
94
+ promise.execute
95
+ end
96
+
97
+ #
98
+ # Gets policy definition.
99
+ #
100
+ # @param policy_definition_name [String] The policy definition name.
101
+ # @param [Hash{String => String}] The hash of custom headers need to be
102
+ # applied to HTTP request.
103
+ #
104
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
105
+ # response.
106
+ #
107
+ def get(policy_definition_name, custom_headers = nil)
108
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
109
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
110
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
111
+ request_headers = {}
112
+
113
+ # Set Headers
114
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
115
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
116
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
117
+ options = {
118
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
119
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
120
+ query_params: {'api-version' => @client.api_version},
121
+ headers: request_headers.merge(custom_headers || {})
122
+ }
123
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
124
+ promise = request.run_promise do |req|
125
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
126
+ end
127
+
128
+ promise = promise.then do |http_response|
129
+ status_code = http_response.status
130
+ response_content = http_response.body
131
+ unless status_code == 200
132
+ error_model = JSON.load(response_content)
133
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
134
+ end
135
+
136
+ # Create Result
137
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
138
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
139
+ # Deserialize Response
140
+ if status_code == 200
141
+ begin
142
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
143
+ unless parsed_response.nil?
144
+ parsed_response = PolicyDefinition.deserialize_object(parsed_response)
145
+ end
146
+ result.body = parsed_response
147
+ rescue Exception => e
148
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
149
+ end
150
+ end
151
+
152
+ result
153
+ end
154
+
155
+ promise.execute
156
+ end
157
+
158
+ #
159
+ # Deletes policy definition.
160
+ #
161
+ # @param policy_definition_name [String] The policy definition name.
162
+ # @param [Hash{String => String}] The hash of custom headers need to be
163
+ # applied to HTTP request.
164
+ #
165
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
166
+ # response.
167
+ #
168
+ def delete(policy_definition_name, custom_headers = nil)
169
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
170
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
171
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
172
+ request_headers = {}
173
+
174
+ # Set Headers
175
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
176
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
177
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
178
+ options = {
179
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
180
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
181
+ query_params: {'api-version' => @client.api_version},
182
+ headers: request_headers.merge(custom_headers || {})
183
+ }
184
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :delete, options)
185
+ promise = request.run_promise do |req|
186
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
187
+ end
188
+
189
+ promise = promise.then do |http_response|
190
+ status_code = http_response.status
191
+ response_content = http_response.body
192
+ unless status_code == 200
193
+ error_model = JSON.load(response_content)
194
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
195
+ end
196
+
197
+ # Create Result
198
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
199
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
200
+
201
+ result
202
+ end
203
+
204
+ promise.execute
205
+ end
206
+
207
+ end
208
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Code generated by Microsoft (R) AutoRest Code Generator 0.11.0.0
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
3
3
  # Changes may cause incorrect behavior and will be lost if the code is
4
4
  # regenerated.
5
5
 
@@ -24,6 +24,7 @@ module Azure::ARM::Resources
24
24
 
25
25
  #
26
26
  # Unregisters provider from a subscription.
27
+ #
27
28
  # @param resource_provider_namespace [String] Namespace of the resource
28
29
  # provider.
29
30
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -36,71 +37,44 @@ module Azure::ARM::Resources
36
37
  fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
37
38
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
38
39
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
39
- # Construct URL
40
- path = "/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/unregister"
41
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
42
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
43
- url = URI.join(@client.base_url, path)
44
- properties = {}
45
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
46
- unless url.query.nil?
47
- url.query.split('&').each do |url_item|
48
- url_items_parts = url_item.split('=')
49
- properties[url_items_parts[0]] = url_items_parts[1]
50
- end
51
- end
52
- properties.reject!{ |key, value| value.nil? }
53
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
54
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
55
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
56
- url = URI.parse(corrected_url)
57
-
58
- connection = Faraday.new(:url => url) do |faraday|
59
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
60
- faraday.use :cookie_jar
61
- faraday.adapter Faraday.default_adapter
62
- end
63
- request_headers = Hash.new
40
+ request_headers = {}
64
41
 
65
42
  # Set Headers
66
43
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
67
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
68
-
69
- unless custom_headers.nil?
70
- custom_headers.each do |key, value|
71
- request_headers[key] = value
72
- end
73
- end
74
-
75
- # Send Request
76
- promise = Concurrent::Promise.new do
77
- connection.post do |request|
78
- request.headers = request_headers
79
- @client.credentials.sign_request(request) unless @client.credentials.nil?
80
- end
44
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
45
+ path_template = '/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/unregister'
46
+ options = {
47
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
48
+ path_params: {'resourceProviderNamespace' => resource_provider_namespace,'subscriptionId' => @client.subscription_id},
49
+ query_params: {'api-version' => @client.api_version},
50
+ headers: request_headers.merge(custom_headers || {})
51
+ }
52
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :post, options)
53
+ promise = request.run_promise do |req|
54
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
81
55
  end
82
56
 
83
57
  promise = promise.then do |http_response|
84
58
  status_code = http_response.status
85
59
  response_content = http_response.body
86
- unless (status_code == 200)
60
+ unless status_code == 200
87
61
  error_model = JSON.load(response_content)
88
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
62
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
89
63
  end
90
64
 
91
65
  # Create Result
92
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
66
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
93
67
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
94
68
  # Deserialize Response
95
69
  if status_code == 200
96
70
  begin
97
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
71
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
98
72
  unless parsed_response.nil?
99
73
  parsed_response = Provider.deserialize_object(parsed_response)
100
74
  end
101
75
  result.body = parsed_response
102
76
  rescue Exception => e
103
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
77
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
104
78
  end
105
79
  end
106
80
 
@@ -112,6 +86,7 @@ module Azure::ARM::Resources
112
86
 
113
87
  #
114
88
  # Registers provider to be used with a subscription.
89
+ #
115
90
  # @param resource_provider_namespace [String] Namespace of the resource
116
91
  # provider.
117
92
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -124,71 +99,44 @@ module Azure::ARM::Resources
124
99
  fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
125
100
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
126
101
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
127
- # Construct URL
128
- path = "/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/register"
129
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
130
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
131
- url = URI.join(@client.base_url, path)
132
- properties = {}
133
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
134
- unless url.query.nil?
135
- url.query.split('&').each do |url_item|
136
- url_items_parts = url_item.split('=')
137
- properties[url_items_parts[0]] = url_items_parts[1]
138
- end
139
- end
140
- properties.reject!{ |key, value| value.nil? }
141
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
142
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
143
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
144
- url = URI.parse(corrected_url)
145
-
146
- connection = Faraday.new(:url => url) do |faraday|
147
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
148
- faraday.use :cookie_jar
149
- faraday.adapter Faraday.default_adapter
150
- end
151
- request_headers = Hash.new
102
+ request_headers = {}
152
103
 
153
104
  # Set Headers
154
105
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
155
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
156
-
157
- unless custom_headers.nil?
158
- custom_headers.each do |key, value|
159
- request_headers[key] = value
160
- end
161
- end
162
-
163
- # Send Request
164
- promise = Concurrent::Promise.new do
165
- connection.post do |request|
166
- request.headers = request_headers
167
- @client.credentials.sign_request(request) unless @client.credentials.nil?
168
- end
106
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
107
+ path_template = '/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/register'
108
+ options = {
109
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
110
+ path_params: {'resourceProviderNamespace' => resource_provider_namespace,'subscriptionId' => @client.subscription_id},
111
+ query_params: {'api-version' => @client.api_version},
112
+ headers: request_headers.merge(custom_headers || {})
113
+ }
114
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :post, options)
115
+ promise = request.run_promise do |req|
116
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
169
117
  end
170
118
 
171
119
  promise = promise.then do |http_response|
172
120
  status_code = http_response.status
173
121
  response_content = http_response.body
174
- unless (status_code == 200)
122
+ unless status_code == 200
175
123
  error_model = JSON.load(response_content)
176
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
124
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
177
125
  end
178
126
 
179
127
  # Create Result
180
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
128
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
181
129
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
182
130
  # Deserialize Response
183
131
  if status_code == 200
184
132
  begin
185
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
133
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
186
134
  unless parsed_response.nil?
187
135
  parsed_response = Provider.deserialize_object(parsed_response)
188
136
  end
189
137
  result.body = parsed_response
190
138
  rescue Exception => e
191
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
139
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
192
140
  end
193
141
  end
194
142
 
@@ -200,6 +148,7 @@ module Azure::ARM::Resources
200
148
 
201
149
  #
202
150
  # Gets a list of resource providers.
151
+ #
203
152
  # @param top [Integer] Query parameters. If null is passed returns all
204
153
  # deployments.
205
154
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -211,71 +160,44 @@ module Azure::ARM::Resources
211
160
  def list(top = nil, custom_headers = nil)
212
161
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
213
162
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
214
- # Construct URL
215
- path = "/subscriptions/{subscriptionId}/providers"
216
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
217
- url = URI.join(@client.base_url, path)
218
- properties = {}
219
- properties['$top'] = ERB::Util.url_encode(top.to_s) unless top.nil?
220
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
221
- unless url.query.nil?
222
- url.query.split('&').each do |url_item|
223
- url_items_parts = url_item.split('=')
224
- properties[url_items_parts[0]] = url_items_parts[1]
225
- end
226
- end
227
- properties.reject!{ |key, value| value.nil? }
228
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
229
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
230
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
231
- url = URI.parse(corrected_url)
232
-
233
- connection = Faraday.new(:url => url) do |faraday|
234
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
235
- faraday.use :cookie_jar
236
- faraday.adapter Faraday.default_adapter
237
- end
238
- request_headers = Hash.new
163
+ request_headers = {}
239
164
 
240
165
  # Set Headers
241
166
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
242
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
243
-
244
- unless custom_headers.nil?
245
- custom_headers.each do |key, value|
246
- request_headers[key] = value
247
- end
248
- end
249
-
250
- # Send Request
251
- promise = Concurrent::Promise.new do
252
- connection.get do |request|
253
- request.headers = request_headers
254
- @client.credentials.sign_request(request) unless @client.credentials.nil?
255
- end
167
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
168
+ path_template = '/subscriptions/{subscriptionId}/providers'
169
+ options = {
170
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
171
+ path_params: {'subscriptionId' => @client.subscription_id},
172
+ query_params: {'$top' => top,'api-version' => @client.api_version},
173
+ headers: request_headers.merge(custom_headers || {})
174
+ }
175
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
176
+ promise = request.run_promise do |req|
177
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
256
178
  end
257
179
 
258
180
  promise = promise.then do |http_response|
259
181
  status_code = http_response.status
260
182
  response_content = http_response.body
261
- unless (status_code == 200)
183
+ unless status_code == 200
262
184
  error_model = JSON.load(response_content)
263
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
185
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
264
186
  end
265
187
 
266
188
  # Create Result
267
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
189
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
268
190
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
269
191
  # Deserialize Response
270
192
  if status_code == 200
271
193
  begin
272
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
194
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
273
195
  unless parsed_response.nil?
274
196
  parsed_response = ProviderListResult.deserialize_object(parsed_response)
275
197
  end
276
198
  result.body = parsed_response
277
199
  rescue Exception => e
278
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
200
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
279
201
  end
280
202
  end
281
203
 
@@ -287,6 +209,7 @@ module Azure::ARM::Resources
287
209
 
288
210
  #
289
211
  # Gets a resource provider.
212
+ #
290
213
  # @param resource_provider_namespace [String] Namespace of the resource
291
214
  # provider.
292
215
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -299,71 +222,44 @@ module Azure::ARM::Resources
299
222
  fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
300
223
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
301
224
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
302
- # Construct URL
303
- path = "/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}"
304
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
305
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
306
- url = URI.join(@client.base_url, path)
307
- properties = {}
308
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
309
- unless url.query.nil?
310
- url.query.split('&').each do |url_item|
311
- url_items_parts = url_item.split('=')
312
- properties[url_items_parts[0]] = url_items_parts[1]
313
- end
314
- end
315
- properties.reject!{ |key, value| value.nil? }
316
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
317
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
318
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
319
- url = URI.parse(corrected_url)
320
-
321
- connection = Faraday.new(:url => url) do |faraday|
322
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
323
- faraday.use :cookie_jar
324
- faraday.adapter Faraday.default_adapter
325
- end
326
- request_headers = Hash.new
225
+ request_headers = {}
327
226
 
328
227
  # Set Headers
329
228
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
330
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
331
-
332
- unless custom_headers.nil?
333
- custom_headers.each do |key, value|
334
- request_headers[key] = value
335
- end
336
- end
337
-
338
- # Send Request
339
- promise = Concurrent::Promise.new do
340
- connection.get do |request|
341
- request.headers = request_headers
342
- @client.credentials.sign_request(request) unless @client.credentials.nil?
343
- end
229
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
230
+ path_template = '/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}'
231
+ options = {
232
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
233
+ path_params: {'resourceProviderNamespace' => resource_provider_namespace,'subscriptionId' => @client.subscription_id},
234
+ query_params: {'api-version' => @client.api_version},
235
+ headers: request_headers.merge(custom_headers || {})
236
+ }
237
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
238
+ promise = request.run_promise do |req|
239
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
344
240
  end
345
241
 
346
242
  promise = promise.then do |http_response|
347
243
  status_code = http_response.status
348
244
  response_content = http_response.body
349
- unless (status_code == 200)
245
+ unless status_code == 200
350
246
  error_model = JSON.load(response_content)
351
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
247
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
352
248
  end
353
249
 
354
250
  # Create Result
355
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
251
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
356
252
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
357
253
  # Deserialize Response
358
254
  if status_code == 200
359
255
  begin
360
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
256
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
361
257
  unless parsed_response.nil?
362
258
  parsed_response = Provider.deserialize_object(parsed_response)
363
259
  end
364
260
  result.body = parsed_response
365
261
  rescue Exception => e
366
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
262
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
367
263
  end
368
264
  end
369
265
 
@@ -375,6 +271,7 @@ module Azure::ARM::Resources
375
271
 
376
272
  #
377
273
  # Gets a list of resource providers.
274
+ #
378
275
  # @param next_page_link [String] The NextLink from the previous successful
379
276
  # call to List operation.
380
277
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -385,69 +282,43 @@ module Azure::ARM::Resources
385
282
  #
386
283
  def list_next(next_page_link, custom_headers = nil)
387
284
  fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
388
- # Construct URL
389
- path = "{nextLink}"
390
- path['{nextLink}'] = next_page_link if path.include?('{nextLink}')
391
- url = URI.parse(path)
392
- properties = {}
393
- unless url.query.nil?
394
- url.query.split('&').each do |url_item|
395
- url_items_parts = url_item.split('=')
396
- properties[url_items_parts[0]] = url_items_parts[1]
397
- end
398
- end
399
- properties.reject!{ |key, value| value.nil? }
400
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
401
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
402
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
403
- url = URI.parse(corrected_url)
404
-
405
- connection = Faraday.new(:url => url) do |faraday|
406
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
407
- faraday.use :cookie_jar
408
- faraday.adapter Faraday.default_adapter
409
- end
410
- request_headers = Hash.new
285
+ request_headers = {}
411
286
 
412
287
  # Set Headers
413
288
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
414
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
415
-
416
- unless custom_headers.nil?
417
- custom_headers.each do |key, value|
418
- request_headers[key] = value
419
- end
420
- end
421
-
422
- # Send Request
423
- promise = Concurrent::Promise.new do
424
- connection.get do |request|
425
- request.headers = request_headers
426
- @client.credentials.sign_request(request) unless @client.credentials.nil?
427
- end
289
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
290
+ path_template = '{nextLink}'
291
+ options = {
292
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
293
+ skip_encoding_path_params: {'nextLink' => next_page_link},
294
+ headers: request_headers.merge(custom_headers || {})
295
+ }
296
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
297
+ promise = request.run_promise do |req|
298
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
428
299
  end
429
300
 
430
301
  promise = promise.then do |http_response|
431
302
  status_code = http_response.status
432
303
  response_content = http_response.body
433
- unless (status_code == 200)
304
+ unless status_code == 200
434
305
  error_model = JSON.load(response_content)
435
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
306
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
436
307
  end
437
308
 
438
309
  # Create Result
439
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
310
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
440
311
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
441
312
  # Deserialize Response
442
313
  if status_code == 200
443
314
  begin
444
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
315
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
445
316
  unless parsed_response.nil?
446
317
  parsed_response = ProviderListResult.deserialize_object(parsed_response)
447
318
  end
448
319
  result.body = parsed_response
449
320
  rescue Exception => e
450
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
321
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
451
322
  end
452
323
  end
453
324