azure_mgmt_policy 0.17.7 → 0.17.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/2015-10-01-preview/generated/azure_mgmt_policy.rb +34 -34
  3. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/models/policy_assignment.rb +101 -101
  4. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  5. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/models/policy_definition.rb +106 -106
  6. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  7. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  8. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/module_definition.rb +9 -9
  9. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb +1356 -1356
  10. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_client.rb +1 -1
  11. data/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_definitions.rb +505 -505
  12. data/lib/2016-04-01/generated/azure_mgmt_policy.rb +34 -34
  13. data/lib/2016-04-01/generated/azure_mgmt_policy/models/policy_assignment.rb +101 -101
  14. data/lib/2016-04-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  15. data/lib/2016-04-01/generated/azure_mgmt_policy/models/policy_definition.rb +106 -106
  16. data/lib/2016-04-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  17. data/lib/2016-04-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  18. data/lib/2016-04-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  19. data/lib/2016-04-01/generated/azure_mgmt_policy/policy_assignments.rb +1356 -1356
  20. data/lib/2016-04-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  21. data/lib/2016-04-01/generated/azure_mgmt_policy/policy_definitions.rb +505 -505
  22. data/lib/2016-12-01/generated/azure_mgmt_policy.rb +35 -35
  23. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_assignment.rb +125 -125
  24. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  25. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_definition.rb +140 -140
  26. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  27. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_mode.rb +17 -17
  28. data/lib/2016-12-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  29. data/lib/2016-12-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  30. data/lib/2016-12-01/generated/azure_mgmt_policy/policy_assignments.rb +1356 -1356
  31. data/lib/2016-12-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  32. data/lib/2016-12-01/generated/azure_mgmt_policy/policy_definitions.rb +1275 -1275
  33. data/lib/2017-06-01-preview/generated/azure_mgmt_policy.rb +37 -37
  34. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/error_response.rb +69 -69
  35. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_assignment.rb +169 -169
  36. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  37. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_definition_reference.rb +58 -58
  38. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_set_definition.rb +151 -151
  39. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  40. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  41. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  42. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/module_definition.rb +9 -9
  43. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/policy_assignments.rb +1356 -1356
  44. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/policy_client.rb +1 -1
  45. data/lib/2017-06-01-preview/generated/azure_mgmt_policy/policy_set_definitions.rb +1295 -1295
  46. data/lib/2018-03-01/generated/azure_mgmt_policy.rb +41 -41
  47. data/lib/2018-03-01/generated/azure_mgmt_policy/models/error_response.rb +69 -69
  48. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_assignment.rb +171 -171
  49. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  50. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_definition.rb +153 -153
  51. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  52. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_definition_reference.rb +58 -58
  53. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_mode.rb +17 -17
  54. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_set_definition.rb +151 -151
  55. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  56. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  57. data/lib/2018-03-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  58. data/lib/2018-03-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  59. data/lib/2018-03-01/generated/azure_mgmt_policy/policy_assignments.rb +1902 -1902
  60. data/lib/2018-03-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  61. data/lib/2018-03-01/generated/azure_mgmt_policy/policy_definitions.rb +1391 -1391
  62. data/lib/2018-03-01/generated/azure_mgmt_policy/policy_set_definitions.rb +1414 -1414
  63. data/lib/2018-05-01/generated/azure_mgmt_policy.rb +43 -43
  64. data/lib/2018-05-01/generated/azure_mgmt_policy/models/error_response.rb +69 -69
  65. data/lib/2018-05-01/generated/azure_mgmt_policy/models/identity.rb +72 -72
  66. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_assignment.rb +196 -196
  67. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  68. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_definition.rb +153 -153
  69. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  70. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_definition_reference.rb +58 -58
  71. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_mode.rb +17 -17
  72. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_set_definition.rb +151 -151
  73. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  74. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  75. data/lib/2018-05-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  76. data/lib/2018-05-01/generated/azure_mgmt_policy/models/resource_identity_type.rb +16 -16
  77. data/lib/2018-05-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  78. data/lib/2018-05-01/generated/azure_mgmt_policy/policy_assignments.rb +1902 -1902
  79. data/lib/2018-05-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  80. data/lib/2018-05-01/generated/azure_mgmt_policy/policy_definitions.rb +1391 -1391
  81. data/lib/2018-05-01/generated/azure_mgmt_policy/policy_set_definitions.rb +1414 -1414
  82. data/lib/2019-01-01/generated/azure_mgmt_policy.rb +42 -42
  83. data/lib/2019-01-01/generated/azure_mgmt_policy/models/error_response.rb +69 -69
  84. data/lib/2019-01-01/generated/azure_mgmt_policy/models/identity.rb +72 -72
  85. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_assignment.rb +196 -196
  86. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  87. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_definition.rb +152 -152
  88. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  89. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_definition_reference.rb +58 -58
  90. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_set_definition.rb +151 -151
  91. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  92. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  93. data/lib/2019-01-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  94. data/lib/2019-01-01/generated/azure_mgmt_policy/models/resource_identity_type.rb +16 -16
  95. data/lib/2019-01-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  96. data/lib/2019-01-01/generated/azure_mgmt_policy/policy_assignments.rb +1902 -1902
  97. data/lib/2019-01-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  98. data/lib/2019-01-01/generated/azure_mgmt_policy/policy_definitions.rb +1391 -1391
  99. data/lib/2019-01-01/generated/azure_mgmt_policy/policy_set_definitions.rb +1414 -1414
  100. data/lib/2019-06-01/generated/azure_mgmt_policy.rb +43 -43
  101. data/lib/2019-06-01/generated/azure_mgmt_policy/models/enforcement_mode.rb +16 -16
  102. data/lib/2019-06-01/generated/azure_mgmt_policy/models/error_response.rb +69 -69
  103. data/lib/2019-06-01/generated/azure_mgmt_policy/models/identity.rb +72 -72
  104. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_assignment.rb +209 -209
  105. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  106. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_definition.rb +152 -152
  107. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  108. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_definition_reference.rb +58 -58
  109. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_set_definition.rb +151 -151
  110. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  111. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  112. data/lib/2019-06-01/generated/azure_mgmt_policy/models/policy_type.rb +17 -17
  113. data/lib/2019-06-01/generated/azure_mgmt_policy/models/resource_identity_type.rb +16 -16
  114. data/lib/2019-06-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  115. data/lib/2019-06-01/generated/azure_mgmt_policy/policy_assignments.rb +1902 -1902
  116. data/lib/2019-06-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  117. data/lib/2019-06-01/generated/azure_mgmt_policy/policy_definitions.rb +1391 -1391
  118. data/lib/2019-06-01/generated/azure_mgmt_policy/policy_set_definitions.rb +1414 -1414
  119. data/lib/2019-09-01/generated/azure_mgmt_policy.rb +49 -49
  120. data/lib/2019-09-01/generated/azure_mgmt_policy/models/enforcement_mode.rb +16 -16
  121. data/lib/2019-09-01/generated/azure_mgmt_policy/models/error_additional_info.rb +59 -59
  122. data/lib/2019-09-01/generated/azure_mgmt_policy/models/error_response.rb +113 -113
  123. data/lib/2019-09-01/generated/azure_mgmt_policy/models/identity.rb +3 -2
  124. data/lib/2019-09-01/generated/azure_mgmt_policy/models/parameter_definitions_value.rb +1 -2
  125. data/lib/2019-09-01/generated/azure_mgmt_policy/models/parameter_definitions_value_metadata.rb +76 -76
  126. data/lib/2019-09-01/generated/azure_mgmt_policy/models/parameter_type.rb +21 -21
  127. data/lib/2019-09-01/generated/azure_mgmt_policy/models/parameter_values_value.rb +1 -2
  128. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_assignment.rb +220 -220
  129. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_assignment_list_result.rb +98 -98
  130. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_definition.rb +164 -164
  131. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_definition_group.rb +91 -91
  132. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_definition_list_result.rb +98 -98
  133. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_definition_reference.rb +100 -100
  134. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_set_definition.rb +182 -182
  135. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_set_definition_list_result.rb +99 -99
  136. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_sku.rb +59 -59
  137. data/lib/2019-09-01/generated/azure_mgmt_policy/models/policy_type.rb +18 -18
  138. data/lib/2019-09-01/generated/azure_mgmt_policy/models/resource_identity_type.rb +16 -16
  139. data/lib/2019-09-01/generated/azure_mgmt_policy/module_definition.rb +9 -9
  140. data/lib/2019-09-01/generated/azure_mgmt_policy/policy_assignments.rb +277 -0
  141. data/lib/2019-09-01/generated/azure_mgmt_policy/policy_client.rb +1 -1
  142. data/lib/2019-09-01/generated/azure_mgmt_policy/policy_definitions.rb +1391 -1391
  143. data/lib/2019-09-01/generated/azure_mgmt_policy/policy_set_definitions.rb +1414 -1414
  144. data/lib/azure_mgmt_policy.rb +17 -17
  145. data/lib/version.rb +1 -1
  146. metadata +3 -3
@@ -1,1356 +1,1356 @@
1
- # encoding: utf-8
2
- # Code generated by Microsoft (R) AutoRest Code Generator.
3
- # Changes may cause incorrect behavior and will be lost if the code is
4
- # regenerated.
5
-
6
- module Azure::Policy::Mgmt::V2016_04_01
7
- #
8
- # To manage and control access to your resources, you can define customized
9
- # policies and assign them at a scope.
10
- #
11
- class PolicyAssignments
12
- include MsRestAzure
13
-
14
- #
15
- # Creates and initializes a new instance of the PolicyAssignments class.
16
- # @param client service class for accessing basic functionality.
17
- #
18
- def initialize(client)
19
- @client = client
20
- end
21
-
22
- # @return [PolicyClient] reference to the PolicyClient
23
- attr_reader :client
24
-
25
- #
26
- # Deletes a policy assignment.
27
- #
28
- # @param scope [String] The scope of the policy assignment.
29
- # @param policy_assignment_name [String] The name of the policy assignment to
30
- # delete.
31
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
32
- # will be added to the HTTP request.
33
- #
34
- # @return [PolicyAssignment] operation results.
35
- #
36
- def delete(scope, policy_assignment_name, custom_headers:nil)
37
- response = delete_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
38
- response.body unless response.nil?
39
- end
40
-
41
- #
42
- # Deletes a policy assignment.
43
- #
44
- # @param scope [String] The scope of the policy assignment.
45
- # @param policy_assignment_name [String] The name of the policy assignment to
46
- # delete.
47
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
48
- # will be added to the HTTP request.
49
- #
50
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
51
- #
52
- def delete_with_http_info(scope, policy_assignment_name, custom_headers:nil)
53
- delete_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
54
- end
55
-
56
- #
57
- # Deletes a policy assignment.
58
- #
59
- # @param scope [String] The scope of the policy assignment.
60
- # @param policy_assignment_name [String] The name of the policy assignment to
61
- # delete.
62
- # @param [Hash{String => String}] A hash of custom headers that will be added
63
- # to the HTTP request.
64
- #
65
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
66
- #
67
- def delete_async(scope, policy_assignment_name, custom_headers:nil)
68
- fail ArgumentError, 'scope is nil' if scope.nil?
69
- fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
70
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
71
-
72
-
73
- request_headers = {}
74
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
75
-
76
- # Set Headers
77
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
78
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
79
- path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
80
-
81
- request_url = @base_url || @client.base_url
82
-
83
- options = {
84
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
85
- path_params: {'policyAssignmentName' => policy_assignment_name},
86
- skip_encoding_path_params: {'scope' => scope},
87
- query_params: {'api-version' => @client.api_version},
88
- headers: request_headers.merge(custom_headers || {}),
89
- base_url: request_url
90
- }
91
- promise = @client.make_request_async(:delete, path_template, options)
92
-
93
- promise = promise.then do |result|
94
- http_response = result.response
95
- status_code = http_response.status
96
- response_content = http_response.body
97
- unless status_code == 200
98
- error_model = JSON.load(response_content)
99
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
100
- end
101
-
102
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
103
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
104
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
105
- # Deserialize Response
106
- if status_code == 200
107
- begin
108
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
109
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
110
- result.body = @client.deserialize(result_mapper, parsed_response)
111
- rescue Exception => e
112
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
113
- end
114
- end
115
-
116
- result
117
- end
118
-
119
- promise.execute
120
- end
121
-
122
- #
123
- # Creates a policy assignment.
124
- #
125
- # Policy assignments are inherited by child resources. For example, when you
126
- # apply a policy to a resource group that policy is assigned to all resources
127
- # in the group.
128
- #
129
- # @param scope [String] The scope of the policy assignment.
130
- # @param policy_assignment_name [String] The name of the policy assignment.
131
- # @param parameters [PolicyAssignment] Parameters for the policy assignment.
132
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
133
- # will be added to the HTTP request.
134
- #
135
- # @return [PolicyAssignment] operation results.
136
- #
137
- def create(scope, policy_assignment_name, parameters, custom_headers:nil)
138
- response = create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
139
- response.body unless response.nil?
140
- end
141
-
142
- #
143
- # Creates a policy assignment.
144
- #
145
- # Policy assignments are inherited by child resources. For example, when you
146
- # apply a policy to a resource group that policy is assigned to all resources
147
- # in the group.
148
- #
149
- # @param scope [String] The scope of the policy assignment.
150
- # @param policy_assignment_name [String] The name of the policy assignment.
151
- # @param parameters [PolicyAssignment] Parameters for the policy assignment.
152
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
153
- # will be added to the HTTP request.
154
- #
155
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
156
- #
157
- def create_with_http_info(scope, policy_assignment_name, parameters, custom_headers:nil)
158
- create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
159
- end
160
-
161
- #
162
- # Creates a policy assignment.
163
- #
164
- # Policy assignments are inherited by child resources. For example, when you
165
- # apply a policy to a resource group that policy is assigned to all resources
166
- # in the group.
167
- #
168
- # @param scope [String] The scope of the policy assignment.
169
- # @param policy_assignment_name [String] The name of the policy assignment.
170
- # @param parameters [PolicyAssignment] Parameters for the policy assignment.
171
- # @param [Hash{String => String}] A hash of custom headers that will be added
172
- # to the HTTP request.
173
- #
174
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
175
- #
176
- def create_async(scope, policy_assignment_name, parameters, custom_headers:nil)
177
- fail ArgumentError, 'scope is nil' if scope.nil?
178
- fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
179
- fail ArgumentError, 'parameters is nil' if parameters.nil?
180
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
181
-
182
-
183
- request_headers = {}
184
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
185
-
186
- # Set Headers
187
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
188
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
189
-
190
- # Serialize Request
191
- request_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
192
- request_content = @client.serialize(request_mapper, parameters)
193
- request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
194
-
195
- path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
196
-
197
- request_url = @base_url || @client.base_url
198
-
199
- options = {
200
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
201
- path_params: {'policyAssignmentName' => policy_assignment_name},
202
- skip_encoding_path_params: {'scope' => scope},
203
- query_params: {'api-version' => @client.api_version},
204
- body: request_content,
205
- headers: request_headers.merge(custom_headers || {}),
206
- base_url: request_url
207
- }
208
- promise = @client.make_request_async(:put, path_template, options)
209
-
210
- promise = promise.then do |result|
211
- http_response = result.response
212
- status_code = http_response.status
213
- response_content = http_response.body
214
- unless status_code == 201
215
- error_model = JSON.load(response_content)
216
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
217
- end
218
-
219
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
220
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
221
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
222
- # Deserialize Response
223
- if status_code == 201
224
- begin
225
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
226
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
227
- result.body = @client.deserialize(result_mapper, parsed_response)
228
- rescue Exception => e
229
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
230
- end
231
- end
232
-
233
- result
234
- end
235
-
236
- promise.execute
237
- end
238
-
239
- #
240
- # Gets a policy assignment.
241
- #
242
- # @param scope [String] The scope of the policy assignment.
243
- # @param policy_assignment_name [String] The name of the policy assignment to
244
- # get.
245
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
246
- # will be added to the HTTP request.
247
- #
248
- # @return [PolicyAssignment] operation results.
249
- #
250
- def get(scope, policy_assignment_name, custom_headers:nil)
251
- response = get_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
252
- response.body unless response.nil?
253
- end
254
-
255
- #
256
- # Gets a policy assignment.
257
- #
258
- # @param scope [String] The scope of the policy assignment.
259
- # @param policy_assignment_name [String] The name of the policy assignment to
260
- # get.
261
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
262
- # will be added to the HTTP request.
263
- #
264
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
265
- #
266
- def get_with_http_info(scope, policy_assignment_name, custom_headers:nil)
267
- get_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
268
- end
269
-
270
- #
271
- # Gets a policy assignment.
272
- #
273
- # @param scope [String] The scope of the policy assignment.
274
- # @param policy_assignment_name [String] The name of the policy assignment to
275
- # get.
276
- # @param [Hash{String => String}] A hash of custom headers that will be added
277
- # to the HTTP request.
278
- #
279
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
280
- #
281
- def get_async(scope, policy_assignment_name, custom_headers:nil)
282
- fail ArgumentError, 'scope is nil' if scope.nil?
283
- fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
284
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
285
-
286
-
287
- request_headers = {}
288
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
289
-
290
- # Set Headers
291
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
292
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
293
- path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
294
-
295
- request_url = @base_url || @client.base_url
296
-
297
- options = {
298
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
299
- path_params: {'policyAssignmentName' => policy_assignment_name},
300
- skip_encoding_path_params: {'scope' => scope},
301
- query_params: {'api-version' => @client.api_version},
302
- headers: request_headers.merge(custom_headers || {}),
303
- base_url: request_url
304
- }
305
- promise = @client.make_request_async(:get, path_template, options)
306
-
307
- promise = promise.then do |result|
308
- http_response = result.response
309
- status_code = http_response.status
310
- response_content = http_response.body
311
- unless status_code == 200
312
- error_model = JSON.load(response_content)
313
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
314
- end
315
-
316
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
317
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
318
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
319
- # Deserialize Response
320
- if status_code == 200
321
- begin
322
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
323
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
324
- result.body = @client.deserialize(result_mapper, parsed_response)
325
- rescue Exception => e
326
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
327
- end
328
- end
329
-
330
- result
331
- end
332
-
333
- promise.execute
334
- end
335
-
336
- #
337
- # Gets policy assignments for the resource group.
338
- #
339
- # @param resource_group_name [String] The name of the resource group that
340
- # contains policy assignments.
341
- # @param filter [String] The filter to apply on the operation.
342
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
343
- # will be added to the HTTP request.
344
- #
345
- # @return [Array<PolicyAssignment>] operation results.
346
- #
347
- def list_for_resource_group(resource_group_name, filter:nil, custom_headers:nil)
348
- first_page = list_for_resource_group_as_lazy(resource_group_name, filter:filter, custom_headers:custom_headers)
349
- first_page.get_all_items
350
- end
351
-
352
- #
353
- # Gets policy assignments for the resource group.
354
- #
355
- # @param resource_group_name [String] The name of the resource group that
356
- # contains policy assignments.
357
- # @param filter [String] The filter to apply on the operation.
358
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
359
- # will be added to the HTTP request.
360
- #
361
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
362
- #
363
- def list_for_resource_group_with_http_info(resource_group_name, filter:nil, custom_headers:nil)
364
- list_for_resource_group_async(resource_group_name, filter:filter, custom_headers:custom_headers).value!
365
- end
366
-
367
- #
368
- # Gets policy assignments for the resource group.
369
- #
370
- # @param resource_group_name [String] The name of the resource group that
371
- # contains policy assignments.
372
- # @param filter [String] The filter to apply on the operation.
373
- # @param [Hash{String => String}] A hash of custom headers that will be added
374
- # to the HTTP request.
375
- #
376
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
377
- #
378
- def list_for_resource_group_async(resource_group_name, filter:nil, custom_headers:nil)
379
- fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
380
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MaxLength': '90'" if !resource_group_name.nil? && resource_group_name.length > 90
381
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MinLength': '1'" if !resource_group_name.nil? && resource_group_name.length < 1
382
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'Pattern': '^[-\w\._\(\)]+$'" if !resource_group_name.nil? && resource_group_name.match(Regexp.new('^^[-\w\._\(\)]+$$')).nil?
383
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
384
- fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
385
-
386
-
387
- request_headers = {}
388
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
389
-
390
- # Set Headers
391
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
392
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
393
- path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments'
394
-
395
- request_url = @base_url || @client.base_url
396
-
397
- options = {
398
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
399
- path_params: {'resourceGroupName' => resource_group_name,'subscriptionId' => @client.subscription_id},
400
- query_params: {'api-version' => @client.api_version},
401
- skip_encoding_query_params: {'$filter' => filter},
402
- headers: request_headers.merge(custom_headers || {}),
403
- base_url: request_url
404
- }
405
- promise = @client.make_request_async(:get, path_template, options)
406
-
407
- promise = promise.then do |result|
408
- http_response = result.response
409
- status_code = http_response.status
410
- response_content = http_response.body
411
- unless status_code == 200
412
- error_model = JSON.load(response_content)
413
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
414
- end
415
-
416
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
417
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
418
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
419
- # Deserialize Response
420
- if status_code == 200
421
- begin
422
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
423
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
424
- result.body = @client.deserialize(result_mapper, parsed_response)
425
- rescue Exception => e
426
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
427
- end
428
- end
429
-
430
- result
431
- end
432
-
433
- promise.execute
434
- end
435
-
436
- #
437
- # Gets policy assignments for a resource.
438
- #
439
- # @param resource_group_name [String] The name of the resource group containing
440
- # the resource. The name is case insensitive.
441
- # @param resource_provider_namespace [String] The namespace of the resource
442
- # provider.
443
- # @param parent_resource_path [String] The parent resource path.
444
- # @param resource_type [String] The resource type.
445
- # @param resource_name [String] The name of the resource with policy
446
- # assignments.
447
- # @param filter [String] The filter to apply on the operation.
448
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
449
- # will be added to the HTTP request.
450
- #
451
- # @return [Array<PolicyAssignment>] operation results.
452
- #
453
- def list_for_resource(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
454
- first_page = list_for_resource_as_lazy(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers)
455
- first_page.get_all_items
456
- end
457
-
458
- #
459
- # Gets policy assignments for a resource.
460
- #
461
- # @param resource_group_name [String] The name of the resource group containing
462
- # the resource. The name is case insensitive.
463
- # @param resource_provider_namespace [String] The namespace of the resource
464
- # provider.
465
- # @param parent_resource_path [String] The parent resource path.
466
- # @param resource_type [String] The resource type.
467
- # @param resource_name [String] The name of the resource with policy
468
- # assignments.
469
- # @param filter [String] The filter to apply on the operation.
470
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
471
- # will be added to the HTTP request.
472
- #
473
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
474
- #
475
- def list_for_resource_with_http_info(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
476
- list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers).value!
477
- end
478
-
479
- #
480
- # Gets policy assignments for a resource.
481
- #
482
- # @param resource_group_name [String] The name of the resource group containing
483
- # the resource. The name is case insensitive.
484
- # @param resource_provider_namespace [String] The namespace of the resource
485
- # provider.
486
- # @param parent_resource_path [String] The parent resource path.
487
- # @param resource_type [String] The resource type.
488
- # @param resource_name [String] The name of the resource with policy
489
- # assignments.
490
- # @param filter [String] The filter to apply on the operation.
491
- # @param [Hash{String => String}] A hash of custom headers that will be added
492
- # to the HTTP request.
493
- #
494
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
495
- #
496
- def list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
497
- fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
498
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MaxLength': '90'" if !resource_group_name.nil? && resource_group_name.length > 90
499
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MinLength': '1'" if !resource_group_name.nil? && resource_group_name.length < 1
500
- fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'Pattern': '^[-\w\._\(\)]+$'" if !resource_group_name.nil? && resource_group_name.match(Regexp.new('^^[-\w\._\(\)]+$$')).nil?
501
- fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
502
- fail ArgumentError, 'parent_resource_path is nil' if parent_resource_path.nil?
503
- fail ArgumentError, 'resource_type is nil' if resource_type.nil?
504
- fail ArgumentError, 'resource_name is nil' if resource_name.nil?
505
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
506
- fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
507
-
508
-
509
- request_headers = {}
510
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
511
-
512
- # Set Headers
513
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
514
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
515
- path_template = 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyassignments'
516
-
517
- request_url = @base_url || @client.base_url
518
-
519
- options = {
520
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
521
- path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
522
- skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
523
- query_params: {'$filter' => filter,'api-version' => @client.api_version},
524
- headers: request_headers.merge(custom_headers || {}),
525
- base_url: request_url
526
- }
527
- promise = @client.make_request_async(:get, path_template, options)
528
-
529
- promise = promise.then do |result|
530
- http_response = result.response
531
- status_code = http_response.status
532
- response_content = http_response.body
533
- unless status_code == 200
534
- error_model = JSON.load(response_content)
535
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
536
- end
537
-
538
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
539
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
540
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
541
- # Deserialize Response
542
- if status_code == 200
543
- begin
544
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
545
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
546
- result.body = @client.deserialize(result_mapper, parsed_response)
547
- rescue Exception => e
548
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
549
- end
550
- end
551
-
552
- result
553
- end
554
-
555
- promise.execute
556
- end
557
-
558
- #
559
- # Gets all the policy assignments for a subscription.
560
- #
561
- # @param filter [String] The filter to apply on the operation.
562
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
563
- # will be added to the HTTP request.
564
- #
565
- # @return [Array<PolicyAssignment>] operation results.
566
- #
567
- def list(filter:nil, custom_headers:nil)
568
- first_page = list_as_lazy(filter:filter, custom_headers:custom_headers)
569
- first_page.get_all_items
570
- end
571
-
572
- #
573
- # Gets all the policy assignments for a subscription.
574
- #
575
- # @param filter [String] The filter to apply on the operation.
576
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
577
- # will be added to the HTTP request.
578
- #
579
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
580
- #
581
- def list_with_http_info(filter:nil, custom_headers:nil)
582
- list_async(filter:filter, custom_headers:custom_headers).value!
583
- end
584
-
585
- #
586
- # Gets all the policy assignments for a subscription.
587
- #
588
- # @param filter [String] The filter to apply on the operation.
589
- # @param [Hash{String => String}] A hash of custom headers that will be added
590
- # to the HTTP request.
591
- #
592
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
593
- #
594
- def list_async(filter:nil, custom_headers:nil)
595
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
596
- fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
597
-
598
-
599
- request_headers = {}
600
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
601
-
602
- # Set Headers
603
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
604
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
605
- path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyassignments'
606
-
607
- request_url = @base_url || @client.base_url
608
-
609
- options = {
610
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
611
- path_params: {'subscriptionId' => @client.subscription_id},
612
- query_params: {'$filter' => filter,'api-version' => @client.api_version},
613
- headers: request_headers.merge(custom_headers || {}),
614
- base_url: request_url
615
- }
616
- promise = @client.make_request_async(:get, path_template, options)
617
-
618
- promise = promise.then do |result|
619
- http_response = result.response
620
- status_code = http_response.status
621
- response_content = http_response.body
622
- unless status_code == 200
623
- error_model = JSON.load(response_content)
624
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
625
- end
626
-
627
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
628
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
629
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
630
- # Deserialize Response
631
- if status_code == 200
632
- begin
633
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
634
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
635
- result.body = @client.deserialize(result_mapper, parsed_response)
636
- rescue Exception => e
637
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
638
- end
639
- end
640
-
641
- result
642
- end
643
-
644
- promise.execute
645
- end
646
-
647
- #
648
- # Deletes a policy assignment by ID.
649
- #
650
- # When providing a scope for the assignment, use
651
- # '/subscriptions/{subscription-id}/' for subscriptions,
652
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
653
- # resource groups, and
654
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
655
- # for resources.
656
- #
657
- # @param policy_assignment_id [String] The ID of the policy assignment to
658
- # delete. Use the format
659
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
660
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
661
- # will be added to the HTTP request.
662
- #
663
- # @return [PolicyAssignment] operation results.
664
- #
665
- def delete_by_id(policy_assignment_id, custom_headers:nil)
666
- response = delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
667
- response.body unless response.nil?
668
- end
669
-
670
- #
671
- # Deletes a policy assignment by ID.
672
- #
673
- # When providing a scope for the assignment, use
674
- # '/subscriptions/{subscription-id}/' for subscriptions,
675
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
676
- # resource groups, and
677
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
678
- # for resources.
679
- #
680
- # @param policy_assignment_id [String] The ID of the policy assignment to
681
- # delete. Use the format
682
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
683
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
684
- # will be added to the HTTP request.
685
- #
686
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
687
- #
688
- def delete_by_id_with_http_info(policy_assignment_id, custom_headers:nil)
689
- delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
690
- end
691
-
692
- #
693
- # Deletes a policy assignment by ID.
694
- #
695
- # When providing a scope for the assignment, use
696
- # '/subscriptions/{subscription-id}/' for subscriptions,
697
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
698
- # resource groups, and
699
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
700
- # for resources.
701
- #
702
- # @param policy_assignment_id [String] The ID of the policy assignment to
703
- # delete. Use the format
704
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
705
- # @param [Hash{String => String}] A hash of custom headers that will be added
706
- # to the HTTP request.
707
- #
708
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
709
- #
710
- def delete_by_id_async(policy_assignment_id, custom_headers:nil)
711
- fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
712
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
713
-
714
-
715
- request_headers = {}
716
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
717
-
718
- # Set Headers
719
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
720
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
721
- path_template = '{policyAssignmentId}'
722
-
723
- request_url = @base_url || @client.base_url
724
-
725
- options = {
726
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
727
- skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
728
- query_params: {'api-version' => @client.api_version},
729
- headers: request_headers.merge(custom_headers || {}),
730
- base_url: request_url
731
- }
732
- promise = @client.make_request_async(:delete, path_template, options)
733
-
734
- promise = promise.then do |result|
735
- http_response = result.response
736
- status_code = http_response.status
737
- response_content = http_response.body
738
- unless status_code == 200
739
- error_model = JSON.load(response_content)
740
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
741
- end
742
-
743
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
744
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
745
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
746
- # Deserialize Response
747
- if status_code == 200
748
- begin
749
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
750
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
751
- result.body = @client.deserialize(result_mapper, parsed_response)
752
- rescue Exception => e
753
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
754
- end
755
- end
756
-
757
- result
758
- end
759
-
760
- promise.execute
761
- end
762
-
763
- #
764
- # Creates a policy assignment by ID.
765
- #
766
- # Policy assignments are inherited by child resources. For example, when you
767
- # apply a policy to a resource group that policy is assigned to all resources
768
- # in the group. When providing a scope for the assignment, use
769
- # '/subscriptions/{subscription-id}/' for subscriptions,
770
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
771
- # resource groups, and
772
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
773
- # for resources.
774
- #
775
- # @param policy_assignment_id [String] The ID of the policy assignment to
776
- # create. Use the format
777
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
778
- # @param parameters [PolicyAssignment] Parameters for policy assignment.
779
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
780
- # will be added to the HTTP request.
781
- #
782
- # @return [PolicyAssignment] operation results.
783
- #
784
- def create_by_id(policy_assignment_id, parameters, custom_headers:nil)
785
- response = create_by_id_async(policy_assignment_id, parameters, custom_headers:custom_headers).value!
786
- response.body unless response.nil?
787
- end
788
-
789
- #
790
- # Creates a policy assignment by ID.
791
- #
792
- # Policy assignments are inherited by child resources. For example, when you
793
- # apply a policy to a resource group that policy is assigned to all resources
794
- # in the group. When providing a scope for the assignment, use
795
- # '/subscriptions/{subscription-id}/' for subscriptions,
796
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
797
- # resource groups, and
798
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
799
- # for resources.
800
- #
801
- # @param policy_assignment_id [String] The ID of the policy assignment to
802
- # create. Use the format
803
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
804
- # @param parameters [PolicyAssignment] Parameters for policy assignment.
805
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
806
- # will be added to the HTTP request.
807
- #
808
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
809
- #
810
- def create_by_id_with_http_info(policy_assignment_id, parameters, custom_headers:nil)
811
- create_by_id_async(policy_assignment_id, parameters, custom_headers:custom_headers).value!
812
- end
813
-
814
- #
815
- # Creates a policy assignment by ID.
816
- #
817
- # Policy assignments are inherited by child resources. For example, when you
818
- # apply a policy to a resource group that policy is assigned to all resources
819
- # in the group. When providing a scope for the assignment, use
820
- # '/subscriptions/{subscription-id}/' for subscriptions,
821
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
822
- # resource groups, and
823
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
824
- # for resources.
825
- #
826
- # @param policy_assignment_id [String] The ID of the policy assignment to
827
- # create. Use the format
828
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
829
- # @param parameters [PolicyAssignment] Parameters for policy assignment.
830
- # @param [Hash{String => String}] A hash of custom headers that will be added
831
- # to the HTTP request.
832
- #
833
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
834
- #
835
- def create_by_id_async(policy_assignment_id, parameters, custom_headers:nil)
836
- fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
837
- fail ArgumentError, 'parameters is nil' if parameters.nil?
838
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
839
-
840
-
841
- request_headers = {}
842
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
843
-
844
- # Set Headers
845
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
846
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
847
-
848
- # Serialize Request
849
- request_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
850
- request_content = @client.serialize(request_mapper, parameters)
851
- request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
852
-
853
- path_template = '{policyAssignmentId}'
854
-
855
- request_url = @base_url || @client.base_url
856
-
857
- options = {
858
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
859
- skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
860
- query_params: {'api-version' => @client.api_version},
861
- body: request_content,
862
- headers: request_headers.merge(custom_headers || {}),
863
- base_url: request_url
864
- }
865
- promise = @client.make_request_async(:put, path_template, options)
866
-
867
- promise = promise.then do |result|
868
- http_response = result.response
869
- status_code = http_response.status
870
- response_content = http_response.body
871
- unless status_code == 201
872
- error_model = JSON.load(response_content)
873
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
874
- end
875
-
876
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
877
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
878
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
879
- # Deserialize Response
880
- if status_code == 201
881
- begin
882
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
883
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
884
- result.body = @client.deserialize(result_mapper, parsed_response)
885
- rescue Exception => e
886
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
887
- end
888
- end
889
-
890
- result
891
- end
892
-
893
- promise.execute
894
- end
895
-
896
- #
897
- # Gets a policy assignment by ID.
898
- #
899
- # When providing a scope for the assignment, use
900
- # '/subscriptions/{subscription-id}/' for subscriptions,
901
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
902
- # resource groups, and
903
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
904
- # for resources.
905
- #
906
- # @param policy_assignment_id [String] The ID of the policy assignment to get.
907
- # Use the format
908
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
909
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
910
- # will be added to the HTTP request.
911
- #
912
- # @return [PolicyAssignment] operation results.
913
- #
914
- def get_by_id(policy_assignment_id, custom_headers:nil)
915
- response = get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
916
- response.body unless response.nil?
917
- end
918
-
919
- #
920
- # Gets a policy assignment by ID.
921
- #
922
- # When providing a scope for the assignment, use
923
- # '/subscriptions/{subscription-id}/' for subscriptions,
924
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
925
- # resource groups, and
926
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
927
- # for resources.
928
- #
929
- # @param policy_assignment_id [String] The ID of the policy assignment to get.
930
- # Use the format
931
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
932
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
933
- # will be added to the HTTP request.
934
- #
935
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
936
- #
937
- def get_by_id_with_http_info(policy_assignment_id, custom_headers:nil)
938
- get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
939
- end
940
-
941
- #
942
- # Gets a policy assignment by ID.
943
- #
944
- # When providing a scope for the assignment, use
945
- # '/subscriptions/{subscription-id}/' for subscriptions,
946
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
947
- # resource groups, and
948
- # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
949
- # for resources.
950
- #
951
- # @param policy_assignment_id [String] The ID of the policy assignment to get.
952
- # Use the format
953
- # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
954
- # @param [Hash{String => String}] A hash of custom headers that will be added
955
- # to the HTTP request.
956
- #
957
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
958
- #
959
- def get_by_id_async(policy_assignment_id, custom_headers:nil)
960
- fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
961
- fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
962
-
963
-
964
- request_headers = {}
965
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
966
-
967
- # Set Headers
968
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
969
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
970
- path_template = '{policyAssignmentId}'
971
-
972
- request_url = @base_url || @client.base_url
973
-
974
- options = {
975
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
976
- skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
977
- query_params: {'api-version' => @client.api_version},
978
- headers: request_headers.merge(custom_headers || {}),
979
- base_url: request_url
980
- }
981
- promise = @client.make_request_async(:get, path_template, options)
982
-
983
- promise = promise.then do |result|
984
- http_response = result.response
985
- status_code = http_response.status
986
- response_content = http_response.body
987
- unless status_code == 200
988
- error_model = JSON.load(response_content)
989
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
990
- end
991
-
992
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
993
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
994
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
995
- # Deserialize Response
996
- if status_code == 200
997
- begin
998
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
999
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
1000
- result.body = @client.deserialize(result_mapper, parsed_response)
1001
- rescue Exception => e
1002
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1003
- end
1004
- end
1005
-
1006
- result
1007
- end
1008
-
1009
- promise.execute
1010
- end
1011
-
1012
- #
1013
- # Gets policy assignments for the resource group.
1014
- #
1015
- # @param next_page_link [String] The NextLink from the previous successful call
1016
- # to List operation.
1017
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1018
- # will be added to the HTTP request.
1019
- #
1020
- # @return [PolicyAssignmentListResult] operation results.
1021
- #
1022
- def list_for_resource_group_next(next_page_link, custom_headers:nil)
1023
- response = list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
1024
- response.body unless response.nil?
1025
- end
1026
-
1027
- #
1028
- # Gets policy assignments for the resource group.
1029
- #
1030
- # @param next_page_link [String] The NextLink from the previous successful call
1031
- # to List operation.
1032
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1033
- # will be added to the HTTP request.
1034
- #
1035
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1036
- #
1037
- def list_for_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
1038
- list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
1039
- end
1040
-
1041
- #
1042
- # Gets policy assignments for the resource group.
1043
- #
1044
- # @param next_page_link [String] The NextLink from the previous successful call
1045
- # to List operation.
1046
- # @param [Hash{String => String}] A hash of custom headers that will be added
1047
- # to the HTTP request.
1048
- #
1049
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1050
- #
1051
- def list_for_resource_group_next_async(next_page_link, custom_headers:nil)
1052
- fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1053
-
1054
-
1055
- request_headers = {}
1056
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
1057
-
1058
- # Set Headers
1059
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1060
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1061
- path_template = '{nextLink}'
1062
-
1063
- request_url = @base_url || @client.base_url
1064
-
1065
- options = {
1066
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1067
- skip_encoding_path_params: {'nextLink' => next_page_link},
1068
- headers: request_headers.merge(custom_headers || {}),
1069
- base_url: request_url
1070
- }
1071
- promise = @client.make_request_async(:get, path_template, options)
1072
-
1073
- promise = promise.then do |result|
1074
- http_response = result.response
1075
- status_code = http_response.status
1076
- response_content = http_response.body
1077
- unless status_code == 200
1078
- error_model = JSON.load(response_content)
1079
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1080
- end
1081
-
1082
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1083
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1084
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1085
- # Deserialize Response
1086
- if status_code == 200
1087
- begin
1088
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1089
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1090
- result.body = @client.deserialize(result_mapper, parsed_response)
1091
- rescue Exception => e
1092
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1093
- end
1094
- end
1095
-
1096
- result
1097
- end
1098
-
1099
- promise.execute
1100
- end
1101
-
1102
- #
1103
- # Gets policy assignments for a resource.
1104
- #
1105
- # @param next_page_link [String] The NextLink from the previous successful call
1106
- # to List operation.
1107
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1108
- # will be added to the HTTP request.
1109
- #
1110
- # @return [PolicyAssignmentListResult] operation results.
1111
- #
1112
- def list_for_resource_next(next_page_link, custom_headers:nil)
1113
- response = list_for_resource_next_async(next_page_link, custom_headers:custom_headers).value!
1114
- response.body unless response.nil?
1115
- end
1116
-
1117
- #
1118
- # Gets policy assignments for a resource.
1119
- #
1120
- # @param next_page_link [String] The NextLink from the previous successful call
1121
- # to List operation.
1122
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1123
- # will be added to the HTTP request.
1124
- #
1125
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1126
- #
1127
- def list_for_resource_next_with_http_info(next_page_link, custom_headers:nil)
1128
- list_for_resource_next_async(next_page_link, custom_headers:custom_headers).value!
1129
- end
1130
-
1131
- #
1132
- # Gets policy assignments for a resource.
1133
- #
1134
- # @param next_page_link [String] The NextLink from the previous successful call
1135
- # to List operation.
1136
- # @param [Hash{String => String}] A hash of custom headers that will be added
1137
- # to the HTTP request.
1138
- #
1139
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1140
- #
1141
- def list_for_resource_next_async(next_page_link, custom_headers:nil)
1142
- fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1143
-
1144
-
1145
- request_headers = {}
1146
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
1147
-
1148
- # Set Headers
1149
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1150
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1151
- path_template = '{nextLink}'
1152
-
1153
- request_url = @base_url || @client.base_url
1154
-
1155
- options = {
1156
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1157
- skip_encoding_path_params: {'nextLink' => next_page_link},
1158
- headers: request_headers.merge(custom_headers || {}),
1159
- base_url: request_url
1160
- }
1161
- promise = @client.make_request_async(:get, path_template, options)
1162
-
1163
- promise = promise.then do |result|
1164
- http_response = result.response
1165
- status_code = http_response.status
1166
- response_content = http_response.body
1167
- unless status_code == 200
1168
- error_model = JSON.load(response_content)
1169
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1170
- end
1171
-
1172
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1173
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1174
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1175
- # Deserialize Response
1176
- if status_code == 200
1177
- begin
1178
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1179
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1180
- result.body = @client.deserialize(result_mapper, parsed_response)
1181
- rescue Exception => e
1182
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1183
- end
1184
- end
1185
-
1186
- result
1187
- end
1188
-
1189
- promise.execute
1190
- end
1191
-
1192
- #
1193
- # Gets all the policy assignments for a subscription.
1194
- #
1195
- # @param next_page_link [String] The NextLink from the previous successful call
1196
- # to List operation.
1197
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1198
- # will be added to the HTTP request.
1199
- #
1200
- # @return [PolicyAssignmentListResult] operation results.
1201
- #
1202
- def list_next(next_page_link, custom_headers:nil)
1203
- response = list_next_async(next_page_link, custom_headers:custom_headers).value!
1204
- response.body unless response.nil?
1205
- end
1206
-
1207
- #
1208
- # Gets all the policy assignments for a subscription.
1209
- #
1210
- # @param next_page_link [String] The NextLink from the previous successful call
1211
- # to List operation.
1212
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1213
- # will be added to the HTTP request.
1214
- #
1215
- # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1216
- #
1217
- def list_next_with_http_info(next_page_link, custom_headers:nil)
1218
- list_next_async(next_page_link, custom_headers:custom_headers).value!
1219
- end
1220
-
1221
- #
1222
- # Gets all the policy assignments for a subscription.
1223
- #
1224
- # @param next_page_link [String] The NextLink from the previous successful call
1225
- # to List operation.
1226
- # @param [Hash{String => String}] A hash of custom headers that will be added
1227
- # to the HTTP request.
1228
- #
1229
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1230
- #
1231
- def list_next_async(next_page_link, custom_headers:nil)
1232
- fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1233
-
1234
-
1235
- request_headers = {}
1236
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
1237
-
1238
- # Set Headers
1239
- request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1240
- request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1241
- path_template = '{nextLink}'
1242
-
1243
- request_url = @base_url || @client.base_url
1244
-
1245
- options = {
1246
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1247
- skip_encoding_path_params: {'nextLink' => next_page_link},
1248
- headers: request_headers.merge(custom_headers || {}),
1249
- base_url: request_url
1250
- }
1251
- promise = @client.make_request_async(:get, path_template, options)
1252
-
1253
- promise = promise.then do |result|
1254
- http_response = result.response
1255
- status_code = http_response.status
1256
- response_content = http_response.body
1257
- unless status_code == 200
1258
- error_model = JSON.load(response_content)
1259
- fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1260
- end
1261
-
1262
- result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1263
- result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1264
- result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1265
- # Deserialize Response
1266
- if status_code == 200
1267
- begin
1268
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1269
- result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1270
- result.body = @client.deserialize(result_mapper, parsed_response)
1271
- rescue Exception => e
1272
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1273
- end
1274
- end
1275
-
1276
- result
1277
- end
1278
-
1279
- promise.execute
1280
- end
1281
-
1282
- #
1283
- # Gets policy assignments for the resource group.
1284
- #
1285
- # @param resource_group_name [String] The name of the resource group that
1286
- # contains policy assignments.
1287
- # @param filter [String] The filter to apply on the operation.
1288
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1289
- # will be added to the HTTP request.
1290
- #
1291
- # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1292
- # the response.
1293
- #
1294
- def list_for_resource_group_as_lazy(resource_group_name, filter:nil, custom_headers:nil)
1295
- response = list_for_resource_group_async(resource_group_name, filter:filter, custom_headers:custom_headers).value!
1296
- unless response.nil?
1297
- page = response.body
1298
- page.next_method = Proc.new do |next_page_link|
1299
- list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers)
1300
- end
1301
- page
1302
- end
1303
- end
1304
-
1305
- #
1306
- # Gets policy assignments for a resource.
1307
- #
1308
- # @param resource_group_name [String] The name of the resource group containing
1309
- # the resource. The name is case insensitive.
1310
- # @param resource_provider_namespace [String] The namespace of the resource
1311
- # provider.
1312
- # @param parent_resource_path [String] The parent resource path.
1313
- # @param resource_type [String] The resource type.
1314
- # @param resource_name [String] The name of the resource with policy
1315
- # assignments.
1316
- # @param filter [String] The filter to apply on the operation.
1317
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1318
- # will be added to the HTTP request.
1319
- #
1320
- # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1321
- # the response.
1322
- #
1323
- def list_for_resource_as_lazy(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
1324
- response = list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers).value!
1325
- unless response.nil?
1326
- page = response.body
1327
- page.next_method = Proc.new do |next_page_link|
1328
- list_for_resource_next_async(next_page_link, custom_headers:custom_headers)
1329
- end
1330
- page
1331
- end
1332
- end
1333
-
1334
- #
1335
- # Gets all the policy assignments for a subscription.
1336
- #
1337
- # @param filter [String] The filter to apply on the operation.
1338
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
1339
- # will be added to the HTTP request.
1340
- #
1341
- # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1342
- # the response.
1343
- #
1344
- def list_as_lazy(filter:nil, custom_headers:nil)
1345
- response = list_async(filter:filter, custom_headers:custom_headers).value!
1346
- unless response.nil?
1347
- page = response.body
1348
- page.next_method = Proc.new do |next_page_link|
1349
- list_next_async(next_page_link, custom_headers:custom_headers)
1350
- end
1351
- page
1352
- end
1353
- end
1354
-
1355
- end
1356
- end
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator.
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::Policy::Mgmt::V2016_04_01
7
+ #
8
+ # To manage and control access to your resources, you can define customized
9
+ # policies and assign them at a scope.
10
+ #
11
+ class PolicyAssignments
12
+ include MsRestAzure
13
+
14
+ #
15
+ # Creates and initializes a new instance of the PolicyAssignments class.
16
+ # @param client service class for accessing basic functionality.
17
+ #
18
+ def initialize(client)
19
+ @client = client
20
+ end
21
+
22
+ # @return [PolicyClient] reference to the PolicyClient
23
+ attr_reader :client
24
+
25
+ #
26
+ # Deletes a policy assignment.
27
+ #
28
+ # @param scope [String] The scope of the policy assignment.
29
+ # @param policy_assignment_name [String] The name of the policy assignment to
30
+ # delete.
31
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
32
+ # will be added to the HTTP request.
33
+ #
34
+ # @return [PolicyAssignment] operation results.
35
+ #
36
+ def delete(scope, policy_assignment_name, custom_headers:nil)
37
+ response = delete_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
38
+ response.body unless response.nil?
39
+ end
40
+
41
+ #
42
+ # Deletes a policy assignment.
43
+ #
44
+ # @param scope [String] The scope of the policy assignment.
45
+ # @param policy_assignment_name [String] The name of the policy assignment to
46
+ # delete.
47
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
48
+ # will be added to the HTTP request.
49
+ #
50
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
51
+ #
52
+ def delete_with_http_info(scope, policy_assignment_name, custom_headers:nil)
53
+ delete_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
54
+ end
55
+
56
+ #
57
+ # Deletes a policy assignment.
58
+ #
59
+ # @param scope [String] The scope of the policy assignment.
60
+ # @param policy_assignment_name [String] The name of the policy assignment to
61
+ # delete.
62
+ # @param [Hash{String => String}] A hash of custom headers that will be added
63
+ # to the HTTP request.
64
+ #
65
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
66
+ #
67
+ def delete_async(scope, policy_assignment_name, custom_headers:nil)
68
+ fail ArgumentError, 'scope is nil' if scope.nil?
69
+ fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
70
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
71
+
72
+
73
+ request_headers = {}
74
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
75
+
76
+ # Set Headers
77
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
78
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
79
+ path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
80
+
81
+ request_url = @base_url || @client.base_url
82
+
83
+ options = {
84
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
85
+ path_params: {'policyAssignmentName' => policy_assignment_name},
86
+ skip_encoding_path_params: {'scope' => scope},
87
+ query_params: {'api-version' => @client.api_version},
88
+ headers: request_headers.merge(custom_headers || {}),
89
+ base_url: request_url
90
+ }
91
+ promise = @client.make_request_async(:delete, path_template, options)
92
+
93
+ promise = promise.then do |result|
94
+ http_response = result.response
95
+ status_code = http_response.status
96
+ response_content = http_response.body
97
+ unless status_code == 200
98
+ error_model = JSON.load(response_content)
99
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
100
+ end
101
+
102
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
103
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
104
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
105
+ # Deserialize Response
106
+ if status_code == 200
107
+ begin
108
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
109
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
110
+ result.body = @client.deserialize(result_mapper, parsed_response)
111
+ rescue Exception => e
112
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
113
+ end
114
+ end
115
+
116
+ result
117
+ end
118
+
119
+ promise.execute
120
+ end
121
+
122
+ #
123
+ # Creates a policy assignment.
124
+ #
125
+ # Policy assignments are inherited by child resources. For example, when you
126
+ # apply a policy to a resource group that policy is assigned to all resources
127
+ # in the group.
128
+ #
129
+ # @param scope [String] The scope of the policy assignment.
130
+ # @param policy_assignment_name [String] The name of the policy assignment.
131
+ # @param parameters [PolicyAssignment] Parameters for the policy assignment.
132
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
133
+ # will be added to the HTTP request.
134
+ #
135
+ # @return [PolicyAssignment] operation results.
136
+ #
137
+ def create(scope, policy_assignment_name, parameters, custom_headers:nil)
138
+ response = create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
139
+ response.body unless response.nil?
140
+ end
141
+
142
+ #
143
+ # Creates a policy assignment.
144
+ #
145
+ # Policy assignments are inherited by child resources. For example, when you
146
+ # apply a policy to a resource group that policy is assigned to all resources
147
+ # in the group.
148
+ #
149
+ # @param scope [String] The scope of the policy assignment.
150
+ # @param policy_assignment_name [String] The name of the policy assignment.
151
+ # @param parameters [PolicyAssignment] Parameters for the policy assignment.
152
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
153
+ # will be added to the HTTP request.
154
+ #
155
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
156
+ #
157
+ def create_with_http_info(scope, policy_assignment_name, parameters, custom_headers:nil)
158
+ create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
159
+ end
160
+
161
+ #
162
+ # Creates a policy assignment.
163
+ #
164
+ # Policy assignments are inherited by child resources. For example, when you
165
+ # apply a policy to a resource group that policy is assigned to all resources
166
+ # in the group.
167
+ #
168
+ # @param scope [String] The scope of the policy assignment.
169
+ # @param policy_assignment_name [String] The name of the policy assignment.
170
+ # @param parameters [PolicyAssignment] Parameters for the policy assignment.
171
+ # @param [Hash{String => String}] A hash of custom headers that will be added
172
+ # to the HTTP request.
173
+ #
174
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
175
+ #
176
+ def create_async(scope, policy_assignment_name, parameters, custom_headers:nil)
177
+ fail ArgumentError, 'scope is nil' if scope.nil?
178
+ fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
179
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
180
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
181
+
182
+
183
+ request_headers = {}
184
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
185
+
186
+ # Set Headers
187
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
188
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
189
+
190
+ # Serialize Request
191
+ request_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
192
+ request_content = @client.serialize(request_mapper, parameters)
193
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
194
+
195
+ path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
196
+
197
+ request_url = @base_url || @client.base_url
198
+
199
+ options = {
200
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
201
+ path_params: {'policyAssignmentName' => policy_assignment_name},
202
+ skip_encoding_path_params: {'scope' => scope},
203
+ query_params: {'api-version' => @client.api_version},
204
+ body: request_content,
205
+ headers: request_headers.merge(custom_headers || {}),
206
+ base_url: request_url
207
+ }
208
+ promise = @client.make_request_async(:put, path_template, options)
209
+
210
+ promise = promise.then do |result|
211
+ http_response = result.response
212
+ status_code = http_response.status
213
+ response_content = http_response.body
214
+ unless status_code == 201
215
+ error_model = JSON.load(response_content)
216
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
217
+ end
218
+
219
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
220
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
221
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
222
+ # Deserialize Response
223
+ if status_code == 201
224
+ begin
225
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
226
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
227
+ result.body = @client.deserialize(result_mapper, parsed_response)
228
+ rescue Exception => e
229
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
230
+ end
231
+ end
232
+
233
+ result
234
+ end
235
+
236
+ promise.execute
237
+ end
238
+
239
+ #
240
+ # Gets a policy assignment.
241
+ #
242
+ # @param scope [String] The scope of the policy assignment.
243
+ # @param policy_assignment_name [String] The name of the policy assignment to
244
+ # get.
245
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
246
+ # will be added to the HTTP request.
247
+ #
248
+ # @return [PolicyAssignment] operation results.
249
+ #
250
+ def get(scope, policy_assignment_name, custom_headers:nil)
251
+ response = get_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
252
+ response.body unless response.nil?
253
+ end
254
+
255
+ #
256
+ # Gets a policy assignment.
257
+ #
258
+ # @param scope [String] The scope of the policy assignment.
259
+ # @param policy_assignment_name [String] The name of the policy assignment to
260
+ # get.
261
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
262
+ # will be added to the HTTP request.
263
+ #
264
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
265
+ #
266
+ def get_with_http_info(scope, policy_assignment_name, custom_headers:nil)
267
+ get_async(scope, policy_assignment_name, custom_headers:custom_headers).value!
268
+ end
269
+
270
+ #
271
+ # Gets a policy assignment.
272
+ #
273
+ # @param scope [String] The scope of the policy assignment.
274
+ # @param policy_assignment_name [String] The name of the policy assignment to
275
+ # get.
276
+ # @param [Hash{String => String}] A hash of custom headers that will be added
277
+ # to the HTTP request.
278
+ #
279
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
280
+ #
281
+ def get_async(scope, policy_assignment_name, custom_headers:nil)
282
+ fail ArgumentError, 'scope is nil' if scope.nil?
283
+ fail ArgumentError, 'policy_assignment_name is nil' if policy_assignment_name.nil?
284
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
285
+
286
+
287
+ request_headers = {}
288
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
289
+
290
+ # Set Headers
291
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
292
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
293
+ path_template = '{scope}/providers/Microsoft.Authorization/policyassignments/{policyAssignmentName}'
294
+
295
+ request_url = @base_url || @client.base_url
296
+
297
+ options = {
298
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
299
+ path_params: {'policyAssignmentName' => policy_assignment_name},
300
+ skip_encoding_path_params: {'scope' => scope},
301
+ query_params: {'api-version' => @client.api_version},
302
+ headers: request_headers.merge(custom_headers || {}),
303
+ base_url: request_url
304
+ }
305
+ promise = @client.make_request_async(:get, path_template, options)
306
+
307
+ promise = promise.then do |result|
308
+ http_response = result.response
309
+ status_code = http_response.status
310
+ response_content = http_response.body
311
+ unless status_code == 200
312
+ error_model = JSON.load(response_content)
313
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
314
+ end
315
+
316
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
317
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
318
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
319
+ # Deserialize Response
320
+ if status_code == 200
321
+ begin
322
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
323
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
324
+ result.body = @client.deserialize(result_mapper, parsed_response)
325
+ rescue Exception => e
326
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
327
+ end
328
+ end
329
+
330
+ result
331
+ end
332
+
333
+ promise.execute
334
+ end
335
+
336
+ #
337
+ # Gets policy assignments for the resource group.
338
+ #
339
+ # @param resource_group_name [String] The name of the resource group that
340
+ # contains policy assignments.
341
+ # @param filter [String] The filter to apply on the operation.
342
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
343
+ # will be added to the HTTP request.
344
+ #
345
+ # @return [Array<PolicyAssignment>] operation results.
346
+ #
347
+ def list_for_resource_group(resource_group_name, filter:nil, custom_headers:nil)
348
+ first_page = list_for_resource_group_as_lazy(resource_group_name, filter:filter, custom_headers:custom_headers)
349
+ first_page.get_all_items
350
+ end
351
+
352
+ #
353
+ # Gets policy assignments for the resource group.
354
+ #
355
+ # @param resource_group_name [String] The name of the resource group that
356
+ # contains policy assignments.
357
+ # @param filter [String] The filter to apply on the operation.
358
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
359
+ # will be added to the HTTP request.
360
+ #
361
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
362
+ #
363
+ def list_for_resource_group_with_http_info(resource_group_name, filter:nil, custom_headers:nil)
364
+ list_for_resource_group_async(resource_group_name, filter:filter, custom_headers:custom_headers).value!
365
+ end
366
+
367
+ #
368
+ # Gets policy assignments for the resource group.
369
+ #
370
+ # @param resource_group_name [String] The name of the resource group that
371
+ # contains policy assignments.
372
+ # @param filter [String] The filter to apply on the operation.
373
+ # @param [Hash{String => String}] A hash of custom headers that will be added
374
+ # to the HTTP request.
375
+ #
376
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
377
+ #
378
+ def list_for_resource_group_async(resource_group_name, filter:nil, custom_headers:nil)
379
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
380
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MaxLength': '90'" if !resource_group_name.nil? && resource_group_name.length > 90
381
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MinLength': '1'" if !resource_group_name.nil? && resource_group_name.length < 1
382
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'Pattern': '^[-\w\._\(\)]+$'" if !resource_group_name.nil? && resource_group_name.match(Regexp.new('^^[-\w\._\(\)]+$$')).nil?
383
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
384
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
385
+
386
+
387
+ request_headers = {}
388
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
389
+
390
+ # Set Headers
391
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
392
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
393
+ path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments'
394
+
395
+ request_url = @base_url || @client.base_url
396
+
397
+ options = {
398
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
399
+ path_params: {'resourceGroupName' => resource_group_name,'subscriptionId' => @client.subscription_id},
400
+ query_params: {'api-version' => @client.api_version},
401
+ skip_encoding_query_params: {'$filter' => filter},
402
+ headers: request_headers.merge(custom_headers || {}),
403
+ base_url: request_url
404
+ }
405
+ promise = @client.make_request_async(:get, path_template, options)
406
+
407
+ promise = promise.then do |result|
408
+ http_response = result.response
409
+ status_code = http_response.status
410
+ response_content = http_response.body
411
+ unless status_code == 200
412
+ error_model = JSON.load(response_content)
413
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
414
+ end
415
+
416
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
417
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
418
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
419
+ # Deserialize Response
420
+ if status_code == 200
421
+ begin
422
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
423
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
424
+ result.body = @client.deserialize(result_mapper, parsed_response)
425
+ rescue Exception => e
426
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
427
+ end
428
+ end
429
+
430
+ result
431
+ end
432
+
433
+ promise.execute
434
+ end
435
+
436
+ #
437
+ # Gets policy assignments for a resource.
438
+ #
439
+ # @param resource_group_name [String] The name of the resource group containing
440
+ # the resource. The name is case insensitive.
441
+ # @param resource_provider_namespace [String] The namespace of the resource
442
+ # provider.
443
+ # @param parent_resource_path [String] The parent resource path.
444
+ # @param resource_type [String] The resource type.
445
+ # @param resource_name [String] The name of the resource with policy
446
+ # assignments.
447
+ # @param filter [String] The filter to apply on the operation.
448
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
449
+ # will be added to the HTTP request.
450
+ #
451
+ # @return [Array<PolicyAssignment>] operation results.
452
+ #
453
+ def list_for_resource(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
454
+ first_page = list_for_resource_as_lazy(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers)
455
+ first_page.get_all_items
456
+ end
457
+
458
+ #
459
+ # Gets policy assignments for a resource.
460
+ #
461
+ # @param resource_group_name [String] The name of the resource group containing
462
+ # the resource. The name is case insensitive.
463
+ # @param resource_provider_namespace [String] The namespace of the resource
464
+ # provider.
465
+ # @param parent_resource_path [String] The parent resource path.
466
+ # @param resource_type [String] The resource type.
467
+ # @param resource_name [String] The name of the resource with policy
468
+ # assignments.
469
+ # @param filter [String] The filter to apply on the operation.
470
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
471
+ # will be added to the HTTP request.
472
+ #
473
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
474
+ #
475
+ def list_for_resource_with_http_info(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
476
+ list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers).value!
477
+ end
478
+
479
+ #
480
+ # Gets policy assignments for a resource.
481
+ #
482
+ # @param resource_group_name [String] The name of the resource group containing
483
+ # the resource. The name is case insensitive.
484
+ # @param resource_provider_namespace [String] The namespace of the resource
485
+ # provider.
486
+ # @param parent_resource_path [String] The parent resource path.
487
+ # @param resource_type [String] The resource type.
488
+ # @param resource_name [String] The name of the resource with policy
489
+ # assignments.
490
+ # @param filter [String] The filter to apply on the operation.
491
+ # @param [Hash{String => String}] A hash of custom headers that will be added
492
+ # to the HTTP request.
493
+ #
494
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
495
+ #
496
+ def list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
497
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
498
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MaxLength': '90'" if !resource_group_name.nil? && resource_group_name.length > 90
499
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'MinLength': '1'" if !resource_group_name.nil? && resource_group_name.length < 1
500
+ fail ArgumentError, "'resource_group_name' should satisfy the constraint - 'Pattern': '^[-\w\._\(\)]+$'" if !resource_group_name.nil? && resource_group_name.match(Regexp.new('^^[-\w\._\(\)]+$$')).nil?
501
+ fail ArgumentError, 'resource_provider_namespace is nil' if resource_provider_namespace.nil?
502
+ fail ArgumentError, 'parent_resource_path is nil' if parent_resource_path.nil?
503
+ fail ArgumentError, 'resource_type is nil' if resource_type.nil?
504
+ fail ArgumentError, 'resource_name is nil' if resource_name.nil?
505
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
506
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
507
+
508
+
509
+ request_headers = {}
510
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
511
+
512
+ # Set Headers
513
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
514
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
515
+ path_template = 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyassignments'
516
+
517
+ request_url = @base_url || @client.base_url
518
+
519
+ options = {
520
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
521
+ path_params: {'resourceGroupName' => resource_group_name,'resourceProviderNamespace' => resource_provider_namespace,'resourceName' => resource_name,'subscriptionId' => @client.subscription_id},
522
+ skip_encoding_path_params: {'parentResourcePath' => parent_resource_path,'resourceType' => resource_type},
523
+ query_params: {'$filter' => filter,'api-version' => @client.api_version},
524
+ headers: request_headers.merge(custom_headers || {}),
525
+ base_url: request_url
526
+ }
527
+ promise = @client.make_request_async(:get, path_template, options)
528
+
529
+ promise = promise.then do |result|
530
+ http_response = result.response
531
+ status_code = http_response.status
532
+ response_content = http_response.body
533
+ unless status_code == 200
534
+ error_model = JSON.load(response_content)
535
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
536
+ end
537
+
538
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
539
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
540
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
541
+ # Deserialize Response
542
+ if status_code == 200
543
+ begin
544
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
545
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
546
+ result.body = @client.deserialize(result_mapper, parsed_response)
547
+ rescue Exception => e
548
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
549
+ end
550
+ end
551
+
552
+ result
553
+ end
554
+
555
+ promise.execute
556
+ end
557
+
558
+ #
559
+ # Gets all the policy assignments for a subscription.
560
+ #
561
+ # @param filter [String] The filter to apply on the operation.
562
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
563
+ # will be added to the HTTP request.
564
+ #
565
+ # @return [Array<PolicyAssignment>] operation results.
566
+ #
567
+ def list(filter:nil, custom_headers:nil)
568
+ first_page = list_as_lazy(filter:filter, custom_headers:custom_headers)
569
+ first_page.get_all_items
570
+ end
571
+
572
+ #
573
+ # Gets all the policy assignments for a subscription.
574
+ #
575
+ # @param filter [String] The filter to apply on the operation.
576
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
577
+ # will be added to the HTTP request.
578
+ #
579
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
580
+ #
581
+ def list_with_http_info(filter:nil, custom_headers:nil)
582
+ list_async(filter:filter, custom_headers:custom_headers).value!
583
+ end
584
+
585
+ #
586
+ # Gets all the policy assignments for a subscription.
587
+ #
588
+ # @param filter [String] The filter to apply on the operation.
589
+ # @param [Hash{String => String}] A hash of custom headers that will be added
590
+ # to the HTTP request.
591
+ #
592
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
593
+ #
594
+ def list_async(filter:nil, custom_headers:nil)
595
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
596
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
597
+
598
+
599
+ request_headers = {}
600
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
601
+
602
+ # Set Headers
603
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
604
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
605
+ path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyassignments'
606
+
607
+ request_url = @base_url || @client.base_url
608
+
609
+ options = {
610
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
611
+ path_params: {'subscriptionId' => @client.subscription_id},
612
+ query_params: {'$filter' => filter,'api-version' => @client.api_version},
613
+ headers: request_headers.merge(custom_headers || {}),
614
+ base_url: request_url
615
+ }
616
+ promise = @client.make_request_async(:get, path_template, options)
617
+
618
+ promise = promise.then do |result|
619
+ http_response = result.response
620
+ status_code = http_response.status
621
+ response_content = http_response.body
622
+ unless status_code == 200
623
+ error_model = JSON.load(response_content)
624
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
625
+ end
626
+
627
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
628
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
629
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
630
+ # Deserialize Response
631
+ if status_code == 200
632
+ begin
633
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
634
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
635
+ result.body = @client.deserialize(result_mapper, parsed_response)
636
+ rescue Exception => e
637
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
638
+ end
639
+ end
640
+
641
+ result
642
+ end
643
+
644
+ promise.execute
645
+ end
646
+
647
+ #
648
+ # Deletes a policy assignment by ID.
649
+ #
650
+ # When providing a scope for the assignment, use
651
+ # '/subscriptions/{subscription-id}/' for subscriptions,
652
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
653
+ # resource groups, and
654
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
655
+ # for resources.
656
+ #
657
+ # @param policy_assignment_id [String] The ID of the policy assignment to
658
+ # delete. Use the format
659
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
660
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
661
+ # will be added to the HTTP request.
662
+ #
663
+ # @return [PolicyAssignment] operation results.
664
+ #
665
+ def delete_by_id(policy_assignment_id, custom_headers:nil)
666
+ response = delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
667
+ response.body unless response.nil?
668
+ end
669
+
670
+ #
671
+ # Deletes a policy assignment by ID.
672
+ #
673
+ # When providing a scope for the assignment, use
674
+ # '/subscriptions/{subscription-id}/' for subscriptions,
675
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
676
+ # resource groups, and
677
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
678
+ # for resources.
679
+ #
680
+ # @param policy_assignment_id [String] The ID of the policy assignment to
681
+ # delete. Use the format
682
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
683
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
684
+ # will be added to the HTTP request.
685
+ #
686
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
687
+ #
688
+ def delete_by_id_with_http_info(policy_assignment_id, custom_headers:nil)
689
+ delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
690
+ end
691
+
692
+ #
693
+ # Deletes a policy assignment by ID.
694
+ #
695
+ # When providing a scope for the assignment, use
696
+ # '/subscriptions/{subscription-id}/' for subscriptions,
697
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
698
+ # resource groups, and
699
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
700
+ # for resources.
701
+ #
702
+ # @param policy_assignment_id [String] The ID of the policy assignment to
703
+ # delete. Use the format
704
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
705
+ # @param [Hash{String => String}] A hash of custom headers that will be added
706
+ # to the HTTP request.
707
+ #
708
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
709
+ #
710
+ def delete_by_id_async(policy_assignment_id, custom_headers:nil)
711
+ fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
712
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
713
+
714
+
715
+ request_headers = {}
716
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
717
+
718
+ # Set Headers
719
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
720
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
721
+ path_template = '{policyAssignmentId}'
722
+
723
+ request_url = @base_url || @client.base_url
724
+
725
+ options = {
726
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
727
+ skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
728
+ query_params: {'api-version' => @client.api_version},
729
+ headers: request_headers.merge(custom_headers || {}),
730
+ base_url: request_url
731
+ }
732
+ promise = @client.make_request_async(:delete, path_template, options)
733
+
734
+ promise = promise.then do |result|
735
+ http_response = result.response
736
+ status_code = http_response.status
737
+ response_content = http_response.body
738
+ unless status_code == 200
739
+ error_model = JSON.load(response_content)
740
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
741
+ end
742
+
743
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
744
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
745
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
746
+ # Deserialize Response
747
+ if status_code == 200
748
+ begin
749
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
750
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
751
+ result.body = @client.deserialize(result_mapper, parsed_response)
752
+ rescue Exception => e
753
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
754
+ end
755
+ end
756
+
757
+ result
758
+ end
759
+
760
+ promise.execute
761
+ end
762
+
763
+ #
764
+ # Creates a policy assignment by ID.
765
+ #
766
+ # Policy assignments are inherited by child resources. For example, when you
767
+ # apply a policy to a resource group that policy is assigned to all resources
768
+ # in the group. When providing a scope for the assignment, use
769
+ # '/subscriptions/{subscription-id}/' for subscriptions,
770
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
771
+ # resource groups, and
772
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
773
+ # for resources.
774
+ #
775
+ # @param policy_assignment_id [String] The ID of the policy assignment to
776
+ # create. Use the format
777
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
778
+ # @param parameters [PolicyAssignment] Parameters for policy assignment.
779
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
780
+ # will be added to the HTTP request.
781
+ #
782
+ # @return [PolicyAssignment] operation results.
783
+ #
784
+ def create_by_id(policy_assignment_id, parameters, custom_headers:nil)
785
+ response = create_by_id_async(policy_assignment_id, parameters, custom_headers:custom_headers).value!
786
+ response.body unless response.nil?
787
+ end
788
+
789
+ #
790
+ # Creates a policy assignment by ID.
791
+ #
792
+ # Policy assignments are inherited by child resources. For example, when you
793
+ # apply a policy to a resource group that policy is assigned to all resources
794
+ # in the group. When providing a scope for the assignment, use
795
+ # '/subscriptions/{subscription-id}/' for subscriptions,
796
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
797
+ # resource groups, and
798
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
799
+ # for resources.
800
+ #
801
+ # @param policy_assignment_id [String] The ID of the policy assignment to
802
+ # create. Use the format
803
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
804
+ # @param parameters [PolicyAssignment] Parameters for policy assignment.
805
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
806
+ # will be added to the HTTP request.
807
+ #
808
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
809
+ #
810
+ def create_by_id_with_http_info(policy_assignment_id, parameters, custom_headers:nil)
811
+ create_by_id_async(policy_assignment_id, parameters, custom_headers:custom_headers).value!
812
+ end
813
+
814
+ #
815
+ # Creates a policy assignment by ID.
816
+ #
817
+ # Policy assignments are inherited by child resources. For example, when you
818
+ # apply a policy to a resource group that policy is assigned to all resources
819
+ # in the group. When providing a scope for the assignment, use
820
+ # '/subscriptions/{subscription-id}/' for subscriptions,
821
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
822
+ # resource groups, and
823
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
824
+ # for resources.
825
+ #
826
+ # @param policy_assignment_id [String] The ID of the policy assignment to
827
+ # create. Use the format
828
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
829
+ # @param parameters [PolicyAssignment] Parameters for policy assignment.
830
+ # @param [Hash{String => String}] A hash of custom headers that will be added
831
+ # to the HTTP request.
832
+ #
833
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
834
+ #
835
+ def create_by_id_async(policy_assignment_id, parameters, custom_headers:nil)
836
+ fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
837
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
838
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
839
+
840
+
841
+ request_headers = {}
842
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
843
+
844
+ # Set Headers
845
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
846
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
847
+
848
+ # Serialize Request
849
+ request_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
850
+ request_content = @client.serialize(request_mapper, parameters)
851
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
852
+
853
+ path_template = '{policyAssignmentId}'
854
+
855
+ request_url = @base_url || @client.base_url
856
+
857
+ options = {
858
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
859
+ skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
860
+ query_params: {'api-version' => @client.api_version},
861
+ body: request_content,
862
+ headers: request_headers.merge(custom_headers || {}),
863
+ base_url: request_url
864
+ }
865
+ promise = @client.make_request_async(:put, path_template, options)
866
+
867
+ promise = promise.then do |result|
868
+ http_response = result.response
869
+ status_code = http_response.status
870
+ response_content = http_response.body
871
+ unless status_code == 201
872
+ error_model = JSON.load(response_content)
873
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
874
+ end
875
+
876
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
877
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
878
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
879
+ # Deserialize Response
880
+ if status_code == 201
881
+ begin
882
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
883
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
884
+ result.body = @client.deserialize(result_mapper, parsed_response)
885
+ rescue Exception => e
886
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
887
+ end
888
+ end
889
+
890
+ result
891
+ end
892
+
893
+ promise.execute
894
+ end
895
+
896
+ #
897
+ # Gets a policy assignment by ID.
898
+ #
899
+ # When providing a scope for the assignment, use
900
+ # '/subscriptions/{subscription-id}/' for subscriptions,
901
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
902
+ # resource groups, and
903
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
904
+ # for resources.
905
+ #
906
+ # @param policy_assignment_id [String] The ID of the policy assignment to get.
907
+ # Use the format
908
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
909
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
910
+ # will be added to the HTTP request.
911
+ #
912
+ # @return [PolicyAssignment] operation results.
913
+ #
914
+ def get_by_id(policy_assignment_id, custom_headers:nil)
915
+ response = get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
916
+ response.body unless response.nil?
917
+ end
918
+
919
+ #
920
+ # Gets a policy assignment by ID.
921
+ #
922
+ # When providing a scope for the assignment, use
923
+ # '/subscriptions/{subscription-id}/' for subscriptions,
924
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
925
+ # resource groups, and
926
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
927
+ # for resources.
928
+ #
929
+ # @param policy_assignment_id [String] The ID of the policy assignment to get.
930
+ # Use the format
931
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
932
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
933
+ # will be added to the HTTP request.
934
+ #
935
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
936
+ #
937
+ def get_by_id_with_http_info(policy_assignment_id, custom_headers:nil)
938
+ get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
939
+ end
940
+
941
+ #
942
+ # Gets a policy assignment by ID.
943
+ #
944
+ # When providing a scope for the assignment, use
945
+ # '/subscriptions/{subscription-id}/' for subscriptions,
946
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
947
+ # resource groups, and
948
+ # '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
949
+ # for resources.
950
+ #
951
+ # @param policy_assignment_id [String] The ID of the policy assignment to get.
952
+ # Use the format
953
+ # '/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
954
+ # @param [Hash{String => String}] A hash of custom headers that will be added
955
+ # to the HTTP request.
956
+ #
957
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
958
+ #
959
+ def get_by_id_async(policy_assignment_id, custom_headers:nil)
960
+ fail ArgumentError, 'policy_assignment_id is nil' if policy_assignment_id.nil?
961
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
962
+
963
+
964
+ request_headers = {}
965
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
966
+
967
+ # Set Headers
968
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
969
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
970
+ path_template = '{policyAssignmentId}'
971
+
972
+ request_url = @base_url || @client.base_url
973
+
974
+ options = {
975
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
976
+ skip_encoding_path_params: {'policyAssignmentId' => policy_assignment_id},
977
+ query_params: {'api-version' => @client.api_version},
978
+ headers: request_headers.merge(custom_headers || {}),
979
+ base_url: request_url
980
+ }
981
+ promise = @client.make_request_async(:get, path_template, options)
982
+
983
+ promise = promise.then do |result|
984
+ http_response = result.response
985
+ status_code = http_response.status
986
+ response_content = http_response.body
987
+ unless status_code == 200
988
+ error_model = JSON.load(response_content)
989
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
990
+ end
991
+
992
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
993
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
994
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
995
+ # Deserialize Response
996
+ if status_code == 200
997
+ begin
998
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
999
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignment.mapper()
1000
+ result.body = @client.deserialize(result_mapper, parsed_response)
1001
+ rescue Exception => e
1002
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1003
+ end
1004
+ end
1005
+
1006
+ result
1007
+ end
1008
+
1009
+ promise.execute
1010
+ end
1011
+
1012
+ #
1013
+ # Gets policy assignments for the resource group.
1014
+ #
1015
+ # @param next_page_link [String] The NextLink from the previous successful call
1016
+ # to List operation.
1017
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1018
+ # will be added to the HTTP request.
1019
+ #
1020
+ # @return [PolicyAssignmentListResult] operation results.
1021
+ #
1022
+ def list_for_resource_group_next(next_page_link, custom_headers:nil)
1023
+ response = list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
1024
+ response.body unless response.nil?
1025
+ end
1026
+
1027
+ #
1028
+ # Gets policy assignments for the resource group.
1029
+ #
1030
+ # @param next_page_link [String] The NextLink from the previous successful call
1031
+ # to List operation.
1032
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1033
+ # will be added to the HTTP request.
1034
+ #
1035
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1036
+ #
1037
+ def list_for_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
1038
+ list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
1039
+ end
1040
+
1041
+ #
1042
+ # Gets policy assignments for the resource group.
1043
+ #
1044
+ # @param next_page_link [String] The NextLink from the previous successful call
1045
+ # to List operation.
1046
+ # @param [Hash{String => String}] A hash of custom headers that will be added
1047
+ # to the HTTP request.
1048
+ #
1049
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1050
+ #
1051
+ def list_for_resource_group_next_async(next_page_link, custom_headers:nil)
1052
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1053
+
1054
+
1055
+ request_headers = {}
1056
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
1057
+
1058
+ # Set Headers
1059
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1060
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1061
+ path_template = '{nextLink}'
1062
+
1063
+ request_url = @base_url || @client.base_url
1064
+
1065
+ options = {
1066
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1067
+ skip_encoding_path_params: {'nextLink' => next_page_link},
1068
+ headers: request_headers.merge(custom_headers || {}),
1069
+ base_url: request_url
1070
+ }
1071
+ promise = @client.make_request_async(:get, path_template, options)
1072
+
1073
+ promise = promise.then do |result|
1074
+ http_response = result.response
1075
+ status_code = http_response.status
1076
+ response_content = http_response.body
1077
+ unless status_code == 200
1078
+ error_model = JSON.load(response_content)
1079
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1080
+ end
1081
+
1082
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1083
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1084
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1085
+ # Deserialize Response
1086
+ if status_code == 200
1087
+ begin
1088
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1089
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1090
+ result.body = @client.deserialize(result_mapper, parsed_response)
1091
+ rescue Exception => e
1092
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1093
+ end
1094
+ end
1095
+
1096
+ result
1097
+ end
1098
+
1099
+ promise.execute
1100
+ end
1101
+
1102
+ #
1103
+ # Gets policy assignments for a resource.
1104
+ #
1105
+ # @param next_page_link [String] The NextLink from the previous successful call
1106
+ # to List operation.
1107
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1108
+ # will be added to the HTTP request.
1109
+ #
1110
+ # @return [PolicyAssignmentListResult] operation results.
1111
+ #
1112
+ def list_for_resource_next(next_page_link, custom_headers:nil)
1113
+ response = list_for_resource_next_async(next_page_link, custom_headers:custom_headers).value!
1114
+ response.body unless response.nil?
1115
+ end
1116
+
1117
+ #
1118
+ # Gets policy assignments for a resource.
1119
+ #
1120
+ # @param next_page_link [String] The NextLink from the previous successful call
1121
+ # to List operation.
1122
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1123
+ # will be added to the HTTP request.
1124
+ #
1125
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1126
+ #
1127
+ def list_for_resource_next_with_http_info(next_page_link, custom_headers:nil)
1128
+ list_for_resource_next_async(next_page_link, custom_headers:custom_headers).value!
1129
+ end
1130
+
1131
+ #
1132
+ # Gets policy assignments for a resource.
1133
+ #
1134
+ # @param next_page_link [String] The NextLink from the previous successful call
1135
+ # to List operation.
1136
+ # @param [Hash{String => String}] A hash of custom headers that will be added
1137
+ # to the HTTP request.
1138
+ #
1139
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1140
+ #
1141
+ def list_for_resource_next_async(next_page_link, custom_headers:nil)
1142
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1143
+
1144
+
1145
+ request_headers = {}
1146
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
1147
+
1148
+ # Set Headers
1149
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1150
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1151
+ path_template = '{nextLink}'
1152
+
1153
+ request_url = @base_url || @client.base_url
1154
+
1155
+ options = {
1156
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1157
+ skip_encoding_path_params: {'nextLink' => next_page_link},
1158
+ headers: request_headers.merge(custom_headers || {}),
1159
+ base_url: request_url
1160
+ }
1161
+ promise = @client.make_request_async(:get, path_template, options)
1162
+
1163
+ promise = promise.then do |result|
1164
+ http_response = result.response
1165
+ status_code = http_response.status
1166
+ response_content = http_response.body
1167
+ unless status_code == 200
1168
+ error_model = JSON.load(response_content)
1169
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1170
+ end
1171
+
1172
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1173
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1174
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1175
+ # Deserialize Response
1176
+ if status_code == 200
1177
+ begin
1178
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1179
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1180
+ result.body = @client.deserialize(result_mapper, parsed_response)
1181
+ rescue Exception => e
1182
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1183
+ end
1184
+ end
1185
+
1186
+ result
1187
+ end
1188
+
1189
+ promise.execute
1190
+ end
1191
+
1192
+ #
1193
+ # Gets all the policy assignments for a subscription.
1194
+ #
1195
+ # @param next_page_link [String] The NextLink from the previous successful call
1196
+ # to List operation.
1197
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1198
+ # will be added to the HTTP request.
1199
+ #
1200
+ # @return [PolicyAssignmentListResult] operation results.
1201
+ #
1202
+ def list_next(next_page_link, custom_headers:nil)
1203
+ response = list_next_async(next_page_link, custom_headers:custom_headers).value!
1204
+ response.body unless response.nil?
1205
+ end
1206
+
1207
+ #
1208
+ # Gets all the policy assignments for a subscription.
1209
+ #
1210
+ # @param next_page_link [String] The NextLink from the previous successful call
1211
+ # to List operation.
1212
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1213
+ # will be added to the HTTP request.
1214
+ #
1215
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
1216
+ #
1217
+ def list_next_with_http_info(next_page_link, custom_headers:nil)
1218
+ list_next_async(next_page_link, custom_headers:custom_headers).value!
1219
+ end
1220
+
1221
+ #
1222
+ # Gets all the policy assignments for a subscription.
1223
+ #
1224
+ # @param next_page_link [String] The NextLink from the previous successful call
1225
+ # to List operation.
1226
+ # @param [Hash{String => String}] A hash of custom headers that will be added
1227
+ # to the HTTP request.
1228
+ #
1229
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
1230
+ #
1231
+ def list_next_async(next_page_link, custom_headers:nil)
1232
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1233
+
1234
+
1235
+ request_headers = {}
1236
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
1237
+
1238
+ # Set Headers
1239
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1240
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
1241
+ path_template = '{nextLink}'
1242
+
1243
+ request_url = @base_url || @client.base_url
1244
+
1245
+ options = {
1246
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
1247
+ skip_encoding_path_params: {'nextLink' => next_page_link},
1248
+ headers: request_headers.merge(custom_headers || {}),
1249
+ base_url: request_url
1250
+ }
1251
+ promise = @client.make_request_async(:get, path_template, options)
1252
+
1253
+ promise = promise.then do |result|
1254
+ http_response = result.response
1255
+ status_code = http_response.status
1256
+ response_content = http_response.body
1257
+ unless status_code == 200
1258
+ error_model = JSON.load(response_content)
1259
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
1260
+ end
1261
+
1262
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1263
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
1264
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
1265
+ # Deserialize Response
1266
+ if status_code == 200
1267
+ begin
1268
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
1269
+ result_mapper = Azure::Policy::Mgmt::V2016_04_01::Models::PolicyAssignmentListResult.mapper()
1270
+ result.body = @client.deserialize(result_mapper, parsed_response)
1271
+ rescue Exception => e
1272
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
1273
+ end
1274
+ end
1275
+
1276
+ result
1277
+ end
1278
+
1279
+ promise.execute
1280
+ end
1281
+
1282
+ #
1283
+ # Gets policy assignments for the resource group.
1284
+ #
1285
+ # @param resource_group_name [String] The name of the resource group that
1286
+ # contains policy assignments.
1287
+ # @param filter [String] The filter to apply on the operation.
1288
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1289
+ # will be added to the HTTP request.
1290
+ #
1291
+ # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1292
+ # the response.
1293
+ #
1294
+ def list_for_resource_group_as_lazy(resource_group_name, filter:nil, custom_headers:nil)
1295
+ response = list_for_resource_group_async(resource_group_name, filter:filter, custom_headers:custom_headers).value!
1296
+ unless response.nil?
1297
+ page = response.body
1298
+ page.next_method = Proc.new do |next_page_link|
1299
+ list_for_resource_group_next_async(next_page_link, custom_headers:custom_headers)
1300
+ end
1301
+ page
1302
+ end
1303
+ end
1304
+
1305
+ #
1306
+ # Gets policy assignments for a resource.
1307
+ #
1308
+ # @param resource_group_name [String] The name of the resource group containing
1309
+ # the resource. The name is case insensitive.
1310
+ # @param resource_provider_namespace [String] The namespace of the resource
1311
+ # provider.
1312
+ # @param parent_resource_path [String] The parent resource path.
1313
+ # @param resource_type [String] The resource type.
1314
+ # @param resource_name [String] The name of the resource with policy
1315
+ # assignments.
1316
+ # @param filter [String] The filter to apply on the operation.
1317
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1318
+ # will be added to the HTTP request.
1319
+ #
1320
+ # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1321
+ # the response.
1322
+ #
1323
+ def list_for_resource_as_lazy(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:nil, custom_headers:nil)
1324
+ response = list_for_resource_async(resource_group_name, resource_provider_namespace, parent_resource_path, resource_type, resource_name, filter:filter, custom_headers:custom_headers).value!
1325
+ unless response.nil?
1326
+ page = response.body
1327
+ page.next_method = Proc.new do |next_page_link|
1328
+ list_for_resource_next_async(next_page_link, custom_headers:custom_headers)
1329
+ end
1330
+ page
1331
+ end
1332
+ end
1333
+
1334
+ #
1335
+ # Gets all the policy assignments for a subscription.
1336
+ #
1337
+ # @param filter [String] The filter to apply on the operation.
1338
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
1339
+ # will be added to the HTTP request.
1340
+ #
1341
+ # @return [PolicyAssignmentListResult] which provide lazy access to pages of
1342
+ # the response.
1343
+ #
1344
+ def list_as_lazy(filter:nil, custom_headers:nil)
1345
+ response = list_async(filter:filter, custom_headers:custom_headers).value!
1346
+ unless response.nil?
1347
+ page = response.body
1348
+ page.next_method = Proc.new do |next_page_link|
1349
+ list_next_async(next_page_link, custom_headers:custom_headers)
1350
+ end
1351
+ page
1352
+ end
1353
+ end
1354
+
1355
+ end
1356
+ end