diff --git a/src/Docker.DotNet/Docker.DotNet.csproj b/src/Docker.DotNet/Docker.DotNet.csproj
index ac77c8111..07a06a976 100644
--- a/src/Docker.DotNet/Docker.DotNet.csproj
+++ b/src/Docker.DotNet/Docker.DotNet.csproj
@@ -3,9 +3,12 @@
Docker.DotNet.Enhanced
Docker.DotNet is a library that allows you to interact with the Docker Remote API programmatically with fully asynchronous, non-blocking and object-oriented code in your .NET applications.
Docker.DotNet
+ latest
-
+
+
+
\ No newline at end of file
diff --git a/src/Docker.DotNet/DockerClient.cs b/src/Docker.DotNet/DockerClient.cs
index 64a428f84..1960e8a84 100644
--- a/src/Docker.DotNet/DockerClient.cs
+++ b/src/Docker.DotNet/DockerClient.cs
@@ -33,7 +33,6 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
Configuration = configuration;
DefaultTimeout = configuration.DefaultTimeout;
- JsonSerializer = new JsonSerializer();
Images = new ImageOperations(this);
Containers = new ContainerOperations(this);
System = new SystemOperations(this);
@@ -149,7 +148,7 @@ await sock.ConnectAsync(new Microsoft.Net.Http.Client.UnixDomainSocketEndPoint(p
public IExecOperations Exec { get; }
- internal JsonSerializer JsonSerializer { get; }
+ internal static JsonSerializer JsonSerializer => JsonSerializer.Instance;
public void Dispose()
{
@@ -157,49 +156,92 @@ public void Dispose()
_client.Dispose();
}
- internal Task MakeRequestAsync(
+ internal Task MakeRequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
CancellationToken token)
{
- return MakeRequestAsync(errorHandlers, method, path, null, null, token);
+ return MakeRequestAsync(errorHandlers, method, path, null, null, token);
}
- internal Task MakeRequestAsync(
+ internal Task MakeRequestAsync(
+ IEnumerable errorHandlers,
+ HttpMethod method,
+ string path,
+ CancellationToken token)
+ {
+ return MakeRequestAsync(errorHandlers, method, path, null, null, token);
+ }
+
+ internal Task MakeRequestAsync(
+ IEnumerable errorHandlers,
+ HttpMethod method,
+ string path,
+ IQueryString queryString,
+ CancellationToken token)
+ {
+ return MakeRequestAsync(errorHandlers, method, path, queryString, null, token);
+ }
+
+ internal Task MakeRequestAsync(
+ IEnumerable errorHandlers,
+ HttpMethod method,
+ string path,
+ IQueryString queryString,
+ CancellationToken token)
+ {
+ return MakeRequestAsync(errorHandlers, method, path, queryString, null, token);
+ }
+
+ internal Task MakeRequestAsync(
+ IEnumerable errorHandlers,
+ HttpMethod method,
+ string path,
+ IQueryString queryString,
+ IRequestContent body,
+ CancellationToken token)
+ {
+ return MakeRequestAsync(errorHandlers, method, path, queryString, body, null, token);
+ }
+
+ internal Task MakeRequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
IQueryString queryString,
+ IRequestContent body,
CancellationToken token)
{
- return MakeRequestAsync(errorHandlers, method, path, queryString, null, token);
+ return MakeRequestAsync(errorHandlers, method, path, queryString, body, null, token);
}
- internal Task MakeRequestAsync(
+ internal Task MakeRequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
IQueryString queryString,
IRequestContent body,
+ IDictionary headers,
CancellationToken token)
{
- return MakeRequestAsync(errorHandlers, method, path, queryString, body, null, token);
+ return MakeRequestAsync(errorHandlers, method, path, queryString, body, headers, DefaultTimeout, token);
}
- internal Task MakeRequestAsync(
+ internal Task MakeRequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
IQueryString queryString,
IRequestContent body,
IDictionary headers,
+ TimeSpan timeout,
CancellationToken token)
{
- return MakeRequestAsync(errorHandlers, method, path, queryString, body, headers, DefaultTimeout, token);
+ return MakeRequestAsync(errorHandlers, method, path, queryString, body, headers, timeout, token);
}
- internal async Task MakeRequestAsync(
+ internal async Task MakeRequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
@@ -209,19 +251,19 @@ internal async Task MakeRequestAsync(
TimeSpan timeout,
CancellationToken token)
{
- var response = await PrivateMakeRequestAsync(timeout, HttpCompletionOption.ResponseContentRead, method, path, queryString, headers, body, token)
+ using var response = await PrivateMakeRequestAsync(timeout, HttpCompletionOption.ResponseContentRead, method, path, queryString, headers, body, token)
.ConfigureAwait(false);
- using (response)
- {
- await HandleIfErrorResponseAsync(response.StatusCode, response, errorHandlers)
- .ConfigureAwait(false);
-
- var responseBody = await response.Content.ReadAsStringAsync()
- .ConfigureAwait(false);
+ await HandleIfErrorResponseAsync(response.StatusCode, response, errorHandlers)
+ .ConfigureAwait(false);
- return new DockerApiResponse(response.StatusCode, responseBody);
+ if (typeof(T) == typeof(NoContent))
+ {
+ return default;
}
+
+ return await JsonSerializer.DeserializeAsync(response.Content, token)
+ .ConfigureAwait(false);
}
internal Task MakeRequestForStreamAsync(
@@ -294,9 +336,12 @@ internal async Task MakeRequestForRawResponseAsync(
IDictionary headers,
CancellationToken token)
{
- var response = await PrivateMakeRequestAsync(SInfiniteTimeout, HttpCompletionOption.ResponseHeadersRead, method, path, queryString, headers, body, token).ConfigureAwait(false);
+ var response = await PrivateMakeRequestAsync(SInfiniteTimeout, HttpCompletionOption.ResponseHeadersRead, method, path, queryString, headers, body, token)
+ .ConfigureAwait(false);
+
await HandleIfErrorResponseAsync(response.StatusCode, response)
.ConfigureAwait(false);
+
return response;
}
@@ -347,7 +392,7 @@ internal async Task MakeRequestForHijackedStreamAsync(
await HandleIfErrorResponseAsync(response.StatusCode, response, errorHandlers)
.ConfigureAwait(false);
- if (!(response.Content is HttpConnectionResponseContent content))
+ if (response.Content is not HttpConnectionResponseContent content)
{
throw new NotSupportedException("message handler does not support hijacked streams");
}
@@ -388,7 +433,7 @@ private async Task PrivateMakeRequestAsync(
}
}
- internal HttpRequestMessage PrepareRequest(HttpMethod method, string path, IQueryString queryString, IDictionary headers, IRequestContent data)
+ private HttpRequestMessage PrepareRequest(HttpMethod method, string path, IQueryString queryString, IDictionary headers, IRequestContent data)
{
if (string.IsNullOrEmpty(path))
{
@@ -469,6 +514,8 @@ private async Task HandleIfErrorResponseAsync(HttpStatusCode statusCode, HttpRes
throw new DockerApiException(statusCode, responseBody);
}
}
+
+ private struct NoContent;
}
internal delegate void ApiResponseErrorHandlingDelegate(HttpStatusCode statusCode, string responseBody);
diff --git a/src/Docker.DotNet/Endpoints/ConfigsOperations.cs b/src/Docker.DotNet/Endpoints/ConfigsOperations.cs
index e7e04e8c8..04492f000 100644
--- a/src/Docker.DotNet/Endpoints/ConfigsOperations.cs
+++ b/src/Docker.DotNet/Endpoints/ConfigsOperations.cs
@@ -18,8 +18,7 @@ internal ConfigOperations(DockerClient client)
async Task> IConfigOperations.ListConfigsAsync(CancellationToken cancellationToken)
{
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject>(response.Body);
+ return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false);
}
async Task IConfigOperations.CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken)
@@ -29,9 +28,8 @@ async Task IConfigOperations.CreateConfigAsync(SwarmC
throw new ArgumentNullException(nameof(body));
}
- var data = new JsonRequestContent(body.Config, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(body.Config, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken).ConfigureAwait(false);
}
async Task IConfigOperations.InspectConfigAsync(string id, CancellationToken cancellationToken)
@@ -41,8 +39,7 @@ async Task IConfigOperations.InspectConfigAsync(string id, Cancella
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false);
}
Task IConfigOperations.RemoveConfigAsync(string id, CancellationToken cancellationToken)
@@ -55,4 +52,4 @@ Task IConfigOperations.RemoveConfigAsync(string id, CancellationToken cancellati
return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"configs/{id}", cancellationToken);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/ContainerOperations.cs b/src/Docker.DotNet/Endpoints/ContainerOperations.cs
index 03960ab7c..9d2ffe0a5 100644
--- a/src/Docker.DotNet/Endpoints/ContainerOperations.cs
+++ b/src/Docker.DotNet/Endpoints/ContainerOperations.cs
@@ -5,7 +5,6 @@
using System.Linq;
using System.Net;
using System.Net.Http;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -13,14 +12,15 @@ namespace Docker.DotNet
{
internal class ContainerOperations : IContainerOperations
{
- internal static readonly ApiResponseErrorHandlingDelegate NoSuchContainerHandler = (statusCode, responseBody) =>
+ private static readonly ApiResponseErrorHandlingDelegate NoSuchContainerHandler = (statusCode, responseBody) =>
{
if (statusCode == HttpStatusCode.NotFound)
{
throw new DockerContainerNotFoundException(statusCode, responseBody);
}
};
- internal static readonly ApiResponseErrorHandlingDelegate NoSuchImageHandler = (statusCode, responseBody) =>
+
+ private static readonly ApiResponseErrorHandlingDelegate NoSuchImageHandler = (statusCode, responseBody) =>
{
if (statusCode == HttpStatusCode.NotFound)
{
@@ -43,8 +43,7 @@ internal ContainerOperations(DockerClient client)
}
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "containers/json", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "containers/json", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -61,9 +60,8 @@ internal ContainerOperations(DockerClient client)
qs = new QueryString(parameters);
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false);
}
public async Task InspectContainerAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
@@ -73,8 +71,7 @@ internal ContainerOperations(DockerClient client)
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/json", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/json", cancellationToken).ConfigureAwait(false);
}
public async Task ListProcessesAsync(string id, ContainerListProcessesParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -90,8 +87,7 @@ internal ContainerOperations(DockerClient client)
}
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/top", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/top", queryParameters, cancellationToken).ConfigureAwait(false);
}
public Task GetContainerLogsAsync(string id, ContainerLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -145,8 +141,7 @@ public Task GetContainerLogsAsync(string id, ContainerLogsParameters parameters,
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/changes", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/changes", cancellationToken).ConfigureAwait(false);
}
public Task ExportContainerAsync(string id, CancellationToken cancellationToken)
@@ -207,9 +202,10 @@ public Task GetContainerStatsAsync(string id, ContainerStatsParameters p
throw new ArgumentNullException(nameof(id));
}
- var queryParams = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/start", queryParams, cancellationToken).ConfigureAwait(false);
- return response.StatusCode != HttpStatusCode.NotModified;
+ var queryParameters = parameters == null ? null : new QueryString(parameters);
+ bool? result = null;
+ await _client.MakeRequestAsync(new[] { NoSuchContainerHandler, (statusCode, _) => result = statusCode != HttpStatusCode.NotModified }, HttpMethod.Post, $"containers/{id}/start", queryParameters, cancellationToken).ConfigureAwait(false);
+ return result ?? throw new InvalidOperationException();
}
public async Task StopContainerAsync(string id, ContainerStopParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -224,11 +220,12 @@ public Task GetContainerStatsAsync(string id, ContainerStatsParameters p
throw new ArgumentNullException(nameof(parameters));
}
- IQueryString queryParameters = new QueryString(parameters);
+ var queryParameters = new QueryString(parameters);
// since specified wait timespan can be greater than HttpClient's default, we set the
// client timeout to infinite and provide a cancellation token.
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/stop", queryParameters, null, null, TimeSpan.FromMilliseconds(Timeout.Infinite), cancellationToken).ConfigureAwait(false);
- return response.StatusCode != HttpStatusCode.NotModified;
+ bool? result = null;
+ await _client.MakeRequestAsync(new[] { NoSuchContainerHandler, (statusCode, _) => result = statusCode != HttpStatusCode.NotModified }, HttpMethod.Post, $"containers/{id}/stop", queryParameters, null, null, TimeSpan.FromMilliseconds(Timeout.Infinite), cancellationToken).ConfigureAwait(false);
+ return result ?? throw new InvalidOperationException();
}
public Task RestartContainerAsync(string id, ContainerRestartParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -327,8 +324,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/wait", null, null, null, TimeSpan.FromMilliseconds(Timeout.Infinite), cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/wait", null, null, null, TimeSpan.FromMilliseconds(Timeout.Infinite), cancellationToken).ConfigureAwait(false);
}
public Task RemoveContainerAsync(string id, ContainerRemoveParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -367,9 +363,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
var bytes = Convert.FromBase64String(statHeader);
- var stat = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
-
- var pathStat = _client.JsonSerializer.DeserializeObject(stat);
+ var pathStat = DockerClient.JsonSerializer.Deserialize(bytes);
return new GetArchiveFromContainerResponse
{
@@ -399,8 +393,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
public async Task PruneContainersAsync(ContainersPruneParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "containers/prune", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "containers/prune", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task UpdateContainerAsync(string id, ContainerUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -415,9 +408,8 @@ public async Task PruneContainersAsync(ContainersPruneP
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/update", null, data, cancellationToken);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/update", null, data, cancellationToken);
}
}
}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/ExecOperations.cs b/src/Docker.DotNet/Endpoints/ExecOperations.cs
index 27c695989..1708c6057 100644
--- a/src/Docker.DotNet/Endpoints/ExecOperations.cs
+++ b/src/Docker.DotNet/Endpoints/ExecOperations.cs
@@ -36,9 +36,8 @@ internal ExecOperations(DockerClient client)
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/exec", null, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/exec", null, data, cancellationToken).ConfigureAwait(false);
}
public async Task InspectContainerExecAsync(string id, CancellationToken cancellationToken)
@@ -48,8 +47,7 @@ public async Task InspectContainerExecAsync(string
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"exec/{id}/json", null, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"exec/{id}/json", null, cancellationToken).ConfigureAwait(false);
}
public Task ResizeContainerExecTtyAsync(string id, ContainerResizeParameters parameters, CancellationToken cancellationToken)
@@ -81,7 +79,7 @@ public Task StartContainerExecAsync(string id, CancellationToken cancellationTok
{
Detach = true,
};
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, data, cancellationToken);
}
@@ -99,7 +97,7 @@ public async Task StartWithConfigContainerExecAsync(string id
throw new ArgumentNullException(nameof(id));
}
- var data = new JsonRequestContent(eConfig, _client.JsonSerializer);
+ var data = new JsonRequestContent(eConfig, DockerClient.JsonSerializer);
var stream = await _client.MakeRequestForHijackedStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, data, null, cancellationToken).ConfigureAwait(false);
if (!stream.CanCloseWrite)
{
@@ -110,4 +108,4 @@ public async Task StartWithConfigContainerExecAsync(string id
return new MultiplexedStream(stream, !eConfig.Tty);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/ImageOperations.cs b/src/Docker.DotNet/Endpoints/ImageOperations.cs
index a33df2def..1a965c48d 100644
--- a/src/Docker.DotNet/Endpoints/ImageOperations.cs
+++ b/src/Docker.DotNet/Endpoints/ImageOperations.cs
@@ -5,7 +5,6 @@
using System.Linq;
using System.Net;
using System.Net.Http;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -41,8 +40,7 @@ internal ImageOperations(DockerClient client)
}
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/json", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/json", queryParameters, cancellationToken).ConfigureAwait(false);
}
public Task BuildImageFromDockerfileAsync(Stream contents, ImageBuildParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -140,7 +138,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea
if(headers != null)
{
- foreach(string key in headers.Keys)
+ foreach(var key in headers.Keys)
{
customHeaders[key] = headers[key];
}
@@ -161,8 +159,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea
throw new ArgumentNullException(nameof(name));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/json", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/json", cancellationToken).ConfigureAwait(false);
}
public async Task> GetImageHistoryAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
@@ -172,8 +169,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea
throw new ArgumentNullException(nameof(name));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/history", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/history", cancellationToken).ConfigureAwait(false);
}
public Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken))
@@ -225,8 +221,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea
}
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Delete, $"images/{name}", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject[]>(response.Body);
+ return await _client.MakeRequestAsync[]>(new[] { NoSuchImageHandler }, HttpMethod.Delete, $"images/{name}", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task> SearchImagesAsync(ImagesSearchParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -237,15 +232,13 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea
}
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/search", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/search", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task PruneImagesAsync(ImagesPruneParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "images/prune", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "images/prune", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task CommitContainerChangesAsync(CommitContainerChangesParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -255,11 +248,10 @@ public async Task PruneImagesAsync(ImagesPruneParameters pa
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
IQueryString queryParameters = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "commit", queryParameters, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "commit", queryParameters, data, cancellationToken).ConfigureAwait(false);
}
public Task SaveImageAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
@@ -307,12 +299,10 @@ private Dictionary RegistryAuthHeaders(AuthConfig authConfig)
{
{
RegistryAuthHeaderKey,
- Convert.ToBase64String(
- Encoding.UTF8.GetBytes(
- _client.JsonSerializer.SerializeObject(authConfig ?? new AuthConfig())))
- .Replace("/", "_").Replace("+", "-")
+ Convert.ToBase64String(DockerClient.JsonSerializer.SerializeToUtf8Bytes(authConfig ?? new AuthConfig()))
+ .Replace("/", "_").Replace("+", "-")
// This is not documented in Docker API but from source code (https://github.com/docker/docker-ce/blob/10e40bd1548f69354a803a15fde1b672cc024b91/components/cli/cli/command/registry.go#L47)
- // and from multiple internet sources it has to be base64-url-safe.
+ // and from multiple internet sources it has to be base64-url-safe.
// See RFC 4648 Section 5. Padding (=) needs to be kept.
}
};
@@ -320,12 +310,12 @@ private Dictionary RegistryAuthHeaders(AuthConfig authConfig)
private Dictionary RegistryConfigHeaders(IEnumerable authConfig)
{
- var configDictionary = (authConfig ?? new AuthConfig[0]).ToDictionary(e => e.ServerAddress, e => e);
+ var configDictionary = (authConfig ?? Array.Empty()).ToDictionary(e => e.ServerAddress, e => e);
return new Dictionary
{
{
RegistryConfigHeaderKey,
- Convert.ToBase64String(Encoding.UTF8.GetBytes(_client.JsonSerializer.SerializeObject(configDictionary)))
+ Convert.ToBase64String(DockerClient.JsonSerializer.SerializeToUtf8Bytes(configDictionary))
}
};
}
diff --git a/src/Docker.DotNet/Endpoints/NetworkOperations.cs b/src/Docker.DotNet/Endpoints/NetworkOperations.cs
index 3271c636c..aee91d2f0 100644
--- a/src/Docker.DotNet/Endpoints/NetworkOperations.cs
+++ b/src/Docker.DotNet/Endpoints/NetworkOperations.cs
@@ -29,8 +29,7 @@ internal NetworkOperations(DockerClient client)
async Task> INetworkOperations.ListNetworksAsync(NetworksListParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "networks", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "networks", queryParameters, cancellationToken).ConfigureAwait(false);
}
async Task INetworkOperations.InspectNetworkAsync(string id, CancellationToken cancellationToken)
@@ -40,8 +39,7 @@ async Task INetworkOperations.InspectNetworkAsync(string id, Ca
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Get, $"networks/{id}", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Get, $"networks/{id}", cancellationToken).ConfigureAwait(false);
}
Task INetworkOperations.DeleteNetworkAsync(string id, CancellationToken cancellationToken)
@@ -61,9 +59,8 @@ async Task INetworkOperations.CreateNetworkAsync(Network
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "networks/create", null, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "networks/create", null, data, cancellationToken).ConfigureAwait(false);
}
Task INetworkOperations.ConnectNetworkAsync(string id, NetworkConnectParameters parameters, CancellationToken cancellationToken)
@@ -78,7 +75,7 @@ Task INetworkOperations.ConnectNetworkAsync(string id, NetworkConnectParameters
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
return _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Post, $"networks/{id}/connect", null, data, cancellationToken);
}
@@ -94,7 +91,7 @@ Task INetworkOperations.DisconnectNetworkAsync(string id, NetworkDisconnectParam
throw new ArgumentNullException(nameof(parameters));
}
- var data = new JsonRequestContent(parameters, _client.JsonSerializer);
+ var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer);
return _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Post, $"networks/{id}/disconnect", null, data, cancellationToken);
}
@@ -106,8 +103,7 @@ Task INetworkOperations.DeleteUnusedNetworksAsync(NetworksDeleteUnusedParameters
async Task INetworkOperations.PruneNetworksAsync(NetworksDeleteUnusedParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(null, HttpMethod.Post, "networks/prune", queryParameters, cancellationToken);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(null, HttpMethod.Post, "networks/prune", queryParameters, cancellationToken);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/PluginOperations.cs b/src/Docker.DotNet/Endpoints/PluginOperations.cs
index 472c302a9..80fc7e213 100644
--- a/src/Docker.DotNet/Endpoints/PluginOperations.cs
+++ b/src/Docker.DotNet/Endpoints/PluginOperations.cs
@@ -30,8 +30,7 @@ internal PluginOperations(DockerClient client)
public async Task> ListPluginsAsync(PluginListParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
{
IQueryString queryParameters = parameters == null ? null : new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins", queryParameters, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins", queryParameters, cancellationToken).ConfigureAwait(false);
}
public async Task> GetPluginPrivilegesAsync(PluginGetPrivilegeParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -42,8 +41,7 @@ internal PluginOperations(DockerClient client)
}
var query = new QueryString(parameters);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins/privileges", query, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins/privileges", query, cancellationToken).ConfigureAwait(false);
}
public Task InstallPluginAsync(PluginInstallParameters parameters, IProgress progress, CancellationToken cancellationToken = default(CancellationToken))
@@ -58,7 +56,7 @@ internal PluginOperations(DockerClient client)
throw new ArgumentNullException(nameof(parameters.Privileges));
}
- var data = new JsonRequestContent>(parameters.Privileges, _client.JsonSerializer);
+ var data = new JsonRequestContent>(parameters.Privileges, DockerClient.JsonSerializer);
IQueryString queryParameters = new QueryString(parameters);
return StreamUtil.MonitorStreamForMessagesAsync(
@@ -75,8 +73,7 @@ public async Task InspectPluginAsync(string name, CancellationToken canc
throw new ArgumentNullException(nameof(name));
}
- var response = await _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Get, $"plugins/{name}/json", cancellationToken);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Get, $"plugins/{name}/json", cancellationToken);
}
public Task RemovePluginAsync(string name, PluginRemoveParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -130,7 +127,7 @@ public async Task InspectPluginAsync(string name, CancellationToken canc
}
var query = new QueryString(parameters);
- var data = new JsonRequestContent>(parameters.Privileges, _client.JsonSerializer);
+ var data = new JsonRequestContent>(parameters.Privileges, DockerClient.JsonSerializer);
return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/upgrade", query, data, cancellationToken);
}
@@ -178,8 +175,8 @@ public async Task InspectPluginAsync(string name, CancellationToken canc
throw new ArgumentNullException(nameof(parameters.Args));
}
- var body = new JsonRequestContent>(parameters.Args, _client.JsonSerializer);
+ var body = new JsonRequestContent>(parameters.Args, DockerClient.JsonSerializer);
return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/set", null, body, cancellationToken);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/SecretsOperations.cs b/src/Docker.DotNet/Endpoints/SecretsOperations.cs
index 3c61a00cc..3145b52e0 100644
--- a/src/Docker.DotNet/Endpoints/SecretsOperations.cs
+++ b/src/Docker.DotNet/Endpoints/SecretsOperations.cs
@@ -18,8 +18,7 @@ internal SecretsOperations(DockerClient client)
async Task> ISecretsOperations.ListAsync(CancellationToken cancellationToken)
{
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "secrets", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject>(response.Body);
+ return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "secrets", cancellationToken).ConfigureAwait(false);
}
async Task ISecretsOperations.CreateAsync(SecretSpec body, CancellationToken cancellationToken)
@@ -29,9 +28,8 @@ async Task ISecretsOperations.CreateAsync(SecretSpec body,
throw new ArgumentNullException(nameof(body));
}
- var data = new JsonRequestContent(body, _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "secrets/create", null, data, cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(body, DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "secrets/create", null, data, cancellationToken).ConfigureAwait(false);
}
async Task ISecretsOperations.InspectAsync(string id, CancellationToken cancellationToken)
@@ -41,8 +39,7 @@ async Task ISecretsOperations.InspectAsync(string id, CancellationToken
throw new ArgumentNullException(nameof(id));
}
- var response = await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"secrets/{id}", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"secrets/{id}", cancellationToken).ConfigureAwait(false);
}
Task ISecretsOperations.DeleteAsync(string id, CancellationToken cancellationToken)
diff --git a/src/Docker.DotNet/Endpoints/StreamUtil.cs b/src/Docker.DotNet/Endpoints/StreamUtil.cs
index 92ea822e8..dbe9f2af9 100644
--- a/src/Docker.DotNet/Endpoints/StreamUtil.cs
+++ b/src/Docker.DotNet/Endpoints/StreamUtil.cs
@@ -4,7 +4,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using Newtonsoft.Json;
namespace Docker.DotNet.Models
{
@@ -28,16 +27,10 @@ internal static async Task MonitorStreamAsync(Task streamTask, DockerCli
internal static async Task MonitorStreamForMessagesAsync(Task streamTask, DockerClient client, CancellationToken cancellationToken, IProgress progress)
{
- var tcs = new TaskCompletionSource();
-
using (var stream = await streamTask)
- using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
- using (var jsonReader = new JsonTextReader(reader) { SupportMultipleContent = true })
- using (cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken)))
{
- while (await await Task.WhenAny(jsonReader.ReadAsync(cancellationToken), tcs.Task))
+ await foreach (var ev in DockerClient.JsonSerializer.DeserializeAsync(stream, cancellationToken))
{
- var ev = await client.JsonSerializer.Deserialize(jsonReader, cancellationToken);
progress.Report(ev);
}
}
diff --git a/src/Docker.DotNet/Endpoints/SwarmOperations.cs b/src/Docker.DotNet/Endpoints/SwarmOperations.cs
index e6215df37..a511708db 100644
--- a/src/Docker.DotNet/Endpoints/SwarmOperations.cs
+++ b/src/Docker.DotNet/Endpoints/SwarmOperations.cs
@@ -4,7 +4,6 @@ namespace Docker.DotNet
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
- using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Models;
@@ -32,21 +31,19 @@ async Task ISwarmOperations.CreateServiceAsync(ServiceCre
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
- var data = new JsonRequestContent(parameters.Service ?? throw new ArgumentNullException(nameof(parameters.Service)), _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "services/create", null, data, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var data = new JsonRequestContent(parameters.Service ?? throw new ArgumentNullException(nameof(parameters.Service)), DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "services/create", null, data, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.GetSwarmUnlockKeyAsync(CancellationToken cancellationToken)
{
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm/unlockkey", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm/unlockkey", cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.InitSwarmAsync(SwarmInitParameters parameters, CancellationToken cancellationToken)
{
- var data = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(
+ var data = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(
new ApiResponseErrorHandlingDelegate[]
{
(statusCode, responseBody) =>
@@ -63,27 +60,23 @@ async Task ISwarmOperations.InitSwarmAsync(SwarmInitParameters parameter
null,
data,
cancellationToken).ConfigureAwait(false);
-
- return response.Body;
}
async Task ISwarmOperations.InspectServiceAsync(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}", cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.InspectSwarmAsync(CancellationToken cancellationToken)
{
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm", cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.JoinSwarmAsync(SwarmJoinParameters parameters, CancellationToken cancellationToken)
{
- var data = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), _client.JsonSerializer);
+ var data = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), DockerClient.JsonSerializer);
await _client.MakeRequestAsync(
new ApiResponseErrorHandlingDelegate[]
{
@@ -127,10 +120,9 @@ await _client.MakeRequestAsync(
async Task> ISwarmOperations.ListServicesAsync(ServiceListParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters != null ? new QueryString(parameters) : null;
- var response = await _client
- .MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "services", queryParameters, cancellationToken)
+ return await _client
+ .MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "services", queryParameters, cancellationToken)
.ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
}
async Task ISwarmOperations.RemoveServiceAsync(string id, CancellationToken cancellationToken)
@@ -142,7 +134,7 @@ async Task ISwarmOperations.RemoveServiceAsync(string id, CancellationToken canc
async Task ISwarmOperations.UnlockSwarmAsync(SwarmUnlockParameters parameters, CancellationToken cancellationToken)
{
- var body = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), _client.JsonSerializer);
+ var body = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), DockerClient.JsonSerializer);
await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "swarm/unlock", null, body, cancellationToken).ConfigureAwait(false);
}
@@ -152,9 +144,8 @@ async Task ISwarmOperations.UpdateServiceAsync(string id,
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
var query = new QueryString(parameters);
- var body = new JsonRequestContent(parameters.Service ?? throw new ArgumentNullException(nameof(parameters.Service)), _client.JsonSerializer);
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"services/{id}/update", query, body, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ var body = new JsonRequestContent(parameters.Service ?? throw new ArgumentNullException(nameof(parameters.Service)), DockerClient.JsonSerializer);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"services/{id}/update", query, body, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false);
}
public Task GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
@@ -195,7 +186,7 @@ async Task ISwarmOperations.UpdateServiceAsync(string id,
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
{
var query = new QueryString(parameters ?? throw new ArgumentNullException(nameof(parameters)));
- var body = new JsonRequestContent(parameters.Spec ?? throw new ArgumentNullException(nameof(parameters.Spec)), _client.JsonSerializer);
+ var body = new JsonRequestContent(parameters.Spec ?? throw new ArgumentNullException(nameof(parameters.Spec)), DockerClient.JsonSerializer);
await _client.MakeRequestAsync(
new ApiResponseErrorHandlingDelegate[]
{
@@ -226,22 +217,20 @@ private IDictionary RegistryAuthHeaders(AuthConfig authConfig)
{
{
"X-Registry-Auth",
- Convert.ToBase64String(Encoding.UTF8.GetBytes(_client.JsonSerializer.SerializeObject(authConfig)))
+ Convert.ToBase64String(DockerClient.JsonSerializer.SerializeToUtf8Bytes(authConfig))
}
};
}
async Task> ISwarmOperations.ListNodesAsync(CancellationToken cancellationToken)
{
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "nodes", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "nodes", cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.InspectNodeAsync(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
- var response = await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"nodes/{id}", cancellationToken).ConfigureAwait(false);
- return _client.JsonSerializer.DeserializeObject(response.Body);
+ return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"nodes/{id}", cancellationToken).ConfigureAwait(false);
}
async Task ISwarmOperations.RemoveNodeAsync(string id, bool force, CancellationToken cancellationToken)
@@ -256,8 +245,8 @@ async Task ISwarmOperations.UpdateNodeAsync(string id, ulong version, NodeUpdate
{
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
var query = new EnumerableQueryString("version", new[] { version.ToString() });
- var body = new JsonRequestContent