-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathConfigsOperations.cs
More file actions
53 lines (45 loc) · 2.18 KB
/
ConfigsOperations.cs
File metadata and controls
53 lines (45 loc) · 2.18 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet.Models;
namespace Docker.DotNet
{
internal class ConfigsOperations : IConfigsOperations
{
private readonly DockerClient _client;
internal ConfigsOperations(DockerClient client)
{
_client = client;
}
async Task<IList<SwarmConfig>> IConfigsOperations.ListAsync(CancellationToken cancellationToken)
{
var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false);
return _client.JsonSerializer.DeserializeObject<IList<SwarmConfig>>(response.Body);
}
async Task<SwarmCreateConfigResponse> IConfigsOperations.CreateAsync(ConfigSpec body, CancellationToken cancellationToken)
{
var data = new JsonRequestContent<ConfigSpec>(body ?? throw new ArgumentNullException(nameof(body)), _client.JsonSerializer);
var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken).ConfigureAwait(false);
return _client.JsonSerializer.DeserializeObject<SwarmCreateConfigResponse>(response.Body);
}
async Task<SwarmConfig> IConfigsOperations.InspectAsync(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false);
return _client.JsonSerializer.DeserializeObject<SwarmConfig>(response.Body);
}
Task IConfigsOperations.DeleteAsync(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"configs/{id}", cancellationToken);
}
}
}