-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
EndPointClientV1.cs
38 lines (32 loc) · 1.24 KB
/
EndPointClientV1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using HTTPlease;
using KubeClient.Models;
using KubeClient.ResourceClients;
using Ocelot.Provider.Kubernetes.Interfaces;
namespace Ocelot.Provider.Kubernetes
{
public class EndPointClientV1 : KubeResourceClient, IEndPointClient
{
private readonly HttpRequest _collection;
public EndPointClientV1(IKubeApiClient client) : base(client)
{
_collection = KubeRequest.Create("api/v1/namespaces/{Namespace}/endpoints/{ServiceName}");
}
public async Task<EndpointsV1> GetAsync(string serviceName, string kubeNamespace = null, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(serviceName))
{
throw new ArgumentNullException(nameof(serviceName));
}
var request = _collection
.WithTemplateParameters(new
{
Namespace = kubeNamespace ?? KubeClient.DefaultNamespace,
ServiceName = serviceName,
});
var response = await Http.GetAsync(request, cancellationToken);
return response.IsSuccessStatusCode
? await response.ReadContentAsAsync<EndpointsV1>()
: null;
}
}
}