azure_mgmt_policy 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.17.0.0
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Policy
7
+ #
8
+ # A service client - single point of access to the REST API.
9
+ #
10
+ class PolicyClient < MsRestAzure::AzureServiceClient
11
+ include MsRest::Serialization
12
+ include MsRestAzure
13
+
14
+ # @return [String] the base URI of the service.
15
+ attr_accessor :base_url
16
+
17
+ # @return Credentials needed for the client to connect to Azure.
18
+ attr_reader :credentials
19
+
20
+ # @return [String] Gets subscription credentials which uniquely identify
21
+ # Microsoft Azure subscription. The subscription ID forms part of the URI
22
+ # for every service call.
23
+ attr_accessor :subscription_id
24
+
25
+ # @return [String] Client Api Version.
26
+ attr_reader :api_version
27
+
28
+ # @return [String] Gets or sets the preferred language for the response.
29
+ attr_accessor :accept_language
30
+
31
+ # @return [Integer] Gets or sets the retry timeout in seconds for Long
32
+ # Running Operations. Default value is 30.
33
+ attr_accessor :long_running_operation_retry_timeout
34
+
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.
41
+ attr_accessor :credentials
42
+
43
+ # @return [PolicyAssignments] policy_assignments
44
+ attr_reader :policy_assignments
45
+
46
+ # @return [PolicyDefinitions] policy_definitions
47
+ attr_reader :policy_definitions
48
+
49
+ #
50
+ # Creates initializes a new instance of the PolicyClient class.
51
+ # @param credentials [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client.
52
+ # @param base_url [String] the base URI of the service.
53
+ # @param options [Array] filters to be applied to the HTTP requests.
54
+ #
55
+ def initialize(credentials, base_url = nil, options = nil)
56
+ super(credentials, options)
57
+ @base_url = base_url || 'https://management.azure.com'
58
+
59
+ fail ArgumentError, 'credentials is nil' if credentials.nil?
60
+ fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials)
61
+ @credentials = credentials
62
+
63
+ @policy_assignments = PolicyAssignments.new(self)
64
+ @policy_definitions = PolicyDefinitions.new(self)
65
+ @api_version = '2016-04-01'
66
+ @accept_language = 'en-US'
67
+ @long_running_operation_retry_timeout = 30
68
+ @generate_client_request_id = true
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,498 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.17.0.0
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Policy
7
+ #
8
+ # PolicyDefinitions
9
+ #
10
+ class PolicyDefinitions
11
+ include Azure::ARM::Policy::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 PolicyClient
23
+ attr_reader :client
24
+
25
+ #
26
+ # Create or update a policy definition.
27
+ #
28
+ # @param policy_definition_name [String] The policy definition name.
29
+ # @param parameters [PolicyDefinition] The policy definition properties.
30
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
31
+ # will be added to the HTTP request.
32
+ #
33
+ # @return [PolicyDefinition] operation results.
34
+ #
35
+ def create_or_update(policy_definition_name, parameters, custom_headers = nil)
36
+ response = create_or_update_async(policy_definition_name, parameters, custom_headers).value!
37
+ response.body unless response.nil?
38
+ end
39
+
40
+ #
41
+ # Create or update a policy definition.
42
+ #
43
+ # @param policy_definition_name [String] The policy definition name.
44
+ # @param parameters [PolicyDefinition] The policy definition properties.
45
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
46
+ # will be added to the HTTP request.
47
+ #
48
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
49
+ #
50
+ def create_or_update_with_http_info(policy_definition_name, parameters, custom_headers = nil)
51
+ create_or_update_async(policy_definition_name, parameters, custom_headers).value!
52
+ end
53
+
54
+ #
55
+ # Create or update a policy definition.
56
+ #
57
+ # @param policy_definition_name [String] The policy definition name.
58
+ # @param parameters [PolicyDefinition] The policy definition properties.
59
+ # @param [Hash{String => String}] A hash of custom headers that will be added
60
+ # to the HTTP request.
61
+ #
62
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
63
+ #
64
+ def create_or_update_async(policy_definition_name, parameters, custom_headers = nil)
65
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
66
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
67
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
68
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
69
+
70
+
71
+ request_headers = {}
72
+
73
+ # Set Headers
74
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
75
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
76
+
77
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
78
+
79
+ # Serialize Request
80
+ request_mapper = PolicyDefinition.mapper()
81
+ request_content = @client.serialize(request_mapper, parameters, 'parameters')
82
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
83
+
84
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
85
+ options = {
86
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
87
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
88
+ query_params: {'api-version' => @client.api_version},
89
+ body: request_content,
90
+ headers: request_headers.merge(custom_headers || {})
91
+ }
92
+
93
+ request_url = @base_url || @client.base_url
94
+
95
+ request = MsRest::HttpOperationRequest.new(request_url, path_template, :put, options)
96
+ promise = request.run_promise do |req|
97
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
98
+ end
99
+
100
+ promise = promise.then do |http_response|
101
+ status_code = http_response.status
102
+ response_content = http_response.body
103
+ unless status_code == 201
104
+ error_model = JSON.load(response_content)
105
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
106
+ end
107
+
108
+ # Create Result
109
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
110
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
111
+ # Deserialize Response
112
+ if status_code == 201
113
+ begin
114
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
115
+ result_mapper = PolicyDefinition.mapper()
116
+ result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
117
+ rescue Exception => e
118
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
119
+ end
120
+ end
121
+
122
+ result
123
+ end
124
+
125
+ promise.execute
126
+ end
127
+
128
+ #
129
+ # Deletes the policy definition.
130
+ #
131
+ # @param policy_definition_name [String] The policy definition name.
132
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
133
+ # will be added to the HTTP request.
134
+ #
135
+ #
136
+ def delete(policy_definition_name, custom_headers = nil)
137
+ response = delete_async(policy_definition_name, custom_headers).value!
138
+ nil
139
+ end
140
+
141
+ #
142
+ # Deletes the policy definition.
143
+ #
144
+ # @param policy_definition_name [String] The policy definition name.
145
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
146
+ # will be added to the HTTP request.
147
+ #
148
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
149
+ #
150
+ def delete_with_http_info(policy_definition_name, custom_headers = nil)
151
+ delete_async(policy_definition_name, custom_headers).value!
152
+ end
153
+
154
+ #
155
+ # Deletes the policy definition.
156
+ #
157
+ # @param policy_definition_name [String] The policy definition name.
158
+ # @param [Hash{String => String}] A hash of custom headers that will be added
159
+ # to the HTTP request.
160
+ #
161
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
162
+ #
163
+ def delete_async(policy_definition_name, custom_headers = nil)
164
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
165
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
166
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
167
+
168
+
169
+ request_headers = {}
170
+
171
+ # Set Headers
172
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
173
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
174
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
175
+ options = {
176
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
177
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
178
+ query_params: {'api-version' => @client.api_version},
179
+ headers: request_headers.merge(custom_headers || {})
180
+ }
181
+
182
+ request_url = @base_url || @client.base_url
183
+
184
+ request = MsRest::HttpOperationRequest.new(request_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 == 204 || 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
+ #
208
+ # Gets the policy definition.
209
+ #
210
+ # @param policy_definition_name [String] The policy definition name.
211
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
212
+ # will be added to the HTTP request.
213
+ #
214
+ # @return [PolicyDefinition] operation results.
215
+ #
216
+ def get(policy_definition_name, custom_headers = nil)
217
+ response = get_async(policy_definition_name, custom_headers).value!
218
+ response.body unless response.nil?
219
+ end
220
+
221
+ #
222
+ # Gets the policy definition.
223
+ #
224
+ # @param policy_definition_name [String] The policy definition name.
225
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
226
+ # will be added to the HTTP request.
227
+ #
228
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
229
+ #
230
+ def get_with_http_info(policy_definition_name, custom_headers = nil)
231
+ get_async(policy_definition_name, custom_headers).value!
232
+ end
233
+
234
+ #
235
+ # Gets the policy definition.
236
+ #
237
+ # @param policy_definition_name [String] The policy definition name.
238
+ # @param [Hash{String => String}] A hash of custom headers that will be added
239
+ # to the HTTP request.
240
+ #
241
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
242
+ #
243
+ def get_async(policy_definition_name, custom_headers = nil)
244
+ fail ArgumentError, 'policy_definition_name is nil' if policy_definition_name.nil?
245
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
246
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
247
+
248
+
249
+ request_headers = {}
250
+
251
+ # Set Headers
252
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
253
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
254
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions/{policyDefinitionName}'
255
+ options = {
256
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
257
+ path_params: {'policyDefinitionName' => policy_definition_name,'subscriptionId' => @client.subscription_id},
258
+ query_params: {'api-version' => @client.api_version},
259
+ headers: request_headers.merge(custom_headers || {})
260
+ }
261
+
262
+ request_url = @base_url || @client.base_url
263
+
264
+ request = MsRest::HttpOperationRequest.new(request_url, path_template, :get, options)
265
+ promise = request.run_promise do |req|
266
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
267
+ end
268
+
269
+ promise = promise.then do |http_response|
270
+ status_code = http_response.status
271
+ response_content = http_response.body
272
+ unless status_code == 200
273
+ error_model = JSON.load(response_content)
274
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
275
+ end
276
+
277
+ # Create Result
278
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
279
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
280
+ # Deserialize Response
281
+ if status_code == 200
282
+ begin
283
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
284
+ result_mapper = PolicyDefinition.mapper()
285
+ result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
286
+ rescue Exception => e
287
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
288
+ end
289
+ end
290
+
291
+ result
292
+ end
293
+
294
+ promise.execute
295
+ end
296
+
297
+ #
298
+ # Gets all the policy definitions of a subscription.
299
+ #
300
+ # @param filter [String] The filter to apply on the operation.
301
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
302
+ # will be added to the HTTP request.
303
+ #
304
+ # @return [PolicyDefinitionListResult] which provide lazy access to pages of
305
+ # the response.
306
+ #
307
+ def list_as_lazy(filter = nil, custom_headers = nil)
308
+ response = list_async(filter, custom_headers).value!
309
+ unless response.nil?
310
+ page = response.body
311
+ page.next_method = Proc.new do |next_link|
312
+ list_next_async(next_link, custom_headers)
313
+ end
314
+ page
315
+ end
316
+ end
317
+
318
+ #
319
+ # Gets all the policy definitions of a subscription.
320
+ #
321
+ # @param filter [String] The filter to apply on the operation.
322
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
323
+ # will be added to the HTTP request.
324
+ #
325
+ # @return [Array<PolicyDefinition>] operation results.
326
+ #
327
+ def list(filter = nil, custom_headers = nil)
328
+ first_page = list_as_lazy(filter, custom_headers)
329
+ first_page.get_all_items
330
+ end
331
+
332
+ #
333
+ # Gets all the policy definitions of a subscription.
334
+ #
335
+ # @param filter [String] The filter to apply on the operation.
336
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
337
+ # will be added to the HTTP request.
338
+ #
339
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
340
+ #
341
+ def list_with_http_info(filter = nil, custom_headers = nil)
342
+ list_async(filter, custom_headers).value!
343
+ end
344
+
345
+ #
346
+ # Gets all the policy definitions of a subscription.
347
+ #
348
+ # @param filter [String] The filter to apply on the operation.
349
+ # @param [Hash{String => String}] A hash of custom headers that will be added
350
+ # to the HTTP request.
351
+ #
352
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
353
+ #
354
+ def list_async(filter = nil, custom_headers = nil)
355
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
356
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
357
+
358
+
359
+ request_headers = {}
360
+
361
+ # Set Headers
362
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
363
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
364
+ path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policydefinitions'
365
+ options = {
366
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
367
+ path_params: {'subscriptionId' => @client.subscription_id},
368
+ query_params: {'$filter' => filter,'api-version' => @client.api_version},
369
+ headers: request_headers.merge(custom_headers || {})
370
+ }
371
+
372
+ request_url = @base_url || @client.base_url
373
+
374
+ request = MsRest::HttpOperationRequest.new(request_url, path_template, :get, options)
375
+ promise = request.run_promise do |req|
376
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
377
+ end
378
+
379
+ promise = promise.then do |http_response|
380
+ status_code = http_response.status
381
+ response_content = http_response.body
382
+ unless status_code == 200
383
+ error_model = JSON.load(response_content)
384
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
385
+ end
386
+
387
+ # Create Result
388
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
389
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
390
+ # Deserialize Response
391
+ if status_code == 200
392
+ begin
393
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
394
+ result_mapper = PolicyDefinitionListResult.mapper()
395
+ result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
396
+ rescue Exception => e
397
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
398
+ end
399
+ end
400
+
401
+ result
402
+ end
403
+
404
+ promise.execute
405
+ end
406
+
407
+ #
408
+ # Gets all the policy definitions of a subscription.
409
+ #
410
+ # @param next_page_link [String] The NextLink from the previous successful
411
+ # call to List operation.
412
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
413
+ # will be added to the HTTP request.
414
+ #
415
+ # @return [PolicyDefinitionListResult] operation results.
416
+ #
417
+ def list_next(next_page_link, custom_headers = nil)
418
+ response = list_next_async(next_page_link, custom_headers).value!
419
+ response.body unless response.nil?
420
+ end
421
+
422
+ #
423
+ # Gets all the policy definitions of a subscription.
424
+ #
425
+ # @param next_page_link [String] The NextLink from the previous successful
426
+ # call to List operation.
427
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
428
+ # will be added to the HTTP request.
429
+ #
430
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
431
+ #
432
+ def list_next_with_http_info(next_page_link, custom_headers = nil)
433
+ list_next_async(next_page_link, custom_headers).value!
434
+ end
435
+
436
+ #
437
+ # Gets all the policy definitions of a subscription.
438
+ #
439
+ # @param next_page_link [String] The NextLink from the previous successful
440
+ # call to List operation.
441
+ # @param [Hash{String => String}] A hash of custom headers that will be added
442
+ # to the HTTP request.
443
+ #
444
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
445
+ #
446
+ def list_next_async(next_page_link, custom_headers = nil)
447
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
448
+
449
+
450
+ request_headers = {}
451
+
452
+ # Set Headers
453
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
454
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
455
+ path_template = '{nextLink}'
456
+ options = {
457
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
458
+ skip_encoding_path_params: {'nextLink' => next_page_link},
459
+ headers: request_headers.merge(custom_headers || {})
460
+ }
461
+
462
+ request_url = @base_url || @client.base_url
463
+
464
+ request = MsRest::HttpOperationRequest.new(request_url, path_template, :get, options)
465
+ promise = request.run_promise do |req|
466
+ @client.credentials.sign_request(req) unless @client.credentials.nil?
467
+ end
468
+
469
+ promise = promise.then do |http_response|
470
+ status_code = http_response.status
471
+ response_content = http_response.body
472
+ unless status_code == 200
473
+ error_model = JSON.load(response_content)
474
+ fail MsRestAzure::AzureOperationError.new(request, http_response, error_model)
475
+ end
476
+
477
+ # Create Result
478
+ result = MsRestAzure::AzureOperationResponse.new(request, http_response)
479
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
480
+ # Deserialize Response
481
+ if status_code == 200
482
+ begin
483
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
484
+ result_mapper = PolicyDefinitionListResult.mapper()
485
+ result.body = @client.deserialize(result_mapper, parsed_response, 'result.body')
486
+ rescue Exception => e
487
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
488
+ end
489
+ end
490
+
491
+ result
492
+ end
493
+
494
+ promise.execute
495
+ end
496
+
497
+ end
498
+ end