2022-03-23 16:25:20 -07:00
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
namespace k8s;
|
2022-03-23 16:25:20 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
public abstract partial class AbstractKubernetes
|
2022-03-23 16:25:20 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);
|
2022-03-23 16:25:20 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
protected internal virtual MediaTypeHeaderValue GetHeader(object body)
|
|
|
|
|
{
|
|
|
|
|
if (body == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(body));
|
2022-03-23 16:25:20 -07:00
|
|
|
}
|
|
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
if (body is V1Patch patch)
|
2022-03-23 16:25:20 -07:00
|
|
|
{
|
2022-05-07 13:05:17 -07:00
|
|
|
return GetHeader(patch);
|
2022-03-23 16:25:20 -07:00
|
|
|
}
|
|
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
return MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
|
|
|
|
|
}
|
2022-03-23 16:25:20 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
private MediaTypeHeaderValue GetHeader(V1Patch body)
|
|
|
|
|
{
|
|
|
|
|
if (body == null)
|
2022-03-28 08:45:23 -07:00
|
|
|
{
|
2022-05-07 13:05:17 -07:00
|
|
|
throw new ArgumentNullException(nameof(body));
|
2022-03-28 08:45:23 -07:00
|
|
|
}
|
|
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
switch (body.Type)
|
2022-03-28 08:45:23 -07:00
|
|
|
{
|
2022-05-07 13:05:17 -07:00
|
|
|
case V1Patch.PatchType.JsonPatch:
|
|
|
|
|
return MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");
|
|
|
|
|
case V1Patch.PatchType.MergePatch:
|
|
|
|
|
return MediaTypeHeaderValue.Parse("application/merge-patch+json; charset=utf-8");
|
|
|
|
|
case V1Patch.PatchType.StrategicMergePatch:
|
|
|
|
|
return MediaTypeHeaderValue.Parse("application/strategic-merge-patch+json; charset=utf-8");
|
|
|
|
|
case V1Patch.PatchType.ApplyPatch:
|
|
|
|
|
return MediaTypeHeaderValue.Parse("application/apply-patch+yaml; charset=utf-8");
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(body.Type), "");
|
2022-03-28 08:45:23 -07:00
|
|
|
}
|
2022-05-07 13:05:17 -07:00
|
|
|
}
|
2022-03-28 08:45:23 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
protected internal abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);
|
2022-03-23 16:25:20 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
protected internal abstract HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders);
|
2022-03-23 16:25:20 -07:00
|
|
|
|
2022-05-07 13:05:17 -07:00
|
|
|
protected internal abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
|
2022-03-23 16:25:20 -07:00
|
|
|
}
|