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
@@ -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
 
@@ -14,7 +14,7 @@ module Azure::ARM::Resources
14
14
  # @return [String] the base URI of the service.
15
15
  attr_accessor :base_url
16
16
 
17
- # @return [ServiceClientCredentials] The management credentials for Azure.
17
+ # @return Gets Azure subscription credentials.
18
18
  attr_reader :credentials
19
19
 
20
20
  # @return [String] Gets subscription credentials which uniquely identify
@@ -28,13 +28,21 @@ module Azure::ARM::Resources
28
28
  # @return [String] Gets or sets the preferred language for the response.
29
29
  attr_accessor :accept_language
30
30
 
31
- # @return [Integer] The retry timeout for Long Running Operations.
31
+ # @return [Integer] Gets or sets the retry timeout in seconds for Long
32
+ # Running Operations. Default value is 30.
32
33
  attr_accessor :long_running_operation_retry_timeout
33
34
 
34
- # @return [ServiceClient] Subscription credentials which uniquely identify
35
- # client subscription.
35
+ # @return [Boolean] When set to true a unique x-ms-client-request-id value
36
+ # is generated and included in each request. Default is true.
37
+ attr_accessor :generate_client_request_id
38
+
39
+ # @return Subscription credentials which uniquely identify client
40
+ # subscription.
36
41
  attr_accessor :credentials
37
42
 
43
+ # @return deployments
44
+ attr_reader :deployments
45
+
38
46
  # @return providers
39
47
  attr_reader :providers
40
48
 
@@ -53,8 +61,11 @@ module Azure::ARM::Resources
53
61
  # @return resource_provider_operation_details
54
62
  attr_reader :resource_provider_operation_details
55
63
 
56
- # @return deployments
57
- attr_reader :deployments
64
+ # @return policy_definitions
65
+ attr_reader :policy_definitions
66
+
67
+ # @return policy_assignments
68
+ attr_reader :policy_assignments
58
69
 
59
70
  #
60
71
  # Creates initializes a new instance of the ResourceManagementClient class.
@@ -70,15 +81,19 @@ module Azure::ARM::Resources
70
81
  fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials)
71
82
  @credentials = credentials
72
83
 
84
+ @deployments = Deployments.new(self)
73
85
  @providers = Providers.new(self)
74
86
  @resource_groups = ResourceGroups.new(self)
75
87
  @resources = Resources.new(self)
76
88
  @tags = Tags.new(self)
77
89
  @deployment_operations = DeploymentOperations.new(self)
78
90
  @resource_provider_operation_details = ResourceProviderOperationDetails.new(self)
79
- @deployments = Deployments.new(self)
80
- @api_version = "2014-04-01-preview"
81
- @accept_language = "en-US"
91
+ @policy_definitions = PolicyDefinitions.new(self)
92
+ @policy_assignments = PolicyAssignments.new(self)
93
+ @api_version = '2015-11-01'
94
+ @accept_language = 'en-US'
95
+ @long_running_operation_retry_timeout = 30
96
+ @generate_client_request_id = true
82
97
  end
83
98
 
84
99
  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
  # Gets a list of resource providers.
27
+ #
27
28
  # @param resource_provider_namespace [String] Resource identity.
28
29
  # @param api_version [String]
29
30
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -36,83 +37,127 @@ module Azure::ARM::Resources
36
37
  fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
37
38
  fail ArgumentError, 'api_version is nil' if api_version.nil?
38
39
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
39
- # Construct URL
40
- path = "/providers/{resourceProviderNamespace}/operations"
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(api_version.to_s) unless 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?
44
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
45
+ path_template = '/providers/{resourceProviderNamespace}/operations'
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' => api_version},
50
+ headers: request_headers.merge(custom_headers || {})
51
+ }
52
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
53
+ promise = request.run_promise do |req|
54
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
55
+ end
68
56
 
69
- unless custom_headers.nil?
70
- custom_headers.each do |key, value|
71
- request_headers[key] = value
57
+ promise = promise.then do |http_response|
58
+ status_code = http_response.status
59
+ response_content = http_response.body
60
+ unless status_code == 200 || status_code == 204
61
+ error_model = JSON.load(response_content)
62
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
72
63
  end
73
- end
74
64
 
75
- # Send Request
76
- promise = Concurrent::Promise.new do
77
- connection.get do |request|
78
- request.headers = request_headers
79
- @client.credentials.sign_request(request) unless @client.credentials.nil?
65
+ # Create Result
66
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
67
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
68
+ # Deserialize Response
69
+ if status_code == 200
70
+ begin
71
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
72
+ unless parsed_response.nil?
73
+ parsed_response = ResourceProviderOperationDetailListResult.deserialize_object(parsed_response)
74
+ end
75
+ result.body = parsed_response
76
+ rescue Exception => e
77
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
78
+ end
79
+ end
80
+ # Deserialize Response
81
+ if status_code == 204
82
+ begin
83
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
84
+ unless parsed_response.nil?
85
+ parsed_response = ResourceProviderOperationDetailListResult.deserialize_object(parsed_response)
86
+ end
87
+ result.body = parsed_response
88
+ rescue Exception => e
89
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
90
+ end
80
91
  end
92
+
93
+ result
94
+ end
95
+
96
+ promise.execute
97
+ end
98
+
99
+ #
100
+ # Gets a list of resource providers.
101
+ #
102
+ # @param next_page_link [String] The NextLink from the previous successful
103
+ # call to List operation.
104
+ # @param [Hash{String => String}] The hash of custom headers need to be
105
+ # applied to HTTP request.
106
+ #
107
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
108
+ # response.
109
+ #
110
+ def list_next(next_page_link, custom_headers = nil)
111
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
112
+ request_headers = {}
113
+
114
+ # Set Headers
115
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
116
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
117
+ path_template = '{nextLink}'
118
+ options = {
119
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
120
+ skip_encoding_path_params: {'nextLink' => next_page_link},
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?
81
126
  end
82
127
 
83
128
  promise = promise.then do |http_response|
84
129
  status_code = http_response.status
85
130
  response_content = http_response.body
86
- unless (status_code == 200 || status_code == 204)
131
+ unless status_code == 200 || status_code == 204
87
132
  error_model = JSON.load(response_content)
88
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
133
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
89
134
  end
90
135
 
91
136
  # Create Result
92
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
137
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
93
138
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
94
139
  # Deserialize Response
95
140
  if status_code == 200
96
141
  begin
97
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
142
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
98
143
  unless parsed_response.nil?
99
144
  parsed_response = ResourceProviderOperationDetailListResult.deserialize_object(parsed_response)
100
145
  end
101
146
  result.body = parsed_response
102
147
  rescue Exception => e
103
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
148
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
104
149
  end
105
150
  end
106
151
  # Deserialize Response
107
152
  if status_code == 204
108
153
  begin
109
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
154
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
110
155
  unless parsed_response.nil?
111
156
  parsed_response = ResourceProviderOperationDetailListResult.deserialize_object(parsed_response)
112
157
  end
113
158
  result.body = parsed_response
114
159
  rescue Exception => e
115
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
160
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
116
161
  end
117
162
  end
118
163
 
@@ -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
 
@@ -23,7 +23,34 @@ module Azure::ARM::Resources
23
23
  attr_reader :client
24
24
 
25
25
  #
26
- # Move resources within or across subscriptions.
26
+ # Begin moving resources.To determine whether the operation has finished
27
+ # processing the request, call GetLongRunningOperationStatus.
28
+ #
29
+ # @param source_resource_group_name [String] Source resource group name.
30
+ # @param parameters [ResourcesMoveInfo] move resources' parameters.
31
+ # @return [Concurrent::Promise] promise which provides async access to http
32
+ # response.
33
+ #
34
+ def move_resources(source_resource_group_name, parameters, custom_headers = nil)
35
+ # Send request
36
+ promise = begin_move_resources(source_resource_group_name, parameters, custom_headers)
37
+
38
+ promise = promise.then do |response|
39
+ # Defining deserialization method.
40
+ deserialize_method = lambda do |parsed_response|
41
+ end
42
+
43
+ # Waiting for response.
44
+ @client.get_post_or_delete_operation_result(response, deserialize_method)
45
+ end
46
+
47
+ promise
48
+ end
49
+
50
+ #
51
+ # Begin moving resources.To determine whether the operation has finished
52
+ # processing the request, call GetLongRunningOperationStatus.
53
+ #
27
54
  # @param source_resource_group_name [String] Source resource group name.
28
55
  # @param parameters [ResourcesMoveInfo] move resources' parameters.
29
56
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -32,73 +59,47 @@ module Azure::ARM::Resources
32
59
  # @return [Concurrent::Promise] Promise object which allows to get HTTP
33
60
  # response.
34
61
  #
35
- def move_resources(source_resource_group_name, parameters, custom_headers = nil)
62
+ def begin_move_resources(source_resource_group_name, parameters, custom_headers = nil)
36
63
  fail ArgumentError, 'source_resource_group_name is nil' if source_resource_group_name.nil?
37
64
  fail ArgumentError, 'parameters is nil' if parameters.nil?
38
65
  parameters.validate unless parameters.nil?
39
66
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
40
67
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
41
- # Construct URL
42
- path = "/subscriptions/{subscriptionId}/resourceGroups/{sourceResourceGroupName}/moveResources"
43
- path['{sourceResourceGroupName}'] = ERB::Util.url_encode(source_resource_group_name) if path.include?('{sourceResourceGroupName}')
44
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
45
- url = URI.join(@client.base_url, path)
46
- properties = {}
47
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
48
- unless url.query.nil?
49
- url.query.split('&').each do |url_item|
50
- url_items_parts = url_item.split('=')
51
- properties[url_items_parts[0]] = url_items_parts[1]
52
- end
53
- end
54
- properties.reject!{ |key, value| value.nil? }
55
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
56
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
57
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
58
- url = URI.parse(corrected_url)
59
-
60
- connection = Faraday.new(:url => url) do |faraday|
61
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
62
- faraday.use :cookie_jar
63
- faraday.adapter Faraday.default_adapter
64
- end
65
- request_headers = Hash.new
68
+ request_headers = {}
66
69
 
67
70
  # Set Headers
68
71
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
69
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
70
-
71
- unless custom_headers.nil?
72
- custom_headers.each do |key, value|
73
- request_headers[key] = value
74
- end
75
- end
72
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
76
73
 
77
74
  # Serialize Request
78
- request_headers['Content-Type'] = 'application/json'
75
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
79
76
  unless parameters.nil?
80
77
  parameters = ResourcesMoveInfo.serialize_object(parameters)
81
78
  end
82
79
  request_content = JSON.generate(parameters, quirks_mode: true)
83
-
84
- # Send Request
85
- promise = Concurrent::Promise.new do
86
- connection.post do |request|
87
- request.headers = request_headers
88
- request.body = request_content
89
- @client.credentials.sign_request(request) unless @client.credentials.nil?
90
- end
80
+ path_template = '/subscriptions/{subscriptionId}/resourceGroups/{sourceResourceGroupName}/moveResources'
81
+ options = {
82
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
83
+ path_params: {'sourceResourceGroupName' => source_resource_group_name,'subscriptionId' => @client.subscription_id},
84
+ query_params: {'api-version' => @client.api_version},
85
+ body: request_content,
86
+ headers: request_headers.merge(custom_headers || {})
87
+ }
88
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :post, options)
89
+ promise = request.run_promise do |req|
90
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
91
91
  end
92
92
 
93
93
  promise = promise.then do |http_response|
94
94
  status_code = http_response.status
95
95
  response_content = http_response.body
96
- unless (status_code == 202)
97
- fail MsRestAzure::AzureOperationError.new(connection, http_response)
96
+ unless status_code == 202 || status_code == 204
97
+ error_model = JSON.load(response_content)
98
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
98
99
  end
99
100
 
100
101
  # Create Result
101
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
102
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
102
103
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
103
104
 
104
105
  result
@@ -109,6 +110,7 @@ module Azure::ARM::Resources
109
110
 
110
111
  #
111
112
  # Get all of the resources under a subscription.
113
+ #
112
114
  # @param filter [String] The filter to apply on the operation.
113
115
  # @param top [Integer] Query parameters. If null is passed returns all
114
116
  # resource groups.
@@ -121,72 +123,44 @@ module Azure::ARM::Resources
121
123
  def list(filter = nil, top = nil, custom_headers = nil)
122
124
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
123
125
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
124
- # Construct URL
125
- path = "/subscriptions/{subscriptionId}/resources"
126
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
127
- url = URI.join(@client.base_url, path)
128
- properties = {}
129
- properties['$filter'] = ERB::Util.url_encode(filter.to_s) unless filter.nil?
130
- properties['$top'] = ERB::Util.url_encode(top.to_s) unless top.nil?
131
- properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
132
- unless url.query.nil?
133
- url.query.split('&').each do |url_item|
134
- url_items_parts = url_item.split('=')
135
- properties[url_items_parts[0]] = url_items_parts[1]
136
- end
137
- end
138
- properties.reject!{ |key, value| value.nil? }
139
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
140
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
141
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
142
- url = URI.parse(corrected_url)
143
-
144
- connection = Faraday.new(:url => url) do |faraday|
145
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
146
- faraday.use :cookie_jar
147
- faraday.adapter Faraday.default_adapter
148
- end
149
- request_headers = Hash.new
126
+ request_headers = {}
150
127
 
151
128
  # Set Headers
152
129
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
153
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
154
-
155
- unless custom_headers.nil?
156
- custom_headers.each do |key, value|
157
- request_headers[key] = value
158
- end
159
- end
160
-
161
- # Send Request
162
- promise = Concurrent::Promise.new do
163
- connection.get do |request|
164
- request.headers = request_headers
165
- @client.credentials.sign_request(request) unless @client.credentials.nil?
166
- end
130
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
131
+ path_template = '/subscriptions/{subscriptionId}/resources'
132
+ options = {
133
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
134
+ path_params: {'subscriptionId' => @client.subscription_id},
135
+ query_params: {'$filter' => filter,'$top' => top,'api-version' => @client.api_version},
136
+ headers: request_headers.merge(custom_headers || {})
137
+ }
138
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
139
+ promise = request.run_promise do |req|
140
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
167
141
  end
168
142
 
169
143
  promise = promise.then do |http_response|
170
144
  status_code = http_response.status
171
145
  response_content = http_response.body
172
- unless (status_code == 200)
146
+ unless status_code == 200
173
147
  error_model = JSON.load(response_content)
174
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
148
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
175
149
  end
176
150
 
177
151
  # Create Result
178
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
152
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
179
153
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
180
154
  # Deserialize Response
181
155
  if status_code == 200
182
156
  begin
183
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
157
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
184
158
  unless parsed_response.nil?
185
159
  parsed_response = ResourceListResult.deserialize_object(parsed_response)
186
160
  end
187
161
  result.body = parsed_response
188
162
  rescue Exception => e
189
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
163
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
190
164
  end
191
165
  end
192
166
 
@@ -198,6 +172,7 @@ module Azure::ARM::Resources
198
172
 
199
173
  #
200
174
  # Checks whether resource exists.
175
+ #
201
176
  # @param resource_group_name [String] The name of the resource group. The name
202
177
  # is case insensitive.
203
178
  # @param resource_provider_namespace [String] Resource identity.
@@ -219,64 +194,34 @@ module Azure::ARM::Resources
219
194
  fail ArgumentError, 'resource_name is nil' if resource_name.nil?
220
195
  fail ArgumentError, 'api_version is nil' if api_version.nil?
221
196
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
222
- # Construct URL
223
- path = "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}"
224
- path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
225
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
226
- path['{parentResourcePath}'] = parent_resource_path if path.include?('{parentResourcePath}')
227
- path['{resourceType}'] = resource_type if path.include?('{resourceType}')
228
- path['{resourceName}'] = ERB::Util.url_encode(resource_name) if path.include?('{resourceName}')
229
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
230
- url = URI.join(@client.base_url, path)
231
- properties = {}
232
- properties['api-version'] = ERB::Util.url_encode(api_version.to_s) unless api_version.nil?
233
- unless url.query.nil?
234
- url.query.split('&').each do |url_item|
235
- url_items_parts = url_item.split('=')
236
- properties[url_items_parts[0]] = url_items_parts[1]
237
- end
238
- end
239
- properties.reject!{ |key, value| value.nil? }
240
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
241
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
242
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
243
- url = URI.parse(corrected_url)
244
-
245
- connection = Faraday.new(:url => url) do |faraday|
246
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
247
- faraday.use :cookie_jar
248
- faraday.adapter Faraday.default_adapter
249
- end
250
- request_headers = Hash.new
197
+ request_headers = {}
251
198
 
252
199
  # Set Headers
253
200
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
254
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
255
-
256
- unless custom_headers.nil?
257
- custom_headers.each do |key, value|
258
- request_headers[key] = value
259
- end
260
- end
261
-
262
- # Send Request
263
- promise = Concurrent::Promise.new do
264
- connection.head do |request|
265
- request.headers = request_headers
266
- @client.credentials.sign_request(request) unless @client.credentials.nil?
267
- end
201
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
202
+ path_template = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}'
203
+ options = {
204
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
205
+ path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
206
+ skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
207
+ query_params: {'api-version' => api_version},
208
+ headers: request_headers.merge(custom_headers || {})
209
+ }
210
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :head, options)
211
+ promise = request.run_promise do |req|
212
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
268
213
  end
269
214
 
270
215
  promise = promise.then do |http_response|
271
216
  status_code = http_response.status
272
217
  response_content = http_response.body
273
- unless (status_code == 204 || status_code == 404)
218
+ unless status_code == 204 || status_code == 404
274
219
  error_model = JSON.load(response_content)
275
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
220
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
276
221
  end
277
222
 
278
223
  # Create Result
279
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
224
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
280
225
  result.body = (status_code == 204)
281
226
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
282
227
 
@@ -288,6 +233,7 @@ module Azure::ARM::Resources
288
233
 
289
234
  #
290
235
  # Delete resource and all of its resources.
236
+ #
291
237
  # @param resource_group_name [String] The name of the resource group. The name
292
238
  # is case insensitive.
293
239
  # @param resource_provider_namespace [String] Resource identity.
@@ -309,63 +255,34 @@ module Azure::ARM::Resources
309
255
  fail ArgumentError, 'resource_name is nil' if resource_name.nil?
310
256
  fail ArgumentError, 'api_version is nil' if api_version.nil?
311
257
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
312
- # Construct URL
313
- path = "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}"
314
- path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
315
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
316
- path['{parentResourcePath}'] = parent_resource_path if path.include?('{parentResourcePath}')
317
- path['{resourceType}'] = resource_type if path.include?('{resourceType}')
318
- path['{resourceName}'] = ERB::Util.url_encode(resource_name) if path.include?('{resourceName}')
319
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
320
- url = URI.join(@client.base_url, path)
321
- properties = {}
322
- properties['api-version'] = ERB::Util.url_encode(api_version.to_s) unless api_version.nil?
323
- unless url.query.nil?
324
- url.query.split('&').each do |url_item|
325
- url_items_parts = url_item.split('=')
326
- properties[url_items_parts[0]] = url_items_parts[1]
327
- end
328
- end
329
- properties.reject!{ |key, value| value.nil? }
330
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
331
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
332
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
333
- url = URI.parse(corrected_url)
334
-
335
- connection = Faraday.new(:url => url) do |faraday|
336
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
337
- faraday.use :cookie_jar
338
- faraday.adapter Faraday.default_adapter
339
- end
340
- request_headers = Hash.new
258
+ request_headers = {}
341
259
 
342
260
  # Set Headers
343
261
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
344
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
345
-
346
- unless custom_headers.nil?
347
- custom_headers.each do |key, value|
348
- request_headers[key] = value
349
- end
350
- end
351
-
352
- # Send Request
353
- promise = Concurrent::Promise.new do
354
- connection.delete do |request|
355
- request.headers = request_headers
356
- @client.credentials.sign_request(request) unless @client.credentials.nil?
357
- end
262
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
263
+ path_template = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}'
264
+ options = {
265
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
266
+ path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
267
+ skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
268
+ query_params: {'api-version' => api_version},
269
+ headers: request_headers.merge(custom_headers || {})
270
+ }
271
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :delete, options)
272
+ promise = request.run_promise do |req|
273
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
358
274
  end
359
275
 
360
276
  promise = promise.then do |http_response|
361
277
  status_code = http_response.status
362
278
  response_content = http_response.body
363
- unless (status_code == 200 || status_code == 204 || status_code == 202)
364
- fail MsRestAzure::AzureOperationError.new(connection, http_response)
279
+ unless status_code == 200 || status_code == 204 || status_code == 202
280
+ error_model = JSON.load(response_content)
281
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
365
282
  end
366
283
 
367
284
  # Create Result
368
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
285
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
369
286
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
370
287
 
371
288
  result
@@ -376,44 +293,7 @@ module Azure::ARM::Resources
376
293
 
377
294
  #
378
295
  # Create a resource.
379
- # @param resource_group_name [String] The name of the resource group. The name
380
- # is case insensitive.
381
- # @param resource_provider_namespace [String] Resource identity.
382
- # @param parent_resource_path [String] Resource identity.
383
- # @param resource_type [String] Resource identity.
384
- # @param resource_name [String] Resource identity.
385
- # @param api_version [String]
386
- # @param parameters [GenericResource] Create or update resource parameters.
387
- # @param @client.subscription_id [String] Gets subscription credentials which
388
- # uniquely identify Microsoft Azure subscription. The subscription ID forms
389
- # part of the URI for every service call.
390
- # @param @client.accept_language [String] Gets or sets the preferred language
391
- # for the response.
392
- #
393
- # @return [Concurrent::Promise] promise which provides async access to http
394
- # response.
395
- #
396
- def create_or_update(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, api_version, parameters, custom_headers = nil)
397
- # Send request
398
- promise = begin_create_or_update(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, api_version, parameters, custom_headers)
399
-
400
- promise = promise.then do |response|
401
- # Defining deserialization method.
402
- deserialize_method = lambda do |parsed_response|
403
- unless parsed_response.nil?
404
- parsed_response = GenericResource.deserialize_object(parsed_response)
405
- end
406
- end
407
-
408
- # Waiting for response.
409
- @client.get_put_operation_result(response, custom_headers, deserialize_method)
410
- end
411
-
412
- promise
413
- end
414
-
415
296
  #
416
- # Create a resource.
417
297
  # @param resource_group_name [String] The name of the resource group. The name
418
298
  # is case insensitive.
419
299
  # @param resource_provider_namespace [String] Resource identity.
@@ -428,7 +308,7 @@ module Azure::ARM::Resources
428
308
  # @return [Concurrent::Promise] Promise object which allows to get HTTP
429
309
  # response.
430
310
  #
431
- def begin_create_or_update(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, api_version, parameters, custom_headers = nil)
311
+ def create_or_update(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, api_version, parameters, custom_headers = nil)
432
312
  fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
433
313
  fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
434
314
  fail ArgumentError, 'parent_resource_path is nil' if parent_resource_path.nil?
@@ -438,95 +318,65 @@ module Azure::ARM::Resources
438
318
  fail ArgumentError, 'parameters is nil' if parameters.nil?
439
319
  parameters.validate unless parameters.nil?
440
320
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
441
- # Construct URL
442
- path = "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}"
443
- path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
444
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
445
- path['{parentResourcePath}'] = parent_resource_path if path.include?('{parentResourcePath}')
446
- path['{resourceType}'] = resource_type if path.include?('{resourceType}')
447
- path['{resourceName}'] = ERB::Util.url_encode(resource_name) if path.include?('{resourceName}')
448
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
449
- url = URI.join(@client.base_url, path)
450
- properties = {}
451
- properties['api-version'] = ERB::Util.url_encode(api_version.to_s) unless api_version.nil?
452
- unless url.query.nil?
453
- url.query.split('&').each do |url_item|
454
- url_items_parts = url_item.split('=')
455
- properties[url_items_parts[0]] = url_items_parts[1]
456
- end
457
- end
458
- properties.reject!{ |key, value| value.nil? }
459
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
460
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
461
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
462
- url = URI.parse(corrected_url)
463
-
464
- connection = Faraday.new(:url => url) do |faraday|
465
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
466
- faraday.use :cookie_jar
467
- faraday.adapter Faraday.default_adapter
468
- end
469
- request_headers = Hash.new
321
+ request_headers = {}
470
322
 
471
323
  # Set Headers
472
324
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
473
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
474
-
475
- unless custom_headers.nil?
476
- custom_headers.each do |key, value|
477
- request_headers[key] = value
478
- end
479
- end
325
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
480
326
 
481
327
  # Serialize Request
482
- request_headers['Content-Type'] = 'application/json'
328
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
483
329
  unless parameters.nil?
484
330
  parameters = GenericResource.serialize_object(parameters)
485
331
  end
486
332
  request_content = JSON.generate(parameters, quirks_mode: true)
487
-
488
- # Send Request
489
- promise = Concurrent::Promise.new do
490
- connection.put do |request|
491
- request.headers = request_headers
492
- request.body = request_content
493
- @client.credentials.sign_request(request) unless @client.credentials.nil?
494
- end
333
+ path_template = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}'
334
+ options = {
335
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
336
+ path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
337
+ skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
338
+ query_params: {'api-version' => api_version},
339
+ body: request_content,
340
+ headers: request_headers.merge(custom_headers || {})
341
+ }
342
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :put, options)
343
+ promise = request.run_promise do |req|
344
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
495
345
  end
496
346
 
497
347
  promise = promise.then do |http_response|
498
348
  status_code = http_response.status
499
349
  response_content = http_response.body
500
- unless (status_code == 201 || status_code == 202 || status_code == 200)
350
+ unless status_code == 201 || status_code == 200
501
351
  error_model = JSON.load(response_content)
502
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
352
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
503
353
  end
504
354
 
505
355
  # Create Result
506
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
356
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
507
357
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
508
358
  # Deserialize Response
509
359
  if status_code == 201
510
360
  begin
511
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
361
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
512
362
  unless parsed_response.nil?
513
363
  parsed_response = GenericResource.deserialize_object(parsed_response)
514
364
  end
515
365
  result.body = parsed_response
516
366
  rescue Exception => e
517
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
367
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
518
368
  end
519
369
  end
520
370
  # Deserialize Response
521
371
  if status_code == 200
522
372
  begin
523
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
373
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
524
374
  unless parsed_response.nil?
525
375
  parsed_response = GenericResource.deserialize_object(parsed_response)
526
376
  end
527
377
  result.body = parsed_response
528
378
  rescue Exception => e
529
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
379
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
530
380
  end
531
381
  end
532
382
 
@@ -538,6 +388,7 @@ module Azure::ARM::Resources
538
388
 
539
389
  #
540
390
  # Returns a resource belonging to a resource group.
391
+ #
541
392
  # @param resource_group_name [String] The name of the resource group. The name
542
393
  # is case insensitive.
543
394
  # @param resource_provider_namespace [String] Resource identity.
@@ -559,87 +410,57 @@ module Azure::ARM::Resources
559
410
  fail ArgumentError, 'resource_name is nil' if resource_name.nil?
560
411
  fail ArgumentError, 'api_version is nil' if api_version.nil?
561
412
  fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
562
- # Construct URL
563
- path = "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}"
564
- path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
565
- path['{resourceProviderNamespace}'] = ERB::Util.url_encode(resource_provider_namespace) if path.include?('{resourceProviderNamespace}')
566
- path['{parentResourcePath}'] = parent_resource_path if path.include?('{parentResourcePath}')
567
- path['{resourceType}'] = resource_type if path.include?('{resourceType}')
568
- path['{resourceName}'] = ERB::Util.url_encode(resource_name) if path.include?('{resourceName}')
569
- path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
570
- url = URI.join(@client.base_url, path)
571
- properties = {}
572
- properties['api-version'] = ERB::Util.url_encode(api_version.to_s) unless api_version.nil?
573
- unless url.query.nil?
574
- url.query.split('&').each do |url_item|
575
- url_items_parts = url_item.split('=')
576
- properties[url_items_parts[0]] = url_items_parts[1]
577
- end
578
- end
579
- properties.reject!{ |key, value| value.nil? }
580
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
581
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
582
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
583
- url = URI.parse(corrected_url)
584
-
585
- connection = Faraday.new(:url => url) do |faraday|
586
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
587
- faraday.use :cookie_jar
588
- faraday.adapter Faraday.default_adapter
589
- end
590
- request_headers = Hash.new
413
+ request_headers = {}
591
414
 
592
415
  # Set Headers
593
416
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
594
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
595
-
596
- unless custom_headers.nil?
597
- custom_headers.each do |key, value|
598
- request_headers[key] = value
599
- end
600
- end
601
-
602
- # Send Request
603
- promise = Concurrent::Promise.new do
604
- connection.get do |request|
605
- request.headers = request_headers
606
- @client.credentials.sign_request(request) unless @client.credentials.nil?
607
- end
417
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
418
+ path_template = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}'
419
+ options = {
420
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
421
+ path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
422
+ skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
423
+ query_params: {'api-version' => api_version},
424
+ headers: request_headers.merge(custom_headers || {})
425
+ }
426
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
427
+ promise = request.run_promise do |req|
428
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
608
429
  end
609
430
 
610
431
  promise = promise.then do |http_response|
611
432
  status_code = http_response.status
612
433
  response_content = http_response.body
613
- unless (status_code == 200 || status_code == 204)
434
+ unless status_code == 200 || status_code == 204
614
435
  error_model = JSON.load(response_content)
615
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
436
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
616
437
  end
617
438
 
618
439
  # Create Result
619
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
440
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
620
441
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
621
442
  # Deserialize Response
622
443
  if status_code == 200
623
444
  begin
624
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
445
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
625
446
  unless parsed_response.nil?
626
447
  parsed_response = GenericResource.deserialize_object(parsed_response)
627
448
  end
628
449
  result.body = parsed_response
629
450
  rescue Exception => e
630
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
451
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
631
452
  end
632
453
  end
633
454
  # Deserialize Response
634
455
  if status_code == 204
635
456
  begin
636
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
457
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
637
458
  unless parsed_response.nil?
638
459
  parsed_response = GenericResource.deserialize_object(parsed_response)
639
460
  end
640
461
  result.body = parsed_response
641
462
  rescue Exception => e
642
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
463
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
643
464
  end
644
465
  end
645
466
 
@@ -651,6 +472,7 @@ module Azure::ARM::Resources
651
472
 
652
473
  #
653
474
  # Get all of the resources under a subscription.
475
+ #
654
476
  # @param next_page_link [String] The NextLink from the previous successful
655
477
  # call to List operation.
656
478
  # @param [Hash{String => String}] The hash of custom headers need to be
@@ -661,69 +483,43 @@ module Azure::ARM::Resources
661
483
  #
662
484
  def list_next(next_page_link, custom_headers = nil)
663
485
  fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
664
- # Construct URL
665
- path = "{nextLink}"
666
- path['{nextLink}'] = next_page_link if path.include?('{nextLink}')
667
- url = URI.parse(path)
668
- properties = {}
669
- unless url.query.nil?
670
- url.query.split('&').each do |url_item|
671
- url_items_parts = url_item.split('=')
672
- properties[url_items_parts[0]] = url_items_parts[1]
673
- end
674
- end
675
- properties.reject!{ |key, value| value.nil? }
676
- url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
677
- fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
678
- corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
679
- url = URI.parse(corrected_url)
680
-
681
- connection = Faraday.new(:url => url) do |faraday|
682
- faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
683
- faraday.use :cookie_jar
684
- faraday.adapter Faraday.default_adapter
685
- end
686
- request_headers = Hash.new
486
+ request_headers = {}
687
487
 
688
488
  # Set Headers
689
489
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
690
- request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
691
-
692
- unless custom_headers.nil?
693
- custom_headers.each do |key, value|
694
- request_headers[key] = value
695
- end
696
- end
697
-
698
- # Send Request
699
- promise = Concurrent::Promise.new do
700
- connection.get do |request|
701
- request.headers = request_headers
702
- @client.credentials.sign_request(request) unless @client.credentials.nil?
703
- end
490
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
491
+ path_template = '{nextLink}'
492
+ options = {
493
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
494
+ skip_encoding_path_params: {'nextLink' => next_page_link},
495
+ headers: request_headers.merge(custom_headers || {})
496
+ }
497
+ request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :get, options)
498
+ promise = request.run_promise do |req|
499
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
704
500
  end
705
501
 
706
502
  promise = promise.then do |http_response|
707
503
  status_code = http_response.status
708
504
  response_content = http_response.body
709
- unless (status_code == 200)
505
+ unless status_code == 200
710
506
  error_model = JSON.load(response_content)
711
- fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
507
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
712
508
  end
713
509
 
714
510
  # Create Result
715
- result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
511
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
716
512
  result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
717
513
  # Deserialize Response
718
514
  if status_code == 200
719
515
  begin
720
- parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
516
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
721
517
  unless parsed_response.nil?
722
518
  parsed_response = ResourceListResult.deserialize_object(parsed_response)
723
519
  end
724
520
  result.body = parsed_response
725
521
  rescue Exception => e
726
- fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
522
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
727
523
  end
728
524
  end
729
525