| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.ContainerRegistry |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Threading; |
| | 23 | | using System.Threading.Tasks; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// ManifestsOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class ManifestsOperations : IServiceOperations<AzureContainerRegistryClient>, IManifestsOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the ManifestsOperations class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='client'> |
| | 34 | | /// Reference to the service client. |
| | 35 | | /// </param> |
| | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | 37 | | /// Thrown when a required parameter is null |
| | 38 | | /// </exception> |
| 60 | 39 | | internal ManifestsOperations(AzureContainerRegistryClient client) |
| | 40 | | { |
| 60 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 60 | 45 | | Client = client; |
| 60 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the AzureContainerRegistryClient |
| | 50 | | /// </summary> |
| 370 | 51 | | public AzureContainerRegistryClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Get the manifest identified by `name` and `reference` where `reference` can |
| | 55 | | /// be a tag or digest. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='name'> |
| | 58 | | /// Name of the image (including the namespace) |
| | 59 | | /// </param> |
| | 60 | | /// <param name='reference'> |
| | 61 | | /// A tag or a digest, pointing to a specific image |
| | 62 | | /// </param> |
| | 63 | | /// <param name='accept'> |
| | 64 | | /// Accept header string delimited by comma. For example, |
| | 65 | | /// application/vnd.docker.distribution.manifest.v2+json |
| | 66 | | /// </param> |
| | 67 | | /// <param name='customHeaders'> |
| | 68 | | /// Headers that will be added to request. |
| | 69 | | /// </param> |
| | 70 | | /// <param name='cancellationToken'> |
| | 71 | | /// The cancellation token. |
| | 72 | | /// </param> |
| | 73 | | /// <exception cref="AcrErrorsException"> |
| | 74 | | /// Thrown when the operation returned an invalid status code |
| | 75 | | /// </exception> |
| | 76 | | /// <exception cref="SerializationException"> |
| | 77 | | /// Thrown when unable to deserialize the response |
| | 78 | | /// </exception> |
| | 79 | | /// <exception cref="ValidationException"> |
| | 80 | | /// Thrown when a required parameter is null |
| | 81 | | /// </exception> |
| | 82 | | /// <exception cref="System.ArgumentNullException"> |
| | 83 | | /// Thrown when a required parameter is null |
| | 84 | | /// </exception> |
| | 85 | | /// <return> |
| | 86 | | /// A response object containing the response body and response headers. |
| | 87 | | /// </return> |
| | 88 | | public async Task<AzureOperationResponse<ManifestWrapper>> GetWithHttpMessagesAsync(string name, string referenc |
| | 89 | | { |
| 12 | 90 | | if (Client.LoginUri == null) |
| | 91 | | { |
| 0 | 92 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 93 | | } |
| 12 | 94 | | if (name == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 97 | | } |
| 12 | 98 | | if (reference == null) |
| | 99 | | { |
| 0 | 100 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 101 | | } |
| | 102 | | // Tracing |
| 12 | 103 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 12 | 104 | | string _invocationId = null; |
| 12 | 105 | | if (_shouldTrace) |
| | 106 | | { |
| 0 | 107 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 108 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 109 | | tracingParameters.Add("name", name); |
| 0 | 110 | | tracingParameters.Add("reference", reference); |
| 0 | 111 | | tracingParameters.Add("accept", accept); |
| 0 | 112 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 113 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 114 | | } |
| | 115 | | // Construct URL |
| 12 | 116 | | var _baseUrl = Client.BaseUri; |
| 12 | 117 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/manifests/{reference}"; |
| 12 | 118 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 12 | 119 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 12 | 120 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 12 | 121 | | List<string> _queryParameters = new List<string>(); |
| 12 | 122 | | if (_queryParameters.Count > 0) |
| | 123 | | { |
| 0 | 124 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 125 | | } |
| | 126 | | // Create HTTP transport objects |
| 12 | 127 | | var _httpRequest = new HttpRequestMessage(); |
| 12 | 128 | | HttpResponseMessage _httpResponse = null; |
| 12 | 129 | | _httpRequest.Method = new HttpMethod("GET"); |
| 12 | 130 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 131 | | // Set Headers |
| 12 | 132 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 133 | | { |
| 12 | 134 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 135 | | } |
| 12 | 136 | | if (accept != null) |
| | 137 | | { |
| 10 | 138 | | if (_httpRequest.Headers.Contains("accept")) |
| | 139 | | { |
| 0 | 140 | | _httpRequest.Headers.Remove("accept"); |
| | 141 | | } |
| 10 | 142 | | _httpRequest.Headers.TryAddWithoutValidation("accept", accept); |
| | 143 | | } |
| 12 | 144 | | if (Client.AcceptLanguage != null) |
| | 145 | | { |
| 12 | 146 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 147 | | { |
| 0 | 148 | | _httpRequest.Headers.Remove("accept-language"); |
| | 149 | | } |
| 12 | 150 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 151 | | } |
| | 152 | |
|
| | 153 | |
|
| 12 | 154 | | if (customHeaders != null) |
| | 155 | | { |
| 0 | 156 | | foreach(var _header in customHeaders) |
| | 157 | | { |
| 0 | 158 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 159 | | { |
| 0 | 160 | | _httpRequest.Headers.Remove(_header.Key); |
| | 161 | | } |
| 0 | 162 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 163 | | } |
| | 164 | | } |
| | 165 | |
|
| | 166 | | // Serialize Request |
| 12 | 167 | | string _requestContent = null; |
| | 168 | | // Set Credentials |
| 12 | 169 | | if (Client.Credentials != null) |
| | 170 | | { |
| 12 | 171 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 172 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 173 | | } |
| | 174 | | // Send Request |
| 12 | 175 | | if (_shouldTrace) |
| | 176 | | { |
| 0 | 177 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 178 | | } |
| 12 | 179 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 180 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 12 | 181 | | if (_shouldTrace) |
| | 182 | | { |
| 0 | 183 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 184 | | } |
| 12 | 185 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 12 | 186 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 187 | | string _responseContent = null; |
| 12 | 188 | | if ((int)_statusCode != 200) |
| | 189 | | { |
| 0 | 190 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 191 | | try |
| | 192 | | { |
| 0 | 193 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 194 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 195 | | if (_errorBody != null) |
| | 196 | | { |
| 0 | 197 | | ex.Body = _errorBody; |
| | 198 | | } |
| 0 | 199 | | } |
| 0 | 200 | | catch (JsonException) |
| | 201 | | { |
| | 202 | | // Ignore the exception |
| 0 | 203 | | } |
| 0 | 204 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 205 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 206 | | if (_shouldTrace) |
| | 207 | | { |
| 0 | 208 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 209 | | } |
| 0 | 210 | | _httpRequest.Dispose(); |
| 0 | 211 | | if (_httpResponse != null) |
| | 212 | | { |
| 0 | 213 | | _httpResponse.Dispose(); |
| | 214 | | } |
| 0 | 215 | | throw ex; |
| | 216 | | } |
| | 217 | | // Create Result |
| 12 | 218 | | var _result = new AzureOperationResponse<ManifestWrapper>(); |
| 12 | 219 | | _result.Request = _httpRequest; |
| 12 | 220 | | _result.Response = _httpResponse; |
| 12 | 221 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 222 | | { |
| 12 | 223 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 224 | | } |
| | 225 | | // Deserialize Response |
| 12 | 226 | | if ((int)_statusCode == 200) |
| | 227 | | { |
| 12 | 228 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 229 | | try |
| | 230 | | { |
| 12 | 231 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ManifestWrapper>(_responseConten |
| 12 | 232 | | } |
| 0 | 233 | | catch (JsonException ex) |
| | 234 | | { |
| 0 | 235 | | _httpRequest.Dispose(); |
| 0 | 236 | | if (_httpResponse != null) |
| | 237 | | { |
| 0 | 238 | | _httpResponse.Dispose(); |
| | 239 | | } |
| 0 | 240 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 241 | | } |
| | 242 | | } |
| 12 | 243 | | if (_shouldTrace) |
| | 244 | | { |
| 0 | 245 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 246 | | } |
| 12 | 247 | | return _result; |
| 12 | 248 | | } |
| | 249 | |
|
| | 250 | | /// <summary> |
| | 251 | | /// Put the manifest identified by `name` and `reference` where `reference` can |
| | 252 | | /// be a tag or digest. |
| | 253 | | /// </summary> |
| | 254 | | /// <param name='name'> |
| | 255 | | /// Name of the image (including the namespace) |
| | 256 | | /// </param> |
| | 257 | | /// <param name='reference'> |
| | 258 | | /// A tag or a digest, pointing to a specific image |
| | 259 | | /// </param> |
| | 260 | | /// <param name='payload'> |
| | 261 | | /// Manifest body, can take v1 or v2 values depending on accept header |
| | 262 | | /// </param> |
| | 263 | | /// <param name='customHeaders'> |
| | 264 | | /// Headers that will be added to request. |
| | 265 | | /// </param> |
| | 266 | | /// <param name='cancellationToken'> |
| | 267 | | /// The cancellation token. |
| | 268 | | /// </param> |
| | 269 | | /// <exception cref="AcrErrorsException"> |
| | 270 | | /// Thrown when the operation returned an invalid status code |
| | 271 | | /// </exception> |
| | 272 | | /// <exception cref="SerializationException"> |
| | 273 | | /// Thrown when unable to deserialize the response |
| | 274 | | /// </exception> |
| | 275 | | /// <exception cref="ValidationException"> |
| | 276 | | /// Thrown when a required parameter is null |
| | 277 | | /// </exception> |
| | 278 | | /// <exception cref="System.ArgumentNullException"> |
| | 279 | | /// Thrown when a required parameter is null |
| | 280 | | /// </exception> |
| | 281 | | /// <return> |
| | 282 | | /// A response object containing the response body and response headers. |
| | 283 | | /// </return> |
| | 284 | | public async Task<AzureOperationResponse<object,ManifestsCreateHeaders>> CreateWithHttpMessagesAsync(string name |
| | 285 | | { |
| 2 | 286 | | if (Client.LoginUri == null) |
| | 287 | | { |
| 0 | 288 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 289 | | } |
| 2 | 290 | | if (name == null) |
| | 291 | | { |
| 0 | 292 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 293 | | } |
| 2 | 294 | | if (reference == null) |
| | 295 | | { |
| 0 | 296 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 297 | | } |
| 2 | 298 | | if (payload == null) |
| | 299 | | { |
| 0 | 300 | | throw new ValidationException(ValidationRules.CannotBeNull, "payload"); |
| | 301 | | } |
| | 302 | | // Tracing |
| 2 | 303 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 304 | | string _invocationId = null; |
| 2 | 305 | | if (_shouldTrace) |
| | 306 | | { |
| 0 | 307 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 308 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 309 | | tracingParameters.Add("name", name); |
| 0 | 310 | | tracingParameters.Add("reference", reference); |
| 0 | 311 | | tracingParameters.Add("payload", payload); |
| 0 | 312 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 313 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 314 | | } |
| | 315 | | // Construct URL |
| 2 | 316 | | var _baseUrl = Client.BaseUri; |
| 2 | 317 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/manifests/{reference}"; |
| 2 | 318 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 319 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 320 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 2 | 321 | | List<string> _queryParameters = new List<string>(); |
| 2 | 322 | | if (_queryParameters.Count > 0) |
| | 323 | | { |
| 0 | 324 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 325 | | } |
| | 326 | | // Create HTTP transport objects |
| 2 | 327 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 328 | | HttpResponseMessage _httpResponse = null; |
| 2 | 329 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 2 | 330 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 331 | | // Set Headers |
| 2 | 332 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 333 | | { |
| 2 | 334 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 335 | | } |
| 2 | 336 | | if (Client.AcceptLanguage != null) |
| | 337 | | { |
| 2 | 338 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 339 | | { |
| 0 | 340 | | _httpRequest.Headers.Remove("accept-language"); |
| | 341 | | } |
| 2 | 342 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 343 | | } |
| | 344 | |
|
| | 345 | |
|
| 2 | 346 | | if (customHeaders != null) |
| | 347 | | { |
| 0 | 348 | | foreach(var _header in customHeaders) |
| | 349 | | { |
| 0 | 350 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 351 | | { |
| 0 | 352 | | _httpRequest.Headers.Remove(_header.Key); |
| | 353 | | } |
| 0 | 354 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 355 | | } |
| | 356 | | } |
| | 357 | |
|
| | 358 | | // Serialize Request |
| 2 | 359 | | string _requestContent = null; |
| 2 | 360 | | if(payload != null) |
| | 361 | | { |
| 2 | 362 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(payload, Client.SerializationSettin |
| 2 | 363 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 364 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 365 | | } |
| | 366 | | // Set Credentials |
| 2 | 367 | | if (Client.Credentials != null) |
| | 368 | | { |
| 2 | 369 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 370 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 371 | | } |
| | 372 | | // Send Request |
| 2 | 373 | | if (_shouldTrace) |
| | 374 | | { |
| 0 | 375 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 376 | | } |
| 2 | 377 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 378 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 379 | | if (_shouldTrace) |
| | 380 | | { |
| 0 | 381 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 382 | | } |
| 2 | 383 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 384 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 385 | | string _responseContent = null; |
| 2 | 386 | | if ((int)_statusCode != 201) |
| | 387 | | { |
| 0 | 388 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 389 | | try |
| | 390 | | { |
| 0 | 391 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 392 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 393 | | if (_errorBody != null) |
| | 394 | | { |
| 0 | 395 | | ex.Body = _errorBody; |
| | 396 | | } |
| 0 | 397 | | } |
| 0 | 398 | | catch (JsonException) |
| | 399 | | { |
| | 400 | | // Ignore the exception |
| 0 | 401 | | } |
| 0 | 402 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 403 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 404 | | if (_shouldTrace) |
| | 405 | | { |
| 0 | 406 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 407 | | } |
| 0 | 408 | | _httpRequest.Dispose(); |
| 0 | 409 | | if (_httpResponse != null) |
| | 410 | | { |
| 0 | 411 | | _httpResponse.Dispose(); |
| | 412 | | } |
| 0 | 413 | | throw ex; |
| | 414 | | } |
| | 415 | | // Create Result |
| 2 | 416 | | var _result = new AzureOperationResponse<object,ManifestsCreateHeaders>(); |
| 2 | 417 | | _result.Request = _httpRequest; |
| 2 | 418 | | _result.Response = _httpResponse; |
| 2 | 419 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 420 | | { |
| 2 | 421 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 422 | | } |
| | 423 | | // Deserialize Response |
| 2 | 424 | | if ((int)_statusCode == 201) |
| | 425 | | { |
| 2 | 426 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 427 | | try |
| | 428 | | { |
| 2 | 429 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<object>(_responseContent, Client |
| 2 | 430 | | } |
| 0 | 431 | | catch (JsonException ex) |
| | 432 | | { |
| 0 | 433 | | _httpRequest.Dispose(); |
| 0 | 434 | | if (_httpResponse != null) |
| | 435 | | { |
| 0 | 436 | | _httpResponse.Dispose(); |
| | 437 | | } |
| 0 | 438 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 439 | | } |
| | 440 | | } |
| | 441 | | try |
| | 442 | | { |
| 2 | 443 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ManifestsCreateHeaders>(JsonSerializer.Creat |
| 2 | 444 | | } |
| 0 | 445 | | catch (JsonException ex) |
| | 446 | | { |
| 0 | 447 | | _httpRequest.Dispose(); |
| 0 | 448 | | if (_httpResponse != null) |
| | 449 | | { |
| 0 | 450 | | _httpResponse.Dispose(); |
| | 451 | | } |
| 0 | 452 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 453 | | } |
| 2 | 454 | | if (_shouldTrace) |
| | 455 | | { |
| 0 | 456 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 457 | | } |
| 2 | 458 | | return _result; |
| 2 | 459 | | } |
| | 460 | |
|
| | 461 | | /// <summary> |
| | 462 | | /// Delete the manifest identified by `name` and `reference`. Note that a |
| | 463 | | /// manifest can _only_ be deleted by `digest`. |
| | 464 | | /// </summary> |
| | 465 | | /// <param name='name'> |
| | 466 | | /// Name of the image (including the namespace) |
| | 467 | | /// </param> |
| | 468 | | /// <param name='reference'> |
| | 469 | | /// A tag or a digest, pointing to a specific image |
| | 470 | | /// </param> |
| | 471 | | /// <param name='customHeaders'> |
| | 472 | | /// Headers that will be added to request. |
| | 473 | | /// </param> |
| | 474 | | /// <param name='cancellationToken'> |
| | 475 | | /// The cancellation token. |
| | 476 | | /// </param> |
| | 477 | | /// <exception cref="AcrErrorsException"> |
| | 478 | | /// Thrown when the operation returned an invalid status code |
| | 479 | | /// </exception> |
| | 480 | | /// <exception cref="ValidationException"> |
| | 481 | | /// Thrown when a required parameter is null |
| | 482 | | /// </exception> |
| | 483 | | /// <exception cref="System.ArgumentNullException"> |
| | 484 | | /// Thrown when a required parameter is null |
| | 485 | | /// </exception> |
| | 486 | | /// <return> |
| | 487 | | /// A response object containing the response body and response headers. |
| | 488 | | /// </return> |
| | 489 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string name, string reference, Dictionary< |
| | 490 | | { |
| 2 | 491 | | if (Client.LoginUri == null) |
| | 492 | | { |
| 0 | 493 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 494 | | } |
| 2 | 495 | | if (name == null) |
| | 496 | | { |
| 0 | 497 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 498 | | } |
| 2 | 499 | | if (reference == null) |
| | 500 | | { |
| 0 | 501 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 502 | | } |
| | 503 | | // Tracing |
| 2 | 504 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 505 | | string _invocationId = null; |
| 2 | 506 | | if (_shouldTrace) |
| | 507 | | { |
| 0 | 508 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 509 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 510 | | tracingParameters.Add("name", name); |
| 0 | 511 | | tracingParameters.Add("reference", reference); |
| 0 | 512 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 513 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 514 | | } |
| | 515 | | // Construct URL |
| 2 | 516 | | var _baseUrl = Client.BaseUri; |
| 2 | 517 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/manifests/{reference}"; |
| 2 | 518 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 519 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 520 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 2 | 521 | | List<string> _queryParameters = new List<string>(); |
| 2 | 522 | | if (_queryParameters.Count > 0) |
| | 523 | | { |
| 0 | 524 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 525 | | } |
| | 526 | | // Create HTTP transport objects |
| 2 | 527 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 528 | | HttpResponseMessage _httpResponse = null; |
| 2 | 529 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 530 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 531 | | // Set Headers |
| 2 | 532 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 533 | | { |
| 2 | 534 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 535 | | } |
| 2 | 536 | | if (Client.AcceptLanguage != null) |
| | 537 | | { |
| 2 | 538 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 539 | | { |
| 0 | 540 | | _httpRequest.Headers.Remove("accept-language"); |
| | 541 | | } |
| 2 | 542 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 543 | | } |
| | 544 | |
|
| | 545 | |
|
| 2 | 546 | | if (customHeaders != null) |
| | 547 | | { |
| 0 | 548 | | foreach(var _header in customHeaders) |
| | 549 | | { |
| 0 | 550 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 551 | | { |
| 0 | 552 | | _httpRequest.Headers.Remove(_header.Key); |
| | 553 | | } |
| 0 | 554 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 555 | | } |
| | 556 | | } |
| | 557 | |
|
| | 558 | | // Serialize Request |
| 2 | 559 | | string _requestContent = null; |
| | 560 | | // Set Credentials |
| 2 | 561 | | if (Client.Credentials != null) |
| | 562 | | { |
| 2 | 563 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 564 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 565 | | } |
| | 566 | | // Send Request |
| 2 | 567 | | if (_shouldTrace) |
| | 568 | | { |
| 0 | 569 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 570 | | } |
| 2 | 571 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 572 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 573 | | if (_shouldTrace) |
| | 574 | | { |
| 0 | 575 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 576 | | } |
| 2 | 577 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 578 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 579 | | string _responseContent = null; |
| 2 | 580 | | if ((int)_statusCode != 202) |
| | 581 | | { |
| 0 | 582 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 583 | | try |
| | 584 | | { |
| 0 | 585 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 586 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 587 | | if (_errorBody != null) |
| | 588 | | { |
| 0 | 589 | | ex.Body = _errorBody; |
| | 590 | | } |
| 0 | 591 | | } |
| 0 | 592 | | catch (JsonException) |
| | 593 | | { |
| | 594 | | // Ignore the exception |
| 0 | 595 | | } |
| 0 | 596 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 597 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 598 | | if (_shouldTrace) |
| | 599 | | { |
| 0 | 600 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 601 | | } |
| 0 | 602 | | _httpRequest.Dispose(); |
| 0 | 603 | | if (_httpResponse != null) |
| | 604 | | { |
| 0 | 605 | | _httpResponse.Dispose(); |
| | 606 | | } |
| 0 | 607 | | throw ex; |
| | 608 | | } |
| | 609 | | // Create Result |
| 2 | 610 | | var _result = new AzureOperationResponse(); |
| 2 | 611 | | _result.Request = _httpRequest; |
| 2 | 612 | | _result.Response = _httpResponse; |
| 2 | 613 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 614 | | { |
| 2 | 615 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 616 | | } |
| 2 | 617 | | if (_shouldTrace) |
| | 618 | | { |
| 0 | 619 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 620 | | } |
| 2 | 621 | | return _result; |
| 2 | 622 | | } |
| | 623 | |
|
| | 624 | | /// <summary> |
| | 625 | | /// List manifests of a repository |
| | 626 | | /// </summary> |
| | 627 | | /// <param name='name'> |
| | 628 | | /// Name of the image (including the namespace) |
| | 629 | | /// </param> |
| | 630 | | /// <param name='last'> |
| | 631 | | /// Query parameter for the last item in previous query. Result set will |
| | 632 | | /// include values lexically after last. |
| | 633 | | /// </param> |
| | 634 | | /// <param name='n'> |
| | 635 | | /// query parameter for max number of items |
| | 636 | | /// </param> |
| | 637 | | /// <param name='orderby'> |
| | 638 | | /// orderby query parameter |
| | 639 | | /// </param> |
| | 640 | | /// <param name='customHeaders'> |
| | 641 | | /// Headers that will be added to request. |
| | 642 | | /// </param> |
| | 643 | | /// <param name='cancellationToken'> |
| | 644 | | /// The cancellation token. |
| | 645 | | /// </param> |
| | 646 | | /// <exception cref="AcrErrorsException"> |
| | 647 | | /// Thrown when the operation returned an invalid status code |
| | 648 | | /// </exception> |
| | 649 | | /// <exception cref="SerializationException"> |
| | 650 | | /// Thrown when unable to deserialize the response |
| | 651 | | /// </exception> |
| | 652 | | /// <exception cref="ValidationException"> |
| | 653 | | /// Thrown when a required parameter is null |
| | 654 | | /// </exception> |
| | 655 | | /// <exception cref="System.ArgumentNullException"> |
| | 656 | | /// Thrown when a required parameter is null |
| | 657 | | /// </exception> |
| | 658 | | /// <return> |
| | 659 | | /// A response object containing the response body and response headers. |
| | 660 | | /// </return> |
| | 661 | | public async Task<AzureOperationResponse<AcrManifests>> GetListWithHttpMessagesAsync(string name, string last = |
| | 662 | | { |
| 2 | 663 | | if (Client.LoginUri == null) |
| | 664 | | { |
| 0 | 665 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 666 | | } |
| 2 | 667 | | if (name == null) |
| | 668 | | { |
| 0 | 669 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 670 | | } |
| | 671 | | // Tracing |
| 2 | 672 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 673 | | string _invocationId = null; |
| 2 | 674 | | if (_shouldTrace) |
| | 675 | | { |
| 0 | 676 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 677 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 678 | | tracingParameters.Add("name", name); |
| 0 | 679 | | tracingParameters.Add("last", last); |
| 0 | 680 | | tracingParameters.Add("n", n); |
| 0 | 681 | | tracingParameters.Add("orderby", orderby); |
| 0 | 682 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 683 | | ServiceClientTracing.Enter(_invocationId, this, "GetList", tracingParameters); |
| | 684 | | } |
| | 685 | | // Construct URL |
| 2 | 686 | | var _baseUrl = Client.BaseUri; |
| 2 | 687 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_manifests"; |
| 2 | 688 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 689 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 690 | | List<string> _queryParameters = new List<string>(); |
| 2 | 691 | | if (last != null) |
| | 692 | | { |
| 0 | 693 | | _queryParameters.Add(string.Format("last={0}", System.Uri.EscapeDataString(last))); |
| | 694 | | } |
| 2 | 695 | | if (n != null) |
| | 696 | | { |
| 0 | 697 | | _queryParameters.Add(string.Format("n={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConve |
| | 698 | | } |
| 2 | 699 | | if (orderby != null) |
| | 700 | | { |
| 0 | 701 | | _queryParameters.Add(string.Format("orderby={0}", System.Uri.EscapeDataString(orderby))); |
| | 702 | | } |
| 2 | 703 | | if (_queryParameters.Count > 0) |
| | 704 | | { |
| 0 | 705 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 706 | | } |
| | 707 | | // Create HTTP transport objects |
| 2 | 708 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 709 | | HttpResponseMessage _httpResponse = null; |
| 2 | 710 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 711 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 712 | | // Set Headers |
| 2 | 713 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 714 | | { |
| 2 | 715 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 716 | | } |
| 2 | 717 | | if (Client.AcceptLanguage != null) |
| | 718 | | { |
| 2 | 719 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 720 | | { |
| 0 | 721 | | _httpRequest.Headers.Remove("accept-language"); |
| | 722 | | } |
| 2 | 723 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 724 | | } |
| | 725 | |
|
| | 726 | |
|
| 2 | 727 | | if (customHeaders != null) |
| | 728 | | { |
| 0 | 729 | | foreach(var _header in customHeaders) |
| | 730 | | { |
| 0 | 731 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 732 | | { |
| 0 | 733 | | _httpRequest.Headers.Remove(_header.Key); |
| | 734 | | } |
| 0 | 735 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 736 | | } |
| | 737 | | } |
| | 738 | |
|
| | 739 | | // Serialize Request |
| 2 | 740 | | string _requestContent = null; |
| | 741 | | // Set Credentials |
| 2 | 742 | | if (Client.Credentials != null) |
| | 743 | | { |
| 2 | 744 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 745 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 746 | | } |
| | 747 | | // Send Request |
| 2 | 748 | | if (_shouldTrace) |
| | 749 | | { |
| 0 | 750 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 751 | | } |
| 2 | 752 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 753 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 754 | | if (_shouldTrace) |
| | 755 | | { |
| 0 | 756 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 757 | | } |
| 2 | 758 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 759 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 760 | | string _responseContent = null; |
| 2 | 761 | | if ((int)_statusCode != 200) |
| | 762 | | { |
| 0 | 763 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 764 | | try |
| | 765 | | { |
| 0 | 766 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 767 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 768 | | if (_errorBody != null) |
| | 769 | | { |
| 0 | 770 | | ex.Body = _errorBody; |
| | 771 | | } |
| 0 | 772 | | } |
| 0 | 773 | | catch (JsonException) |
| | 774 | | { |
| | 775 | | // Ignore the exception |
| 0 | 776 | | } |
| 0 | 777 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 778 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 779 | | if (_shouldTrace) |
| | 780 | | { |
| 0 | 781 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 782 | | } |
| 0 | 783 | | _httpRequest.Dispose(); |
| 0 | 784 | | if (_httpResponse != null) |
| | 785 | | { |
| 0 | 786 | | _httpResponse.Dispose(); |
| | 787 | | } |
| 0 | 788 | | throw ex; |
| | 789 | | } |
| | 790 | | // Create Result |
| 2 | 791 | | var _result = new AzureOperationResponse<AcrManifests>(); |
| 2 | 792 | | _result.Request = _httpRequest; |
| 2 | 793 | | _result.Response = _httpResponse; |
| 2 | 794 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 795 | | { |
| 0 | 796 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 797 | | } |
| | 798 | | // Deserialize Response |
| 2 | 799 | | if ((int)_statusCode == 200) |
| | 800 | | { |
| 2 | 801 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 802 | | try |
| | 803 | | { |
| 2 | 804 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrManifests>(_responseContent, |
| 2 | 805 | | } |
| 0 | 806 | | catch (JsonException ex) |
| | 807 | | { |
| 0 | 808 | | _httpRequest.Dispose(); |
| 0 | 809 | | if (_httpResponse != null) |
| | 810 | | { |
| 0 | 811 | | _httpResponse.Dispose(); |
| | 812 | | } |
| 0 | 813 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 814 | | } |
| | 815 | | } |
| 2 | 816 | | if (_shouldTrace) |
| | 817 | | { |
| 0 | 818 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 819 | | } |
| 2 | 820 | | return _result; |
| 2 | 821 | | } |
| | 822 | |
|
| | 823 | | /// <summary> |
| | 824 | | /// Get manifest attributes |
| | 825 | | /// </summary> |
| | 826 | | /// <param name='name'> |
| | 827 | | /// Name of the image (including the namespace) |
| | 828 | | /// </param> |
| | 829 | | /// <param name='reference'> |
| | 830 | | /// A tag or a digest, pointing to a specific image |
| | 831 | | /// </param> |
| | 832 | | /// <param name='customHeaders'> |
| | 833 | | /// Headers that will be added to request. |
| | 834 | | /// </param> |
| | 835 | | /// <param name='cancellationToken'> |
| | 836 | | /// The cancellation token. |
| | 837 | | /// </param> |
| | 838 | | /// <exception cref="AcrErrorsException"> |
| | 839 | | /// Thrown when the operation returned an invalid status code |
| | 840 | | /// </exception> |
| | 841 | | /// <exception cref="SerializationException"> |
| | 842 | | /// Thrown when unable to deserialize the response |
| | 843 | | /// </exception> |
| | 844 | | /// <exception cref="ValidationException"> |
| | 845 | | /// Thrown when a required parameter is null |
| | 846 | | /// </exception> |
| | 847 | | /// <exception cref="System.ArgumentNullException"> |
| | 848 | | /// Thrown when a required parameter is null |
| | 849 | | /// </exception> |
| | 850 | | /// <return> |
| | 851 | | /// A response object containing the response body and response headers. |
| | 852 | | /// </return> |
| | 853 | | public async Task<AzureOperationResponse<ManifestAttributes>> GetAttributesWithHttpMessagesAsync(string name, st |
| | 854 | | { |
| 6 | 855 | | if (Client.LoginUri == null) |
| | 856 | | { |
| 0 | 857 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 858 | | } |
| 6 | 859 | | if (name == null) |
| | 860 | | { |
| 0 | 861 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 862 | | } |
| 6 | 863 | | if (reference == null) |
| | 864 | | { |
| 0 | 865 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 866 | | } |
| | 867 | | // Tracing |
| 6 | 868 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 869 | | string _invocationId = null; |
| 6 | 870 | | if (_shouldTrace) |
| | 871 | | { |
| 0 | 872 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 873 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 874 | | tracingParameters.Add("name", name); |
| 0 | 875 | | tracingParameters.Add("reference", reference); |
| 0 | 876 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 877 | | ServiceClientTracing.Enter(_invocationId, this, "GetAttributes", tracingParameters); |
| | 878 | | } |
| | 879 | | // Construct URL |
| 6 | 880 | | var _baseUrl = Client.BaseUri; |
| 6 | 881 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_manifests/{reference}"; |
| 6 | 882 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 6 | 883 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 6 | 884 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 6 | 885 | | List<string> _queryParameters = new List<string>(); |
| 6 | 886 | | if (_queryParameters.Count > 0) |
| | 887 | | { |
| 0 | 888 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 889 | | } |
| | 890 | | // Create HTTP transport objects |
| 6 | 891 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 892 | | HttpResponseMessage _httpResponse = null; |
| 6 | 893 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 894 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 895 | | // Set Headers |
| 6 | 896 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 897 | | { |
| 6 | 898 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 899 | | } |
| 6 | 900 | | if (Client.AcceptLanguage != null) |
| | 901 | | { |
| 6 | 902 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 903 | | { |
| 0 | 904 | | _httpRequest.Headers.Remove("accept-language"); |
| | 905 | | } |
| 6 | 906 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 907 | | } |
| | 908 | |
|
| | 909 | |
|
| 6 | 910 | | if (customHeaders != null) |
| | 911 | | { |
| 0 | 912 | | foreach(var _header in customHeaders) |
| | 913 | | { |
| 0 | 914 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 915 | | { |
| 0 | 916 | | _httpRequest.Headers.Remove(_header.Key); |
| | 917 | | } |
| 0 | 918 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 919 | | } |
| | 920 | | } |
| | 921 | |
|
| | 922 | | // Serialize Request |
| 6 | 923 | | string _requestContent = null; |
| | 924 | | // Set Credentials |
| 6 | 925 | | if (Client.Credentials != null) |
| | 926 | | { |
| 6 | 927 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 928 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 929 | | } |
| | 930 | | // Send Request |
| 6 | 931 | | if (_shouldTrace) |
| | 932 | | { |
| 0 | 933 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 934 | | } |
| 6 | 935 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 936 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 937 | | if (_shouldTrace) |
| | 938 | | { |
| 0 | 939 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 940 | | } |
| 6 | 941 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 942 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 943 | | string _responseContent = null; |
| 6 | 944 | | if ((int)_statusCode != 200) |
| | 945 | | { |
| 0 | 946 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 947 | | try |
| | 948 | | { |
| 0 | 949 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 950 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 951 | | if (_errorBody != null) |
| | 952 | | { |
| 0 | 953 | | ex.Body = _errorBody; |
| | 954 | | } |
| 0 | 955 | | } |
| 0 | 956 | | catch (JsonException) |
| | 957 | | { |
| | 958 | | // Ignore the exception |
| 0 | 959 | | } |
| 0 | 960 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 961 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 962 | | if (_shouldTrace) |
| | 963 | | { |
| 0 | 964 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 965 | | } |
| 0 | 966 | | _httpRequest.Dispose(); |
| 0 | 967 | | if (_httpResponse != null) |
| | 968 | | { |
| 0 | 969 | | _httpResponse.Dispose(); |
| | 970 | | } |
| 0 | 971 | | throw ex; |
| | 972 | | } |
| | 973 | | // Create Result |
| 6 | 974 | | var _result = new AzureOperationResponse<ManifestAttributes>(); |
| 6 | 975 | | _result.Request = _httpRequest; |
| 6 | 976 | | _result.Response = _httpResponse; |
| 6 | 977 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 978 | | { |
| 0 | 979 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 980 | | } |
| | 981 | | // Deserialize Response |
| 6 | 982 | | if ((int)_statusCode == 200) |
| | 983 | | { |
| 6 | 984 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 985 | | try |
| | 986 | | { |
| 6 | 987 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ManifestAttributes>(_responseCon |
| 6 | 988 | | } |
| 0 | 989 | | catch (JsonException ex) |
| | 990 | | { |
| 0 | 991 | | _httpRequest.Dispose(); |
| 0 | 992 | | if (_httpResponse != null) |
| | 993 | | { |
| 0 | 994 | | _httpResponse.Dispose(); |
| | 995 | | } |
| 0 | 996 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 997 | | } |
| | 998 | | } |
| 6 | 999 | | if (_shouldTrace) |
| | 1000 | | { |
| 0 | 1001 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1002 | | } |
| 6 | 1003 | | return _result; |
| 6 | 1004 | | } |
| | 1005 | |
|
| | 1006 | | /// <summary> |
| | 1007 | | /// Update attributes of a manifest |
| | 1008 | | /// </summary> |
| | 1009 | | /// <param name='name'> |
| | 1010 | | /// Name of the image (including the namespace) |
| | 1011 | | /// </param> |
| | 1012 | | /// <param name='reference'> |
| | 1013 | | /// A tag or a digest, pointing to a specific image |
| | 1014 | | /// </param> |
| | 1015 | | /// <param name='value'> |
| | 1016 | | /// Repository attribute value |
| | 1017 | | /// </param> |
| | 1018 | | /// <param name='customHeaders'> |
| | 1019 | | /// Headers that will be added to request. |
| | 1020 | | /// </param> |
| | 1021 | | /// <param name='cancellationToken'> |
| | 1022 | | /// The cancellation token. |
| | 1023 | | /// </param> |
| | 1024 | | /// <exception cref="AcrErrorsException"> |
| | 1025 | | /// Thrown when the operation returned an invalid status code |
| | 1026 | | /// </exception> |
| | 1027 | | /// <exception cref="ValidationException"> |
| | 1028 | | /// Thrown when a required parameter is null |
| | 1029 | | /// </exception> |
| | 1030 | | /// <exception cref="System.ArgumentNullException"> |
| | 1031 | | /// Thrown when a required parameter is null |
| | 1032 | | /// </exception> |
| | 1033 | | /// <return> |
| | 1034 | | /// A response object containing the response body and response headers. |
| | 1035 | | /// </return> |
| | 1036 | | public async Task<AzureOperationResponse> UpdateAttributesWithHttpMessagesAsync(string name, string reference, C |
| | 1037 | | { |
| 4 | 1038 | | if (Client.LoginUri == null) |
| | 1039 | | { |
| 0 | 1040 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1041 | | } |
| 4 | 1042 | | if (name == null) |
| | 1043 | | { |
| 0 | 1044 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 1045 | | } |
| 4 | 1046 | | if (reference == null) |
| | 1047 | | { |
| 0 | 1048 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 1049 | | } |
| | 1050 | | // Tracing |
| 4 | 1051 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1052 | | string _invocationId = null; |
| 4 | 1053 | | if (_shouldTrace) |
| | 1054 | | { |
| 0 | 1055 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1056 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1057 | | tracingParameters.Add("name", name); |
| 0 | 1058 | | tracingParameters.Add("reference", reference); |
| 0 | 1059 | | tracingParameters.Add("value", value); |
| 0 | 1060 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1061 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateAttributes", tracingParameters); |
| | 1062 | | } |
| | 1063 | | // Construct URL |
| 4 | 1064 | | var _baseUrl = Client.BaseUri; |
| 4 | 1065 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_manifests/{reference}"; |
| 4 | 1066 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 1067 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 4 | 1068 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 4 | 1069 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1070 | | if (_queryParameters.Count > 0) |
| | 1071 | | { |
| 0 | 1072 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1073 | | } |
| | 1074 | | // Create HTTP transport objects |
| 4 | 1075 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1076 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1077 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 4 | 1078 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1079 | | // Set Headers |
| 4 | 1080 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1081 | | { |
| 4 | 1082 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1083 | | } |
| 4 | 1084 | | if (Client.AcceptLanguage != null) |
| | 1085 | | { |
| 4 | 1086 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1087 | | { |
| 0 | 1088 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1089 | | } |
| 4 | 1090 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1091 | | } |
| | 1092 | |
|
| | 1093 | |
|
| 4 | 1094 | | if (customHeaders != null) |
| | 1095 | | { |
| 0 | 1096 | | foreach(var _header in customHeaders) |
| | 1097 | | { |
| 0 | 1098 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1099 | | { |
| 0 | 1100 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1101 | | } |
| 0 | 1102 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1103 | | } |
| | 1104 | | } |
| | 1105 | |
|
| | 1106 | | // Serialize Request |
| 4 | 1107 | | string _requestContent = null; |
| 4 | 1108 | | if(value != null) |
| | 1109 | | { |
| 4 | 1110 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(value, Client.SerializationSettings |
| 4 | 1111 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 1112 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1113 | | } |
| | 1114 | | // Set Credentials |
| 4 | 1115 | | if (Client.Credentials != null) |
| | 1116 | | { |
| 4 | 1117 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1118 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1119 | | } |
| | 1120 | | // Send Request |
| 4 | 1121 | | if (_shouldTrace) |
| | 1122 | | { |
| 0 | 1123 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1124 | | } |
| 4 | 1125 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1126 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1127 | | if (_shouldTrace) |
| | 1128 | | { |
| 0 | 1129 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1130 | | } |
| 4 | 1131 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1132 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1133 | | string _responseContent = null; |
| 4 | 1134 | | if ((int)_statusCode != 200) |
| | 1135 | | { |
| 0 | 1136 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 1137 | | try |
| | 1138 | | { |
| 0 | 1139 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1140 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 1141 | | if (_errorBody != null) |
| | 1142 | | { |
| 0 | 1143 | | ex.Body = _errorBody; |
| | 1144 | | } |
| 0 | 1145 | | } |
| 0 | 1146 | | catch (JsonException) |
| | 1147 | | { |
| | 1148 | | // Ignore the exception |
| 0 | 1149 | | } |
| 0 | 1150 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1151 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1152 | | if (_shouldTrace) |
| | 1153 | | { |
| 0 | 1154 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1155 | | } |
| 0 | 1156 | | _httpRequest.Dispose(); |
| 0 | 1157 | | if (_httpResponse != null) |
| | 1158 | | { |
| 0 | 1159 | | _httpResponse.Dispose(); |
| | 1160 | | } |
| 0 | 1161 | | throw ex; |
| | 1162 | | } |
| | 1163 | | // Create Result |
| 4 | 1164 | | var _result = new AzureOperationResponse(); |
| 4 | 1165 | | _result.Request = _httpRequest; |
| 4 | 1166 | | _result.Response = _httpResponse; |
| 4 | 1167 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1168 | | { |
| 0 | 1169 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1170 | | } |
| 4 | 1171 | | if (_shouldTrace) |
| | 1172 | | { |
| 0 | 1173 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1174 | | } |
| 4 | 1175 | | return _result; |
| 4 | 1176 | | } |
| | 1177 | |
|
| | 1178 | | } |
| | 1179 | | } |