| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.ResourceManager.Resources.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.ResourceManager.Resources |
| | 18 | | { |
| | 19 | | internal partial class SubscriptionsRestOperations |
| | 20 | | { |
| | 21 | | private Uri endpoint; |
| | 22 | | private ClientDiagnostics _clientDiagnostics; |
| | 23 | | private HttpPipeline _pipeline; |
| | 24 | |
|
| | 25 | | /// <summary> Initializes a new instance of SubscriptionsRestOperations. </summary> |
| | 26 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 27 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 28 | | /// <param name="endpoint"> server parameter. </param> |
| 268 | 29 | | public SubscriptionsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = nu |
| | 30 | | { |
| 268 | 31 | | endpoint ??= new Uri("https://management.azure.com"); |
| | 32 | |
|
| 268 | 33 | | this.endpoint = endpoint; |
| 268 | 34 | | _clientDiagnostics = clientDiagnostics; |
| 268 | 35 | | _pipeline = pipeline; |
| 268 | 36 | | } |
| | 37 | |
|
| | 38 | | internal Core.HttpMessage CreateListLocationsRequest(string subscriptionId) |
| | 39 | | { |
| 4 | 40 | | var message = _pipeline.CreateMessage(); |
| 4 | 41 | | var request = message.Request; |
| 4 | 42 | | request.Method = RequestMethod.Get; |
| 4 | 43 | | var uri = new RawRequestUriBuilder(); |
| 4 | 44 | | uri.Reset(endpoint); |
| 4 | 45 | | uri.AppendPath("/subscriptions/", false); |
| 4 | 46 | | uri.AppendPath(subscriptionId, true); |
| 4 | 47 | | uri.AppendPath("/locations", false); |
| 4 | 48 | | uri.AppendQuery("api-version", "2019-11-01", true); |
| 4 | 49 | | request.Uri = uri; |
| 4 | 50 | | return message; |
| | 51 | | } |
| | 52 | |
|
| | 53 | | /// <summary> This operation provides all the locations that are available for resource providers; however, each |
| | 54 | | /// <param name="subscriptionId"> The ID of the target subscription. </param> |
| | 55 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 56 | | public async Task<Response<LocationListResult>> ListLocationsAsync(string subscriptionId, CancellationToken canc |
| | 57 | | { |
| 2 | 58 | | if (subscriptionId == null) |
| | 59 | | { |
| 0 | 60 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 61 | | } |
| | 62 | |
|
| 2 | 63 | | using var message = CreateListLocationsRequest(subscriptionId); |
| 2 | 64 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 65 | | switch (message.Response.Status) |
| | 66 | | { |
| | 67 | | case 200: |
| | 68 | | { |
| 2 | 69 | | LocationListResult value = default; |
| 2 | 70 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 71 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 72 | | { |
| 0 | 73 | | value = null; |
| | 74 | | } |
| | 75 | | else |
| | 76 | | { |
| 2 | 77 | | value = LocationListResult.DeserializeLocationListResult(document.RootElement); |
| | 78 | | } |
| 2 | 79 | | return Response.FromValue(value, message.Response); |
| | 80 | | } |
| | 81 | | default: |
| 0 | 82 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 83 | | } |
| 2 | 84 | | } |
| | 85 | |
|
| | 86 | | /// <summary> This operation provides all the locations that are available for resource providers; however, each |
| | 87 | | /// <param name="subscriptionId"> The ID of the target subscription. </param> |
| | 88 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 89 | | public Response<LocationListResult> ListLocations(string subscriptionId, CancellationToken cancellationToken = d |
| | 90 | | { |
| 2 | 91 | | if (subscriptionId == null) |
| | 92 | | { |
| 0 | 93 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 94 | | } |
| | 95 | |
|
| 2 | 96 | | using var message = CreateListLocationsRequest(subscriptionId); |
| 2 | 97 | | _pipeline.Send(message, cancellationToken); |
| 2 | 98 | | switch (message.Response.Status) |
| | 99 | | { |
| | 100 | | case 200: |
| | 101 | | { |
| 2 | 102 | | LocationListResult value = default; |
| 2 | 103 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 104 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 105 | | { |
| 0 | 106 | | value = null; |
| | 107 | | } |
| | 108 | | else |
| | 109 | | { |
| 2 | 110 | | value = LocationListResult.DeserializeLocationListResult(document.RootElement); |
| | 111 | | } |
| 2 | 112 | | return Response.FromValue(value, message.Response); |
| | 113 | | } |
| | 114 | | default: |
| 0 | 115 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 116 | | } |
| 2 | 117 | | } |
| | 118 | |
|
| | 119 | | internal Core.HttpMessage CreateGetRequest(string subscriptionId) |
| | 120 | | { |
| 8 | 121 | | var message = _pipeline.CreateMessage(); |
| 8 | 122 | | var request = message.Request; |
| 8 | 123 | | request.Method = RequestMethod.Get; |
| 8 | 124 | | var uri = new RawRequestUriBuilder(); |
| 8 | 125 | | uri.Reset(endpoint); |
| 8 | 126 | | uri.AppendPath("/subscriptions/", false); |
| 8 | 127 | | uri.AppendPath(subscriptionId, true); |
| 8 | 128 | | uri.AppendQuery("api-version", "2019-11-01", true); |
| 8 | 129 | | request.Uri = uri; |
| 8 | 130 | | return message; |
| | 131 | | } |
| | 132 | |
|
| | 133 | | /// <summary> Gets details about a specified subscription. </summary> |
| | 134 | | /// <param name="subscriptionId"> The ID of the target subscription. </param> |
| | 135 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 136 | | public async Task<Response<Subscription>> GetAsync(string subscriptionId, CancellationToken cancellationToken = |
| | 137 | | { |
| 4 | 138 | | if (subscriptionId == null) |
| | 139 | | { |
| 0 | 140 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 141 | | } |
| | 142 | |
|
| 4 | 143 | | using var message = CreateGetRequest(subscriptionId); |
| 4 | 144 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 145 | | switch (message.Response.Status) |
| | 146 | | { |
| | 147 | | case 200: |
| | 148 | | { |
| 4 | 149 | | Subscription value = default; |
| 4 | 150 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 4 | 151 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 152 | | { |
| 0 | 153 | | value = null; |
| | 154 | | } |
| | 155 | | else |
| | 156 | | { |
| 4 | 157 | | value = Subscription.DeserializeSubscription(document.RootElement); |
| | 158 | | } |
| 4 | 159 | | return Response.FromValue(value, message.Response); |
| | 160 | | } |
| | 161 | | default: |
| 0 | 162 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 163 | | } |
| 4 | 164 | | } |
| | 165 | |
|
| | 166 | | /// <summary> Gets details about a specified subscription. </summary> |
| | 167 | | /// <param name="subscriptionId"> The ID of the target subscription. </param> |
| | 168 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 169 | | public Response<Subscription> Get(string subscriptionId, CancellationToken cancellationToken = default) |
| | 170 | | { |
| 4 | 171 | | if (subscriptionId == null) |
| | 172 | | { |
| 0 | 173 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 174 | | } |
| | 175 | |
|
| 4 | 176 | | using var message = CreateGetRequest(subscriptionId); |
| 4 | 177 | | _pipeline.Send(message, cancellationToken); |
| 4 | 178 | | switch (message.Response.Status) |
| | 179 | | { |
| | 180 | | case 200: |
| | 181 | | { |
| 4 | 182 | | Subscription value = default; |
| 4 | 183 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 4 | 184 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 185 | | { |
| 0 | 186 | | value = null; |
| | 187 | | } |
| | 188 | | else |
| | 189 | | { |
| 4 | 190 | | value = Subscription.DeserializeSubscription(document.RootElement); |
| | 191 | | } |
| 4 | 192 | | return Response.FromValue(value, message.Response); |
| | 193 | | } |
| | 194 | | default: |
| 0 | 195 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 196 | | } |
| 4 | 197 | | } |
| | 198 | |
|
| | 199 | | internal Core.HttpMessage CreateListRequest() |
| | 200 | | { |
| 8 | 201 | | var message = _pipeline.CreateMessage(); |
| 8 | 202 | | var request = message.Request; |
| 8 | 203 | | request.Method = RequestMethod.Get; |
| 8 | 204 | | var uri = new RawRequestUriBuilder(); |
| 8 | 205 | | uri.Reset(endpoint); |
| 8 | 206 | | uri.AppendPath("/subscriptions", false); |
| 8 | 207 | | uri.AppendQuery("api-version", "2019-11-01", true); |
| 8 | 208 | | request.Uri = uri; |
| 8 | 209 | | return message; |
| | 210 | | } |
| | 211 | |
|
| | 212 | | /// <summary> Gets all subscriptions for a tenant. </summary> |
| | 213 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 214 | | public async Task<Response<SubscriptionListResult>> ListAsync(CancellationToken cancellationToken = default) |
| | 215 | | { |
| 4 | 216 | | using var message = CreateListRequest(); |
| 4 | 217 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 218 | | switch (message.Response.Status) |
| | 219 | | { |
| | 220 | | case 200: |
| | 221 | | { |
| 4 | 222 | | SubscriptionListResult value = default; |
| 4 | 223 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 4 | 224 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 225 | | { |
| 0 | 226 | | value = null; |
| | 227 | | } |
| | 228 | | else |
| | 229 | | { |
| 4 | 230 | | value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement); |
| | 231 | | } |
| 4 | 232 | | return Response.FromValue(value, message.Response); |
| | 233 | | } |
| | 234 | | default: |
| 0 | 235 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 236 | | } |
| 4 | 237 | | } |
| | 238 | |
|
| | 239 | | /// <summary> Gets all subscriptions for a tenant. </summary> |
| | 240 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 241 | | public Response<SubscriptionListResult> List(CancellationToken cancellationToken = default) |
| | 242 | | { |
| 4 | 243 | | using var message = CreateListRequest(); |
| 4 | 244 | | _pipeline.Send(message, cancellationToken); |
| 4 | 245 | | switch (message.Response.Status) |
| | 246 | | { |
| | 247 | | case 200: |
| | 248 | | { |
| 4 | 249 | | SubscriptionListResult value = default; |
| 4 | 250 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 4 | 251 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 252 | | { |
| 0 | 253 | | value = null; |
| | 254 | | } |
| | 255 | | else |
| | 256 | | { |
| 4 | 257 | | value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement); |
| | 258 | | } |
| 4 | 259 | | return Response.FromValue(value, message.Response); |
| | 260 | | } |
| | 261 | | default: |
| 0 | 262 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 263 | | } |
| 4 | 264 | | } |
| | 265 | |
|
| | 266 | | internal Core.HttpMessage CreateListNextPageRequest(string nextLink) |
| | 267 | | { |
| 0 | 268 | | var message = _pipeline.CreateMessage(); |
| 0 | 269 | | var request = message.Request; |
| 0 | 270 | | request.Method = RequestMethod.Get; |
| 0 | 271 | | var uri = new RawRequestUriBuilder(); |
| 0 | 272 | | uri.Reset(endpoint); |
| 0 | 273 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 274 | | request.Uri = uri; |
| 0 | 275 | | return message; |
| | 276 | | } |
| | 277 | |
|
| | 278 | | /// <summary> Gets all subscriptions for a tenant. </summary> |
| | 279 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 280 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 281 | | public async Task<Response<SubscriptionListResult>> ListNextPageAsync(string nextLink, CancellationToken cancell |
| | 282 | | { |
| 0 | 283 | | if (nextLink == null) |
| | 284 | | { |
| 0 | 285 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 286 | | } |
| | 287 | |
|
| 0 | 288 | | using var message = CreateListNextPageRequest(nextLink); |
| 0 | 289 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 290 | | switch (message.Response.Status) |
| | 291 | | { |
| | 292 | | case 200: |
| | 293 | | { |
| 0 | 294 | | SubscriptionListResult value = default; |
| 0 | 295 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 296 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 297 | | { |
| 0 | 298 | | value = null; |
| | 299 | | } |
| | 300 | | else |
| | 301 | | { |
| 0 | 302 | | value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement); |
| | 303 | | } |
| 0 | 304 | | return Response.FromValue(value, message.Response); |
| | 305 | | } |
| | 306 | | default: |
| 0 | 307 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 308 | | } |
| 0 | 309 | | } |
| | 310 | |
|
| | 311 | | /// <summary> Gets all subscriptions for a tenant. </summary> |
| | 312 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 313 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 314 | | public Response<SubscriptionListResult> ListNextPage(string nextLink, CancellationToken cancellationToken = defa |
| | 315 | | { |
| 0 | 316 | | if (nextLink == null) |
| | 317 | | { |
| 0 | 318 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 319 | | } |
| | 320 | |
|
| 0 | 321 | | using var message = CreateListNextPageRequest(nextLink); |
| 0 | 322 | | _pipeline.Send(message, cancellationToken); |
| 0 | 323 | | switch (message.Response.Status) |
| | 324 | | { |
| | 325 | | case 200: |
| | 326 | | { |
| 0 | 327 | | SubscriptionListResult value = default; |
| 0 | 328 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 329 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 330 | | { |
| 0 | 331 | | value = null; |
| | 332 | | } |
| | 333 | | else |
| | 334 | | { |
| 0 | 335 | | value = SubscriptionListResult.DeserializeSubscriptionListResult(document.RootElement); |
| | 336 | | } |
| 0 | 337 | | return Response.FromValue(value, message.Response); |
| | 338 | | } |
| | 339 | | default: |
| 0 | 340 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 341 | | } |
| 0 | 342 | | } |
| | 343 | | } |
| | 344 | | } |