2021-08-09 07:27:32 -07:00
|
|
|
// <auto-generated>
|
|
|
|
|
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/gen/KubernetesGenerator
|
|
|
|
|
// Changes may cause incorrect behavior and will be lost if the code is
|
|
|
|
|
// regenerated.
|
|
|
|
|
// </auto-generated>
|
|
|
|
|
|
|
|
|
|
namespace k8s
|
|
|
|
|
{
|
|
|
|
|
using Microsoft.Rest;
|
|
|
|
|
using Microsoft.Rest.Serialization;
|
|
|
|
|
using Models;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
public partial class Kubernetes : ServiceClient<Kubernetes>, IKubernetes
|
|
|
|
|
{
|
|
|
|
|
{{#.}}
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
|
|
|
|
|
{{#operation.parameters}}
|
|
|
|
|
{{GetDotNetType .}} {{GetDotNetName . "true"}},
|
|
|
|
|
{{/operation.parameters}}
|
|
|
|
|
Dictionary<string, List<string>> customHeaders = null,
|
|
|
|
|
CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
{
|
2021-10-11 12:55:02 -07:00
|
|
|
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
|
|
|
|
cts.CancelAfter(HttpClientTimeout);
|
2021-10-20 09:55:58 -04:00
|
|
|
{{#IfParamContains operation "watch"}}
|
2021-10-11 12:55:02 -07:00
|
|
|
if (watch == true)
|
|
|
|
|
{
|
|
|
|
|
cts.CancelAfter(Timeout.InfiniteTimeSpan);
|
|
|
|
|
}
|
2021-10-20 09:55:58 -04:00
|
|
|
{{/IfParamContains operation "watch"}}
|
2021-10-11 12:55:02 -07:00
|
|
|
cancellationToken = cts.Token;
|
|
|
|
|
|
2021-08-09 07:27:32 -07:00
|
|
|
{{#operation.parameters}}
|
|
|
|
|
{{#isRequired}}
|
|
|
|
|
if ({{GetDotNetName name}} == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ValidationException(ValidationRules.CannotBeNull, "{{GetDotNetName name}}");
|
|
|
|
|
}
|
|
|
|
|
{{/isRequired}}
|
|
|
|
|
{{/operation.parameters}}
|
|
|
|
|
// Tracing
|
|
|
|
|
bool _shouldTrace = ServiceClientTracing.IsEnabled;
|
|
|
|
|
string _invocationId = null;
|
|
|
|
|
if (_shouldTrace)
|
|
|
|
|
{
|
|
|
|
|
_invocationId = ServiceClientTracing.NextInvocationId.ToString();
|
|
|
|
|
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
|
|
|
|
|
{{#operation.parameters}}
|
|
|
|
|
tracingParameters.Add("{{GetDotNetName name}}", {{GetDotNetName name}});
|
|
|
|
|
{{/operation.parameters}}
|
|
|
|
|
tracingParameters.Add("cancellationToken", cancellationToken);
|
|
|
|
|
ServiceClientTracing.Enter(_invocationId, this, "{{GetMethodName operation ""}}", tracingParameters);
|
|
|
|
|
}
|
|
|
|
|
// Construct URL
|
|
|
|
|
var _baseUrl = BaseUri.AbsoluteUri;
|
|
|
|
|
var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{{path}}").ToString();
|
2021-09-17 08:23:01 -07:00
|
|
|
_url = _url.Replace("/apis//", "/api/");
|
2021-08-09 07:27:32 -07:00
|
|
|
{{#operation.parameters}}
|
|
|
|
|
{{#IfKindIs . "path"}}
|
|
|
|
|
_url = _url.Replace("{{AddCurly name}}", {{GetDotNetName name}});
|
|
|
|
|
{{/IfKindIs . "path"}}
|
|
|
|
|
{{/operation.parameters}}
|
|
|
|
|
List<string> _queryParameters = new List<string>();
|
|
|
|
|
{{#operation.parameters}}
|
|
|
|
|
{{#IfKindIs . "query"}}
|
|
|
|
|
if ({{GetDotNetName name}} != null)
|
|
|
|
|
{
|
|
|
|
|
_queryParameters.Add(string.Format("{{name}}={0}", {{EscapeDataString name type}}));
|
|
|
|
|
}
|
|
|
|
|
{{/IfKindIs . "query"}}
|
|
|
|
|
{{/operation.parameters}}
|
|
|
|
|
if (_queryParameters.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
_url += "?" + string.Join("&", _queryParameters);
|
|
|
|
|
}
|
|
|
|
|
// Create HTTP transport
|
|
|
|
|
var _httpRequest = new HttpRequestMessage();
|
|
|
|
|
HttpResponseMessage _httpResponse = null;
|
|
|
|
|
_httpRequest.Method = HttpMethod.{{Method}};
|
|
|
|
|
_httpRequest.RequestUri = new System.Uri(_url);
|
2021-09-14 11:20:05 -07:00
|
|
|
_httpRequest.Version = HttpVersion.Version20;
|
2021-08-09 07:27:32 -07:00
|
|
|
// Set Headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (customHeaders != null)
|
|
|
|
|
{
|
|
|
|
|
foreach(var _header in customHeaders)
|
|
|
|
|
{
|
2021-10-20 09:55:58 -04:00
|
|
|
_httpRequest.Headers.Remove(_header.Key);
|
2021-08-09 07:27:32 -07:00
|
|
|
_httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Serialize Request
|
|
|
|
|
string _requestContent = null;
|
2021-10-20 09:55:58 -04:00
|
|
|
{{#IfParamContains operation "body"}}
|
2021-08-09 07:27:32 -07:00
|
|
|
if(body != null)
|
|
|
|
|
{
|
|
|
|
|
_requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings);
|
|
|
|
|
_httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
|
|
|
|
|
_httpRequest.Content.Headers.ContentType = GetHeader(body);
|
|
|
|
|
}
|
2021-10-20 09:55:58 -04:00
|
|
|
{{/IfParamContains operation "body"}}
|
2021-08-09 07:27:32 -07:00
|
|
|
// Set Credentials
|
|
|
|
|
if (Credentials != null)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
// Send Request
|
|
|
|
|
if (_shouldTrace)
|
|
|
|
|
{
|
|
|
|
|
ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
|
|
|
|
|
}
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2021-09-14 11:20:05 -07:00
|
|
|
_httpResponse = await HttpClient.SendAsync(_httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
2021-08-09 07:27:32 -07:00
|
|
|
if (_shouldTrace)
|
|
|
|
|
{
|
|
|
|
|
ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
|
|
|
|
|
}
|
|
|
|
|
HttpStatusCode _statusCode = _httpResponse.StatusCode;
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
if ((int)_statusCode != 200 && (int)_statusCode != 201 && (int)_statusCode != 202)
|
|
|
|
|
{
|
2021-10-20 09:55:58 -04:00
|
|
|
string _responseContent = null;
|
2021-08-09 07:27:32 -07:00
|
|
|
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
|
|
|
|
|
if (_httpResponse.Content != null) {
|
|
|
|
|
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_responseContent = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
|
|
|
|
|
ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
|
|
|
|
|
if (_shouldTrace)
|
|
|
|
|
{
|
|
|
|
|
ServiceClientTracing.Error(_invocationId, ex);
|
|
|
|
|
}
|
|
|
|
|
_httpRequest.Dispose();
|
|
|
|
|
if (_httpResponse != null)
|
|
|
|
|
{
|
|
|
|
|
_httpResponse.Dispose();
|
|
|
|
|
}
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
// Create Result
|
2021-10-20 09:55:58 -04:00
|
|
|
{{#IfReturnType operation "void"}}
|
|
|
|
|
HttpOperationResponse _result = new HttpOperationResponse() { Request = _httpRequest, Response = _httpResponse };
|
|
|
|
|
{{/IfReturnType operation "void"}}
|
|
|
|
|
{{#IfReturnType operation "obj"}}
|
|
|
|
|
var _result = await CreateResultAsync{{GetReturnType operation "<>"}}(_httpRequest,
|
|
|
|
|
_httpResponse,
|
|
|
|
|
{{#IfParamContains operation "watch"}}
|
|
|
|
|
watch,
|
|
|
|
|
{{/IfParamContains operation "watch"}}
|
|
|
|
|
{{#IfParamDoesNotContain operation "watch"}}
|
|
|
|
|
false,
|
|
|
|
|
{{/IfParamDoesNotContain operation "watch"}}
|
|
|
|
|
cancellationToken);
|
|
|
|
|
{{/IfReturnType operation "obj"}}
|
|
|
|
|
{{#IfReturnType operation "stream"}}
|
|
|
|
|
var _result = new HttpOperationResponse{{GetReturnType operation "<>"}}() {
|
|
|
|
|
Request = _httpRequest,
|
|
|
|
|
Response = _httpResponse,
|
|
|
|
|
Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
|
|
|
|
|
{{/IfReturnType operation "stream"}}
|
2021-08-09 07:27:32 -07:00
|
|
|
if (_shouldTrace)
|
|
|
|
|
{
|
|
|
|
|
ServiceClientTracing.Exit(_invocationId, _result);
|
|
|
|
|
}
|
|
|
|
|
return _result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{/.}}
|
|
|
|
|
}
|
|
|
|
|
}
|