| | 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 | | /// TagOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class TagOperations : IServiceOperations<AzureContainerRegistryClient>, ITagOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the TagOperations 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 TagOperations(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> |
| 300 | 51 | | public AzureContainerRegistryClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// List tags of a repository |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='name'> |
| | 57 | | /// Name of the image (including the namespace) |
| | 58 | | /// </param> |
| | 59 | | /// <param name='last'> |
| | 60 | | /// Query parameter for the last item in previous query. Result set will |
| | 61 | | /// include values lexically after last. |
| | 62 | | /// </param> |
| | 63 | | /// <param name='n'> |
| | 64 | | /// query parameter for max number of items |
| | 65 | | /// </param> |
| | 66 | | /// <param name='orderby'> |
| | 67 | | /// orderby query parameter |
| | 68 | | /// </param> |
| | 69 | | /// <param name='digest'> |
| | 70 | | /// filter by digest |
| | 71 | | /// </param> |
| | 72 | | /// <param name='customHeaders'> |
| | 73 | | /// Headers that will be added to request. |
| | 74 | | /// </param> |
| | 75 | | /// <param name='cancellationToken'> |
| | 76 | | /// The cancellation token. |
| | 77 | | /// </param> |
| | 78 | | /// <exception cref="AcrErrorsException"> |
| | 79 | | /// Thrown when the operation returned an invalid status code |
| | 80 | | /// </exception> |
| | 81 | | /// <exception cref="SerializationException"> |
| | 82 | | /// Thrown when unable to deserialize the response |
| | 83 | | /// </exception> |
| | 84 | | /// <exception cref="ValidationException"> |
| | 85 | | /// Thrown when a required parameter is null |
| | 86 | | /// </exception> |
| | 87 | | /// <exception cref="System.ArgumentNullException"> |
| | 88 | | /// Thrown when a required parameter is null |
| | 89 | | /// </exception> |
| | 90 | | /// <return> |
| | 91 | | /// A response object containing the response body and response headers. |
| | 92 | | /// </return> |
| | 93 | | public async Task<AzureOperationResponse<TagList>> GetListWithHttpMessagesAsync(string name, string last = defau |
| | 94 | | { |
| 8 | 95 | | if (Client.LoginUri == null) |
| | 96 | | { |
| 0 | 97 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 98 | | } |
| 8 | 99 | | if (name == null) |
| | 100 | | { |
| 0 | 101 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 102 | | } |
| | 103 | | // Tracing |
| 8 | 104 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 105 | | string _invocationId = null; |
| 8 | 106 | | if (_shouldTrace) |
| | 107 | | { |
| 0 | 108 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 109 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 110 | | tracingParameters.Add("name", name); |
| 0 | 111 | | tracingParameters.Add("last", last); |
| 0 | 112 | | tracingParameters.Add("n", n); |
| 0 | 113 | | tracingParameters.Add("orderby", orderby); |
| 0 | 114 | | tracingParameters.Add("digest", digest); |
| 0 | 115 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 116 | | ServiceClientTracing.Enter(_invocationId, this, "GetList", tracingParameters); |
| | 117 | | } |
| | 118 | | // Construct URL |
| 8 | 119 | | var _baseUrl = Client.BaseUri; |
| 8 | 120 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_tags"; |
| 8 | 121 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 8 | 122 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 8 | 123 | | List<string> _queryParameters = new List<string>(); |
| 8 | 124 | | if (last != null) |
| | 125 | | { |
| 0 | 126 | | _queryParameters.Add(string.Format("last={0}", System.Uri.EscapeDataString(last))); |
| | 127 | | } |
| 8 | 128 | | if (n != null) |
| | 129 | | { |
| 0 | 130 | | _queryParameters.Add(string.Format("n={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConve |
| | 131 | | } |
| 8 | 132 | | if (orderby != null) |
| | 133 | | { |
| 0 | 134 | | _queryParameters.Add(string.Format("orderby={0}", System.Uri.EscapeDataString(orderby))); |
| | 135 | | } |
| 8 | 136 | | if (digest != null) |
| | 137 | | { |
| 0 | 138 | | _queryParameters.Add(string.Format("digest={0}", System.Uri.EscapeDataString(digest))); |
| | 139 | | } |
| 8 | 140 | | if (_queryParameters.Count > 0) |
| | 141 | | { |
| 0 | 142 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 143 | | } |
| | 144 | | // Create HTTP transport objects |
| 8 | 145 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 146 | | HttpResponseMessage _httpResponse = null; |
| 8 | 147 | | _httpRequest.Method = new HttpMethod("GET"); |
| 8 | 148 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 149 | | // Set Headers |
| 8 | 150 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 151 | | { |
| 8 | 152 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 153 | | } |
| 8 | 154 | | if (Client.AcceptLanguage != null) |
| | 155 | | { |
| 8 | 156 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 157 | | { |
| 0 | 158 | | _httpRequest.Headers.Remove("accept-language"); |
| | 159 | | } |
| 8 | 160 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 161 | | } |
| | 162 | |
|
| | 163 | |
|
| 8 | 164 | | if (customHeaders != null) |
| | 165 | | { |
| 0 | 166 | | foreach(var _header in customHeaders) |
| | 167 | | { |
| 0 | 168 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 169 | | { |
| 0 | 170 | | _httpRequest.Headers.Remove(_header.Key); |
| | 171 | | } |
| 0 | 172 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 173 | | } |
| | 174 | | } |
| | 175 | |
|
| | 176 | | // Serialize Request |
| 8 | 177 | | string _requestContent = null; |
| | 178 | | // Set Credentials |
| 8 | 179 | | if (Client.Credentials != null) |
| | 180 | | { |
| 8 | 181 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 182 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 183 | | } |
| | 184 | | // Send Request |
| 8 | 185 | | if (_shouldTrace) |
| | 186 | | { |
| 0 | 187 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 188 | | } |
| 8 | 189 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 190 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 191 | | if (_shouldTrace) |
| | 192 | | { |
| 0 | 193 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 194 | | } |
| 8 | 195 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 196 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 197 | | string _responseContent = null; |
| 8 | 198 | | if ((int)_statusCode != 200) |
| | 199 | | { |
| 0 | 200 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 201 | | try |
| | 202 | | { |
| 0 | 203 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 204 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 205 | | if (_errorBody != null) |
| | 206 | | { |
| 0 | 207 | | ex.Body = _errorBody; |
| | 208 | | } |
| 0 | 209 | | } |
| 0 | 210 | | catch (JsonException) |
| | 211 | | { |
| | 212 | | // Ignore the exception |
| 0 | 213 | | } |
| 0 | 214 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 215 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 216 | | if (_shouldTrace) |
| | 217 | | { |
| 0 | 218 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 219 | | } |
| 0 | 220 | | _httpRequest.Dispose(); |
| 0 | 221 | | if (_httpResponse != null) |
| | 222 | | { |
| 0 | 223 | | _httpResponse.Dispose(); |
| | 224 | | } |
| 0 | 225 | | throw ex; |
| | 226 | | } |
| | 227 | | // Create Result |
| 8 | 228 | | var _result = new AzureOperationResponse<TagList>(); |
| 8 | 229 | | _result.Request = _httpRequest; |
| 8 | 230 | | _result.Response = _httpResponse; |
| 8 | 231 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 232 | | { |
| 0 | 233 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 234 | | } |
| | 235 | | // Deserialize Response |
| 8 | 236 | | if ((int)_statusCode == 200) |
| | 237 | | { |
| 8 | 238 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 239 | | try |
| | 240 | | { |
| 8 | 241 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TagList>(_responseContent, Clien |
| 8 | 242 | | } |
| 0 | 243 | | catch (JsonException ex) |
| | 244 | | { |
| 0 | 245 | | _httpRequest.Dispose(); |
| 0 | 246 | | if (_httpResponse != null) |
| | 247 | | { |
| 0 | 248 | | _httpResponse.Dispose(); |
| | 249 | | } |
| 0 | 250 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 251 | | } |
| | 252 | | } |
| 8 | 253 | | if (_shouldTrace) |
| | 254 | | { |
| 0 | 255 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 256 | | } |
| 8 | 257 | | return _result; |
| 8 | 258 | | } |
| | 259 | |
|
| | 260 | | /// <summary> |
| | 261 | | /// Get tag attributes by tag |
| | 262 | | /// </summary> |
| | 263 | | /// <param name='name'> |
| | 264 | | /// Name of the image (including the namespace) |
| | 265 | | /// </param> |
| | 266 | | /// <param name='reference'> |
| | 267 | | /// Tag name |
| | 268 | | /// </param> |
| | 269 | | /// <param name='customHeaders'> |
| | 270 | | /// Headers that will be added to request. |
| | 271 | | /// </param> |
| | 272 | | /// <param name='cancellationToken'> |
| | 273 | | /// The cancellation token. |
| | 274 | | /// </param> |
| | 275 | | /// <exception cref="AcrErrorsException"> |
| | 276 | | /// Thrown when the operation returned an invalid status code |
| | 277 | | /// </exception> |
| | 278 | | /// <exception cref="SerializationException"> |
| | 279 | | /// Thrown when unable to deserialize the response |
| | 280 | | /// </exception> |
| | 281 | | /// <exception cref="ValidationException"> |
| | 282 | | /// Thrown when a required parameter is null |
| | 283 | | /// </exception> |
| | 284 | | /// <exception cref="System.ArgumentNullException"> |
| | 285 | | /// Thrown when a required parameter is null |
| | 286 | | /// </exception> |
| | 287 | | /// <return> |
| | 288 | | /// A response object containing the response body and response headers. |
| | 289 | | /// </return> |
| | 290 | | public async Task<AzureOperationResponse<TagAttributes>> GetAttributesWithHttpMessagesAsync(string name, string |
| | 291 | | { |
| 8 | 292 | | if (Client.LoginUri == null) |
| | 293 | | { |
| 0 | 294 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 295 | | } |
| 8 | 296 | | if (name == null) |
| | 297 | | { |
| 0 | 298 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 299 | | } |
| 8 | 300 | | if (reference == null) |
| | 301 | | { |
| 0 | 302 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 303 | | } |
| | 304 | | // Tracing |
| 8 | 305 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 306 | | string _invocationId = null; |
| 8 | 307 | | if (_shouldTrace) |
| | 308 | | { |
| 0 | 309 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 310 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 311 | | tracingParameters.Add("name", name); |
| 0 | 312 | | tracingParameters.Add("reference", reference); |
| 0 | 313 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 314 | | ServiceClientTracing.Enter(_invocationId, this, "GetAttributes", tracingParameters); |
| | 315 | | } |
| | 316 | | // Construct URL |
| 8 | 317 | | var _baseUrl = Client.BaseUri; |
| 8 | 318 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_tags/{reference}"; |
| 8 | 319 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 8 | 320 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 8 | 321 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 8 | 322 | | List<string> _queryParameters = new List<string>(); |
| 8 | 323 | | if (_queryParameters.Count > 0) |
| | 324 | | { |
| 0 | 325 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 326 | | } |
| | 327 | | // Create HTTP transport objects |
| 8 | 328 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 329 | | HttpResponseMessage _httpResponse = null; |
| 8 | 330 | | _httpRequest.Method = new HttpMethod("GET"); |
| 8 | 331 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 332 | | // Set Headers |
| 8 | 333 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 334 | | { |
| 8 | 335 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 336 | | } |
| 8 | 337 | | if (Client.AcceptLanguage != null) |
| | 338 | | { |
| 8 | 339 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 340 | | { |
| 0 | 341 | | _httpRequest.Headers.Remove("accept-language"); |
| | 342 | | } |
| 8 | 343 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 344 | | } |
| | 345 | |
|
| | 346 | |
|
| 8 | 347 | | if (customHeaders != null) |
| | 348 | | { |
| 0 | 349 | | foreach(var _header in customHeaders) |
| | 350 | | { |
| 0 | 351 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 352 | | { |
| 0 | 353 | | _httpRequest.Headers.Remove(_header.Key); |
| | 354 | | } |
| 0 | 355 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 356 | | } |
| | 357 | | } |
| | 358 | |
|
| | 359 | | // Serialize Request |
| 8 | 360 | | string _requestContent = null; |
| | 361 | | // Set Credentials |
| 8 | 362 | | if (Client.Credentials != null) |
| | 363 | | { |
| 8 | 364 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 365 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 366 | | } |
| | 367 | | // Send Request |
| 8 | 368 | | if (_shouldTrace) |
| | 369 | | { |
| 0 | 370 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 371 | | } |
| 8 | 372 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 373 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 374 | | if (_shouldTrace) |
| | 375 | | { |
| 0 | 376 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 377 | | } |
| 8 | 378 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 379 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 380 | | string _responseContent = null; |
| 8 | 381 | | if ((int)_statusCode != 200) |
| | 382 | | { |
| 0 | 383 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 384 | | try |
| | 385 | | { |
| 0 | 386 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 387 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 388 | | if (_errorBody != null) |
| | 389 | | { |
| 0 | 390 | | ex.Body = _errorBody; |
| | 391 | | } |
| 0 | 392 | | } |
| 0 | 393 | | catch (JsonException) |
| | 394 | | { |
| | 395 | | // Ignore the exception |
| 0 | 396 | | } |
| 0 | 397 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 398 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 399 | | if (_shouldTrace) |
| | 400 | | { |
| 0 | 401 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 402 | | } |
| 0 | 403 | | _httpRequest.Dispose(); |
| 0 | 404 | | if (_httpResponse != null) |
| | 405 | | { |
| 0 | 406 | | _httpResponse.Dispose(); |
| | 407 | | } |
| 0 | 408 | | throw ex; |
| | 409 | | } |
| | 410 | | // Create Result |
| 8 | 411 | | var _result = new AzureOperationResponse<TagAttributes>(); |
| 8 | 412 | | _result.Request = _httpRequest; |
| 8 | 413 | | _result.Response = _httpResponse; |
| 8 | 414 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 415 | | { |
| 0 | 416 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 417 | | } |
| | 418 | | // Deserialize Response |
| 8 | 419 | | if ((int)_statusCode == 200) |
| | 420 | | { |
| 8 | 421 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 422 | | try |
| | 423 | | { |
| 8 | 424 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TagAttributes>(_responseContent, |
| 8 | 425 | | } |
| 0 | 426 | | catch (JsonException ex) |
| | 427 | | { |
| 0 | 428 | | _httpRequest.Dispose(); |
| 0 | 429 | | if (_httpResponse != null) |
| | 430 | | { |
| 0 | 431 | | _httpResponse.Dispose(); |
| | 432 | | } |
| 0 | 433 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 434 | | } |
| | 435 | | } |
| 8 | 436 | | if (_shouldTrace) |
| | 437 | | { |
| 0 | 438 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 439 | | } |
| 8 | 440 | | return _result; |
| 8 | 441 | | } |
| | 442 | |
|
| | 443 | | /// <summary> |
| | 444 | | /// Update tag attributes |
| | 445 | | /// </summary> |
| | 446 | | /// <param name='name'> |
| | 447 | | /// Name of the image (including the namespace) |
| | 448 | | /// </param> |
| | 449 | | /// <param name='reference'> |
| | 450 | | /// Tag name |
| | 451 | | /// </param> |
| | 452 | | /// <param name='value'> |
| | 453 | | /// Repository attribute value |
| | 454 | | /// </param> |
| | 455 | | /// <param name='customHeaders'> |
| | 456 | | /// Headers that will be added to request. |
| | 457 | | /// </param> |
| | 458 | | /// <param name='cancellationToken'> |
| | 459 | | /// The cancellation token. |
| | 460 | | /// </param> |
| | 461 | | /// <exception cref="AcrErrorsException"> |
| | 462 | | /// Thrown when the operation returned an invalid status code |
| | 463 | | /// </exception> |
| | 464 | | /// <exception cref="ValidationException"> |
| | 465 | | /// Thrown when a required parameter is null |
| | 466 | | /// </exception> |
| | 467 | | /// <exception cref="System.ArgumentNullException"> |
| | 468 | | /// Thrown when a required parameter is null |
| | 469 | | /// </exception> |
| | 470 | | /// <return> |
| | 471 | | /// A response object containing the response body and response headers. |
| | 472 | | /// </return> |
| | 473 | | public async Task<AzureOperationResponse> UpdateAttributesWithHttpMessagesAsync(string name, string reference, C |
| | 474 | | { |
| 4 | 475 | | if (Client.LoginUri == null) |
| | 476 | | { |
| 0 | 477 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 478 | | } |
| 4 | 479 | | if (name == null) |
| | 480 | | { |
| 0 | 481 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 482 | | } |
| 4 | 483 | | if (reference == null) |
| | 484 | | { |
| 0 | 485 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 486 | | } |
| | 487 | | // Tracing |
| 4 | 488 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 489 | | string _invocationId = null; |
| 4 | 490 | | if (_shouldTrace) |
| | 491 | | { |
| 0 | 492 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 493 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 494 | | tracingParameters.Add("name", name); |
| 0 | 495 | | tracingParameters.Add("reference", reference); |
| 0 | 496 | | tracingParameters.Add("value", value); |
| 0 | 497 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 498 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateAttributes", tracingParameters); |
| | 499 | | } |
| | 500 | | // Construct URL |
| 4 | 501 | | var _baseUrl = Client.BaseUri; |
| 4 | 502 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_tags/{reference}"; |
| 4 | 503 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 504 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 4 | 505 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 4 | 506 | | List<string> _queryParameters = new List<string>(); |
| 4 | 507 | | if (_queryParameters.Count > 0) |
| | 508 | | { |
| 0 | 509 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 510 | | } |
| | 511 | | // Create HTTP transport objects |
| 4 | 512 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 513 | | HttpResponseMessage _httpResponse = null; |
| 4 | 514 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 4 | 515 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 516 | | // Set Headers |
| 4 | 517 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 518 | | { |
| 4 | 519 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 520 | | } |
| 4 | 521 | | if (Client.AcceptLanguage != null) |
| | 522 | | { |
| 4 | 523 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 524 | | { |
| 0 | 525 | | _httpRequest.Headers.Remove("accept-language"); |
| | 526 | | } |
| 4 | 527 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 528 | | } |
| | 529 | |
|
| | 530 | |
|
| 4 | 531 | | if (customHeaders != null) |
| | 532 | | { |
| 0 | 533 | | foreach(var _header in customHeaders) |
| | 534 | | { |
| 0 | 535 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 536 | | { |
| 0 | 537 | | _httpRequest.Headers.Remove(_header.Key); |
| | 538 | | } |
| 0 | 539 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 540 | | } |
| | 541 | | } |
| | 542 | |
|
| | 543 | | // Serialize Request |
| 4 | 544 | | string _requestContent = null; |
| 4 | 545 | | if(value != null) |
| | 546 | | { |
| 4 | 547 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(value, Client.SerializationSettings |
| 4 | 548 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 549 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 550 | | } |
| | 551 | | // Set Credentials |
| 4 | 552 | | if (Client.Credentials != null) |
| | 553 | | { |
| 4 | 554 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 555 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 556 | | } |
| | 557 | | // Send Request |
| 4 | 558 | | if (_shouldTrace) |
| | 559 | | { |
| 0 | 560 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 561 | | } |
| 4 | 562 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 563 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 564 | | if (_shouldTrace) |
| | 565 | | { |
| 0 | 566 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 567 | | } |
| 4 | 568 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 569 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 570 | | string _responseContent = null; |
| 4 | 571 | | if ((int)_statusCode != 200) |
| | 572 | | { |
| 0 | 573 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 574 | | try |
| | 575 | | { |
| 0 | 576 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 577 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 578 | | if (_errorBody != null) |
| | 579 | | { |
| 0 | 580 | | ex.Body = _errorBody; |
| | 581 | | } |
| 0 | 582 | | } |
| 0 | 583 | | catch (JsonException) |
| | 584 | | { |
| | 585 | | // Ignore the exception |
| 0 | 586 | | } |
| 0 | 587 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 588 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 589 | | if (_shouldTrace) |
| | 590 | | { |
| 0 | 591 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 592 | | } |
| 0 | 593 | | _httpRequest.Dispose(); |
| 0 | 594 | | if (_httpResponse != null) |
| | 595 | | { |
| 0 | 596 | | _httpResponse.Dispose(); |
| | 597 | | } |
| 0 | 598 | | throw ex; |
| | 599 | | } |
| | 600 | | // Create Result |
| 4 | 601 | | var _result = new AzureOperationResponse(); |
| 4 | 602 | | _result.Request = _httpRequest; |
| 4 | 603 | | _result.Response = _httpResponse; |
| 4 | 604 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 605 | | { |
| 0 | 606 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 607 | | } |
| 4 | 608 | | if (_shouldTrace) |
| | 609 | | { |
| 0 | 610 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 611 | | } |
| 4 | 612 | | return _result; |
| 4 | 613 | | } |
| | 614 | |
|
| | 615 | | /// <summary> |
| | 616 | | /// Delete tag |
| | 617 | | /// </summary> |
| | 618 | | /// <param name='name'> |
| | 619 | | /// Name of the image (including the namespace) |
| | 620 | | /// </param> |
| | 621 | | /// <param name='reference'> |
| | 622 | | /// Tag name |
| | 623 | | /// </param> |
| | 624 | | /// <param name='customHeaders'> |
| | 625 | | /// Headers that will be added to request. |
| | 626 | | /// </param> |
| | 627 | | /// <param name='cancellationToken'> |
| | 628 | | /// The cancellation token. |
| | 629 | | /// </param> |
| | 630 | | /// <exception cref="AcrErrorsException"> |
| | 631 | | /// Thrown when the operation returned an invalid status code |
| | 632 | | /// </exception> |
| | 633 | | /// <exception cref="ValidationException"> |
| | 634 | | /// Thrown when a required parameter is null |
| | 635 | | /// </exception> |
| | 636 | | /// <exception cref="System.ArgumentNullException"> |
| | 637 | | /// Thrown when a required parameter is null |
| | 638 | | /// </exception> |
| | 639 | | /// <return> |
| | 640 | | /// A response object containing the response body and response headers. |
| | 641 | | /// </return> |
| | 642 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string name, string reference, Dictionary< |
| | 643 | | { |
| 2 | 644 | | if (Client.LoginUri == null) |
| | 645 | | { |
| 0 | 646 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 647 | | } |
| 2 | 648 | | if (name == null) |
| | 649 | | { |
| 0 | 650 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 651 | | } |
| 2 | 652 | | if (reference == null) |
| | 653 | | { |
| 0 | 654 | | throw new ValidationException(ValidationRules.CannotBeNull, "reference"); |
| | 655 | | } |
| | 656 | | // Tracing |
| 2 | 657 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 658 | | string _invocationId = null; |
| 2 | 659 | | if (_shouldTrace) |
| | 660 | | { |
| 0 | 661 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 662 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 663 | | tracingParameters.Add("name", name); |
| 0 | 664 | | tracingParameters.Add("reference", reference); |
| 0 | 665 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 666 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 667 | | } |
| | 668 | | // Construct URL |
| 2 | 669 | | var _baseUrl = Client.BaseUri; |
| 2 | 670 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_tags/{reference}"; |
| 2 | 671 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 672 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 673 | | _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference)); |
| 2 | 674 | | List<string> _queryParameters = new List<string>(); |
| 2 | 675 | | if (_queryParameters.Count > 0) |
| | 676 | | { |
| 0 | 677 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 678 | | } |
| | 679 | | // Create HTTP transport objects |
| 2 | 680 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 681 | | HttpResponseMessage _httpResponse = null; |
| 2 | 682 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 683 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 684 | | // Set Headers |
| 2 | 685 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 686 | | { |
| 2 | 687 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 688 | | } |
| 2 | 689 | | if (Client.AcceptLanguage != null) |
| | 690 | | { |
| 2 | 691 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 692 | | { |
| 0 | 693 | | _httpRequest.Headers.Remove("accept-language"); |
| | 694 | | } |
| 2 | 695 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 696 | | } |
| | 697 | |
|
| | 698 | |
|
| 2 | 699 | | if (customHeaders != null) |
| | 700 | | { |
| 0 | 701 | | foreach(var _header in customHeaders) |
| | 702 | | { |
| 0 | 703 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 704 | | { |
| 0 | 705 | | _httpRequest.Headers.Remove(_header.Key); |
| | 706 | | } |
| 0 | 707 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 708 | | } |
| | 709 | | } |
| | 710 | |
|
| | 711 | | // Serialize Request |
| 2 | 712 | | string _requestContent = null; |
| | 713 | | // Set Credentials |
| 2 | 714 | | if (Client.Credentials != null) |
| | 715 | | { |
| 2 | 716 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 717 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 718 | | } |
| | 719 | | // Send Request |
| 2 | 720 | | if (_shouldTrace) |
| | 721 | | { |
| 0 | 722 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 723 | | } |
| 2 | 724 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 725 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 726 | | if (_shouldTrace) |
| | 727 | | { |
| 0 | 728 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 729 | | } |
| 2 | 730 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 731 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 732 | | string _responseContent = null; |
| 2 | 733 | | if ((int)_statusCode != 202) |
| | 734 | | { |
| 0 | 735 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 736 | | try |
| | 737 | | { |
| 0 | 738 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 739 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 740 | | if (_errorBody != null) |
| | 741 | | { |
| 0 | 742 | | ex.Body = _errorBody; |
| | 743 | | } |
| 0 | 744 | | } |
| 0 | 745 | | catch (JsonException) |
| | 746 | | { |
| | 747 | | // Ignore the exception |
| 0 | 748 | | } |
| 0 | 749 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 750 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 751 | | if (_shouldTrace) |
| | 752 | | { |
| 0 | 753 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 754 | | } |
| 0 | 755 | | _httpRequest.Dispose(); |
| 0 | 756 | | if (_httpResponse != null) |
| | 757 | | { |
| 0 | 758 | | _httpResponse.Dispose(); |
| | 759 | | } |
| 0 | 760 | | throw ex; |
| | 761 | | } |
| | 762 | | // Create Result |
| 2 | 763 | | var _result = new AzureOperationResponse(); |
| 2 | 764 | | _result.Request = _httpRequest; |
| 2 | 765 | | _result.Response = _httpResponse; |
| 2 | 766 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 767 | | { |
| 2 | 768 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 769 | | } |
| 2 | 770 | | if (_shouldTrace) |
| | 771 | | { |
| 0 | 772 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 773 | | } |
| 2 | 774 | | return _result; |
| 2 | 775 | | } |
| | 776 | |
|
| | 777 | | } |
| | 778 | | } |