diff --git a/src/Docker.DotNet/Endpoints/ConfigsOperations.cs b/src/Docker.DotNet/Endpoints/ConfigsOperations.cs index e1af40e7..d3712136 100644 --- a/src/Docker.DotNet/Endpoints/ConfigsOperations.cs +++ b/src/Docker.DotNet/Endpoints/ConfigsOperations.cs @@ -9,12 +9,13 @@ internal ConfigOperations(DockerClient client) _client = client; } - async Task> IConfigOperations.ListConfigsAsync(CancellationToken cancellationToken) + public async Task> ListConfigsAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken) + .ConfigureAwait(false); } - async Task IConfigOperations.CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken) + public async Task CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default) { if (body == null) { @@ -22,26 +23,30 @@ async Task IConfigOperations.CreateConfigAsync(SwarmC } var data = new JsonRequestContent(body.Config, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken) + .ConfigureAwait(false); } - async Task IConfigOperations.InspectConfigAsync(string id, CancellationToken cancellationToken) + public async Task InspectConfigAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken) + .ConfigureAwait(false); } - Task IConfigOperations.RemoveConfigAsync(string id, CancellationToken cancellationToken) + public async Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"configs/{id}", cancellationToken); + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"configs/{id}", cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ContainerOperations.cs b/src/Docker.DotNet/Endpoints/ContainerOperations.cs index c9eda1e7..967b06c1 100644 --- a/src/Docker.DotNet/Endpoints/ContainerOperations.cs +++ b/src/Docker.DotNet/Endpoints/ContainerOperations.cs @@ -32,26 +32,29 @@ public async Task> ListContainersAsync(ContainersLi throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "containers/json", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "containers/json", queryParameters, cancellationToken) + .ConfigureAwait(false); } public async Task CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken = default) { - IQueryString? qs = null; - if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } + IQueryString? queryParameters = null; if (!string.IsNullOrEmpty(parameters.Name)) { - qs = new QueryString(parameters); + queryParameters = new QueryString(parameters); } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync([NoSuchImageHandler], HttpMethod.Post, "containers/create", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } public async Task InspectContainerAsync(string id, CancellationToken cancellationToken = default) @@ -61,7 +64,8 @@ public async Task InspectContainerAsync(string id, Can throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/json", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/json", cancellationToken) + .ConfigureAwait(false); } public async Task InspectContainerAsync(string id, ContainerInspectParameters parameters, CancellationToken cancellationToken = default) @@ -76,8 +80,10 @@ public async Task InspectContainerAsync(string id, Con throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryString = new QueryString(parameters); - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/json", queryString, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/json", queryParameters, cancellationToken) + .ConfigureAwait(false); } public async Task ListProcessesAsync(string id, ContainerListProcessesParameters parameters, CancellationToken cancellationToken = default) @@ -92,8 +98,10 @@ public async Task ListProcessesAsync(string id, Cont throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/top", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/top", queryParameters, cancellationToken) + .ConfigureAwait(false); } public async Task GetContainerLogsAsync(string id, ContainerLogsParameters parameters, IProgress progress, CancellationToken cancellationToken = default) @@ -122,7 +130,7 @@ public async Task GetContainerLogsAsync(string id, ContainerL var containerInspectResponse = await InspectContainerAsync(id, cancellationToken) .ConfigureAwait(false); - var response = await _client.MakeRequestForStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/logs", queryParameters, null, null, cancellationToken) + var response = await _client.MakeRequestForStreamAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/logs", queryParameters, null, null, cancellationToken) .ConfigureAwait(false); return new MultiplexedStream(response, !containerInspectResponse.Config.Tty); @@ -135,21 +143,22 @@ public async Task> InspectChangesAsync( throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/changes", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/changes", cancellationToken) + .ConfigureAwait(false); } - public async Task ExportContainerAsync(string id, CancellationToken cancellationToken) + public async Task ExportContainerAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestForStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/export", cancellationToken) + return await _client.MakeRequestForStreamAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/export", cancellationToken) .ConfigureAwait(false); } - public async Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, CancellationToken cancellationToken) + public async Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -161,9 +170,9 @@ public async Task GetContainerStatsAsync(string id, ContainerStatsParame throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); - return await _client.MakeRequestForStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/stats", queryParameters, null, null, cancellationToken) + return await _client.MakeRequestForStreamAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/stats", queryParameters, null, null, cancellationToken) .ConfigureAwait(false); } @@ -184,15 +193,15 @@ public Task GetContainerStatsAsync(string id, ContainerStatsParameters parameter throw new ArgumentNullException(nameof(progress)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); return StreamUtil.MonitorStreamForMessagesAsync( - _client.MakeRequestForStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, $"containers/{id}/stats", queryParameters, null, null, cancellationToken), + _client.MakeRequestForStreamAsync([NoSuchContainerHandler], HttpMethod.Get, $"containers/{id}/stats", queryParameters, null, null, cancellationToken), progress, cancellationToken); } - public Task ResizeContainerTtyAsync(string id, ContainerResizeParameters parameters, CancellationToken cancellationToken = default) + public async Task ResizeContainerTtyAsync(string id, ContainerResizeParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -205,10 +214,12 @@ public Task ResizeContainerTtyAsync(string id, ContainerResizeParameters paramet } var queryParameters = new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/resize", queryParameters, cancellationToken); + + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/resize", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task StartContainerAsync(string id, ContainerStartParameters? parameters, CancellationToken cancellationToken = default) + public async Task StartContainerAsync(string id, ContainerStartParameters? parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -216,8 +227,12 @@ public async Task StartContainerAsync(string id, ContainerStartParameters? } 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); + + await _client.MakeRequestAsync([NoSuchContainerHandler, (statusCode, _) => result = statusCode != HttpStatusCode.NotModified], HttpMethod.Post, $"containers/{id}/start", queryParameters, cancellationToken) + .ConfigureAwait(false); + return result ?? throw new InvalidOperationException(); } @@ -234,14 +249,18 @@ public async Task StopContainerAsync(string id, ContainerStopParameters pa } var queryParameters = new QueryString(parameters); + + bool? result = null; + // since specified wait timespan can be greater than HttpClient's default, we set the // client timeout to infinite and provide a cancellation token. - 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); + await _client.MakeRequestAsync([NoSuchContainerHandler, (statusCode, _) => result = statusCode != HttpStatusCode.NotModified], HttpMethod.Post, $"containers/{id}/stop", queryParameters, null, null, Timeout.InfiniteTimeSpan, cancellationToken) + .ConfigureAwait(false); + return result ?? throw new InvalidOperationException(); } - public Task RestartContainerAsync(string id, ContainerRestartParameters parameters, CancellationToken cancellationToken = default) + public async Task RestartContainerAsync(string id, ContainerRestartParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -253,14 +272,15 @@ public Task RestartContainerAsync(string id, ContainerRestartParameters paramete throw new ArgumentNullException(nameof(parameters)); } + var queryParameters = new QueryString(parameters); - IQueryString 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. - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/restart", queryParameters, null, null, TimeSpan.FromMilliseconds(Timeout.Infinite), cancellationToken); + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/restart", queryParameters, null, null, Timeout.InfiniteTimeSpan, cancellationToken) + .ConfigureAwait(false); } - public Task KillContainerAsync(string id, ContainerKillParameters parameters, CancellationToken cancellationToken = default) + public async Task KillContainerAsync(string id, ContainerKillParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -272,11 +292,13 @@ public Task KillContainerAsync(string id, ContainerKillParameters parameters, Ca throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/kill", queryParameters, cancellationToken); + var queryParameters = new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/kill", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task RenameContainerAsync(string id, ContainerRenameParameters parameters, CancellationToken cancellationToken) + public async Task RenameContainerAsync(string id, ContainerRenameParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -284,27 +306,31 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters } var queryParameters = new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/rename", queryParameters, cancellationToken); + + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/rename", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task PauseContainerAsync(string id, CancellationToken cancellationToken = default) + public async Task PauseContainerAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/pause", cancellationToken); + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/pause", cancellationToken) + .ConfigureAwait(false); } - public Task UnpauseContainerAsync(string id, CancellationToken cancellationToken = default) + public async Task UnpauseContainerAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/unpause", cancellationToken); + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/unpause", cancellationToken) + .ConfigureAwait(false); } public async Task AttachContainerAsync(string id, ContainerAttachParameters parameters, CancellationToken cancellationToken = default) @@ -324,7 +350,7 @@ public async Task AttachContainerAsync(string id, ContainerAt var containerInspectResponse = await InspectContainerAsync(id, cancellationToken) .ConfigureAwait(false); - var response = await _client.MakeRequestForHijackedStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/attach", queryParameters, null, null, cancellationToken) + var response = await _client.MakeRequestForHijackedStreamAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/attach", queryParameters, null, null, cancellationToken) .ConfigureAwait(false); return new MultiplexedStream(response, !containerInspectResponse.Config.Tty); @@ -337,10 +363,11 @@ public async Task WaitContainerAsync(string id, Cancellat throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/wait", null, null, null, Timeout.InfiniteTimeSpan, cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/wait", null, null, null, Timeout.InfiniteTimeSpan, cancellationToken) + .ConfigureAwait(false); } - public Task RemoveContainerAsync(string id, ContainerRemoveParameters parameters, CancellationToken cancellationToken = default) + public async Task RemoveContainerAsync(string id, ContainerRemoveParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -352,8 +379,10 @@ public Task RemoveContainerAsync(string id, ContainerRemoveParameters parameters throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Delete, $"containers/{id}", queryParameters, cancellationToken); + var queryParameters = new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Delete, $"containers/{id}", queryParameters, cancellationToken) + .ConfigureAwait(false); } public async Task GetArchiveFromContainerAsync(string id, ContainerPathStatParameters parameters, bool statOnly, CancellationToken cancellationToken = default) @@ -370,9 +399,9 @@ public async Task GetArchiveFromContainerAsync(string Stream? stream; - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); - var response = await _client.MakeRequestForStreamedResponseAsync(new[] { NoSuchContainerHandler }, statOnly ? HttpMethod.Head : HttpMethod.Get, $"containers/{id}/archive", queryParameters, cancellationToken); + var response = await _client.MakeRequestForStreamedResponseAsync([NoSuchContainerHandler], statOnly ? HttpMethod.Head : HttpMethod.Get, $"containers/{id}/archive", queryParameters, cancellationToken); var statHeader = response.Headers.GetValues("X-Docker-Container-Path-Stat").First(); @@ -397,7 +426,7 @@ public async Task GetArchiveFromContainerAsync(string }; } - public Task ExtractArchiveToContainerAsync(string id, CopyToContainerParameters parameters, Stream stream, CancellationToken cancellationToken = default) + public async Task ExtractArchiveToContainerAsync(string id, CopyToContainerParameters parameters, Stream stream, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -409,16 +438,20 @@ public Task ExtractArchiveToContainerAsync(string id, CopyToContainerParameters throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); var data = new BinaryRequestContent(stream, "application/x-tar"); - return _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Put, $"containers/{id}/archive", queryParameters, data, cancellationToken); + + await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Put, $"containers/{id}/archive", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } - public async Task PruneContainersAsync(ContainersPruneParameters? parameters, CancellationToken cancellationToken) + public async Task PruneContainersAsync(ContainersPruneParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "containers/prune", queryParameters, cancellationToken).ConfigureAwait(false); + + 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) @@ -434,6 +467,8 @@ public async Task UpdateContainerAsync(string id, Conta } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/update", null, data, cancellationToken); + + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Post, $"containers/{id}/update", null, data, cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ExecOperations.cs b/src/Docker.DotNet/Endpoints/ExecOperations.cs index 221ff6e2..afdf8de0 100644 --- a/src/Docker.DotNet/Endpoints/ExecOperations.cs +++ b/src/Docker.DotNet/Endpoints/ExecOperations.cs @@ -24,7 +24,7 @@ public async Task InspectContainerExecAsync(string throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"exec/{id}/json", null, cancellationToken) + return await _client.MakeRequestAsync([NoSuchContainerHandler], HttpMethod.Get, $"exec/{id}/json", cancellationToken) .ConfigureAwait(false); } diff --git a/src/Docker.DotNet/Endpoints/IConfigsOperations.cs b/src/Docker.DotNet/Endpoints/IConfigsOperations.cs index fdd8a52f..7ba42039 100644 --- a/src/Docker.DotNet/Endpoints/IConfigsOperations.cs +++ b/src/Docker.DotNet/Endpoints/IConfigsOperations.cs @@ -9,7 +9,7 @@ public interface IConfigOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListConfigsAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task> ListConfigsAsync(CancellationToken cancellationToken = default); /// /// Create a configs @@ -20,7 +20,7 @@ public interface IConfigOperations /// 409 - Name conflicts with an existing object. /// 500 - Server error. /// - Task CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default); /// /// Inspect a configs @@ -32,7 +32,7 @@ public interface IConfigOperations /// 500 - Server error. /// /// ID of the config. - Task InspectConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectConfigAsync(string id, CancellationToken cancellationToken = default); /// /// Remove a configs @@ -43,5 +43,5 @@ public interface IConfigOperations /// 500 - Server error. /// /// ID of the config. - Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/IContainerOperations.cs b/src/Docker.DotNet/Endpoints/IContainerOperations.cs index 7f4e2be2..0c941d91 100644 --- a/src/Docker.DotNet/Endpoints/IContainerOperations.cs +++ b/src/Docker.DotNet/Endpoints/IContainerOperations.cs @@ -148,8 +148,8 @@ public interface IContainerOperations /// One or more of the inputs was . /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - [Obsolete("Use 'Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, CancellationToken cancellationToken, IProgress progress)'")] - Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, CancellationToken cancellationToken); + [Obsolete("Use 'Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, IProgress progress, CancellationToken cancellationToken)'")] + Task GetContainerStatsAsync(string id, ContainerStatsParameters parameters, CancellationToken cancellationToken = default); /// /// Retrieves a live, raw stream of the container's resource usage statistics. @@ -196,7 +196,7 @@ public interface IContainerOperations /// One or more of the inputs was . /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task StartContainerAsync(string id, ContainerStartParameters parameters, CancellationToken cancellationToken = default); + Task StartContainerAsync(string id, ContainerStartParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Stops a container. @@ -257,7 +257,7 @@ public interface IContainerOperations /// One or more of the inputs was . /// The name is already in use, the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task RenameContainerAsync(string id, ContainerRenameParameters parameters, CancellationToken cancellationToken); + Task RenameContainerAsync(string id, ContainerRenameParameters parameters, CancellationToken cancellationToken = default); /// /// Suspends a container. @@ -381,7 +381,7 @@ public interface IContainerOperations /// One or more of the inputs was . /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task PruneContainersAsync(ContainersPruneParameters parameters = null, CancellationToken cancellationToken = default); + Task PruneContainersAsync(ContainersPruneParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Changes configuration options of a container without recreating it. diff --git a/src/Docker.DotNet/Endpoints/IImageOperations.cs b/src/Docker.DotNet/Endpoints/IImageOperations.cs index 8315d1a3..7fefeef1 100644 --- a/src/Docker.DotNet/Endpoints/IImageOperations.cs +++ b/src/Docker.DotNet/Endpoints/IImageOperations.cs @@ -13,7 +13,7 @@ public interface IImageOperations /// One or more of the inputs was . /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task> ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task> ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken = default); /// /// Builds an image from a tar archive that contains a Dockerfile. @@ -42,7 +42,7 @@ public interface IImageOperations /// One or more of the inputs was . /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Stream contents, IEnumerable authConfigs, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Stream contents, IEnumerable? authConfigs, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default); /// /// Builds an image from a tar archive that contains a Dockerfile. @@ -66,7 +66,7 @@ public interface IImageOperations /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. [Obsolete("This method does not wait for build to complete. Use new BuildImageFromDockerfileAsync(contents, parameters, authConfigs, headers, progress, cancellationToken, instead.)", false)] - Task BuildImageFromDockerfileAsync(Stream contents, ImageBuildParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task BuildImageFromDockerfileAsync(Stream contents, ImageBuildParameters parameters, CancellationToken cancellationToken = default); /// /// Creates an image by either pulling it from a registry or importing it. @@ -82,7 +82,7 @@ public interface IImageOperations /// current auth status, the input is invalid, or the daemon experienced an error. /// /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default); /// /// Creates an image by either pulling it from a registry or importing it. @@ -99,7 +99,7 @@ public interface IImageOperations /// current auth status, the input is invalid, or the daemon experienced an error. /// /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default); /// /// Creates an image by importing it from a stream. @@ -116,7 +116,7 @@ public interface IImageOperations /// current auth status, the input is invalid, or the daemon experienced an error. /// /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateImageAsync(ImagesCreateParameters parameters, Stream? imageStream, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default); /// /// Creates an image by importing it from a stream. @@ -134,7 +134,7 @@ public interface IImageOperations /// current auth status, the input is invalid, or the daemon experienced an error. /// /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateImageAsync(ImagesCreateParameters parameters, Stream? imageStream, AuthConfig authConfig, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default); /// /// Retrieves low-level information about an image. @@ -148,7 +148,7 @@ public interface IImageOperations /// No such image was found. /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task InspectImageAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectImageAsync(string name, CancellationToken cancellationToken = default); /// /// Gets the "history" (parent layers) of an image. @@ -162,7 +162,7 @@ public interface IImageOperations /// No such image was found. /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task> GetImageHistoryAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetImageHistoryAsync(string name, CancellationToken cancellationToken = default); /// /// Pushes an image to a registry. @@ -184,7 +184,7 @@ public interface IImageOperations /// No such image was found. /// The input is invalid or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default); /// /// Tags an image so that it becomes part of a registry. @@ -200,7 +200,7 @@ public interface IImageOperations /// No such image was found. /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task TagImageAsync(string name, ImageTagParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task TagImageAsync(string name, ImageTagParameters parameters, CancellationToken cancellationToken = default); /// /// Removes an image, along with any untagged parent images that were referenced by that image. @@ -219,7 +219,7 @@ public interface IImageOperations /// No such image was found. /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task>> DeleteImageAsync(string name, ImageDeleteParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task>> DeleteImageAsync(string name, ImageDeleteParameters parameters, CancellationToken cancellationToken = default); /// /// Searchs for an image on Docker Hub. @@ -232,7 +232,7 @@ public interface IImageOperations /// One or more of the inputs was . /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task> SearchImagesAsync(ImagesSearchParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task> SearchImagesAsync(ImagesSearchParameters parameters, CancellationToken cancellationToken = default); /// /// Deletes unused images. @@ -245,7 +245,7 @@ public interface IImageOperations /// One or more of the inputs was . /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task PruneImagesAsync(ImagesPruneParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task PruneImagesAsync(ImagesPruneParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Create a new image from a container. @@ -259,7 +259,7 @@ public interface IImageOperations /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// No such container was found. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task CommitContainerChangesAsync(CommitContainerChangesParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task CommitContainerChangesAsync(CommitContainerChangesParameters parameters, CancellationToken cancellationToken = default); /// /// Exports an image and its associated metadata as a tarball. @@ -275,7 +275,7 @@ public interface IImageOperations /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// No such image was found. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task SaveImageAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task SaveImageAsync(string name, CancellationToken cancellationToken = default); /// /// Exports multiple images and their associated metadata to a single tarball. @@ -296,7 +296,7 @@ public interface IImageOperations /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// No such image was found. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task SaveImagesAsync(string[] names, CancellationToken cancellationToken = default(CancellationToken)); + Task SaveImagesAsync(string[]? names, CancellationToken cancellationToken = default); /// /// Loads a set of images and tags into a Docker repository. @@ -311,5 +311,5 @@ public interface IImageOperations /// One or more of the inputs was . /// There was a conflict, or the input is invalid, or the daemon experienced an error. /// The request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout. - Task LoadImageAsync(ImageLoadParameters parameters, Stream imageStream, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task LoadImageAsync(ImageLoadParameters parameters, Stream imageStream, IProgress progress, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/INetworkOperations.cs b/src/Docker.DotNet/Endpoints/INetworkOperations.cs index ce6aa34a..d804eae2 100644 --- a/src/Docker.DotNet/Endpoints/INetworkOperations.cs +++ b/src/Docker.DotNet/Endpoints/INetworkOperations.cs @@ -11,7 +11,7 @@ public interface INetworkOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListNetworksAsync(NetworksListParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task> ListNetworksAsync(NetworksListParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Inspect a network. @@ -23,7 +23,7 @@ public interface INetworkOperations /// 404 - Network not found. /// /// Network ID or name. - Task InspectNetworkAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectNetworkAsync(string id, CancellationToken cancellationToken = default); /// /// Remove a network. @@ -36,7 +36,7 @@ public interface INetworkOperations /// 500 - Server error. /// /// Network ID or name. - Task DeleteNetworkAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task DeleteNetworkAsync(string id, CancellationToken cancellationToken = default); /// /// Create a network. @@ -49,7 +49,7 @@ public interface INetworkOperations /// 404 - Plugin not found. /// 500 - Server error. /// - Task CreateNetworkAsync(NetworksCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateNetworkAsync(NetworksCreateParameters parameters, CancellationToken cancellationToken = default); /// /// Connect a container to a network. @@ -63,7 +63,7 @@ public interface INetworkOperations /// 500 - Server error. /// /// Network ID or name. - Task ConnectNetworkAsync(string id, NetworkConnectParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task ConnectNetworkAsync(string id, NetworkConnectParameters parameters, CancellationToken cancellationToken = default); /// /// Disconnect a container from a network. @@ -77,7 +77,7 @@ public interface INetworkOperations /// 404 - Network or container not found. /// 500 - Server error. /// - Task DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters, CancellationToken cancellationToken = default); /// /// Delete unused networks. @@ -94,7 +94,7 @@ public interface INetworkOperations /// 500 - Server error. /// [Obsolete("Use INetworkOperations.PruneNetworksAsync")] - Task DeleteUnusedNetworksAsync(NetworksDeleteUnusedParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task DeleteUnusedNetworksAsync(NetworksDeleteUnusedParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Delete unused networks. @@ -110,5 +110,5 @@ public interface INetworkOperations /// 404 - Network or container not found. /// 500 - Server error. /// - Task PruneNetworksAsync(NetworksDeleteUnusedParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task PruneNetworksAsync(NetworksDeleteUnusedParameters? parameters = null, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/IPluginOperations.cs b/src/Docker.DotNet/Endpoints/IPluginOperations.cs index ad2ba744..03ea9357 100644 --- a/src/Docker.DotNet/Endpoints/IPluginOperations.cs +++ b/src/Docker.DotNet/Endpoints/IPluginOperations.cs @@ -15,7 +15,7 @@ public interface IPluginOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListPluginsAsync(PluginListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task> ListPluginsAsync(PluginListParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Get plugin privileges. @@ -28,7 +28,7 @@ public interface IPluginOperations /// 200 - No error. /// 500 - Server error. /// - Task> GetPrivilegesAsync(PluginGetPrivilegeParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetPrivilegesAsync(PluginGetPrivilegeParameters parameters, CancellationToken cancellationToken = default); /// /// Install a plugin. @@ -43,7 +43,7 @@ public interface IPluginOperations /// 204 - No error. /// 500 - Server error. /// - Task InstallPluginAsync(PluginInstallParameters parameters, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task InstallPluginAsync(PluginInstallParameters parameters, IProgress progress, CancellationToken cancellationToken = default); /// /// Inspect a plugin. @@ -58,7 +58,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task InspectPluginAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectPluginAsync(string name, CancellationToken cancellationToken = default); /// /// Remove a plugin. @@ -73,7 +73,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task RemovePluginAsync(string name, PluginRemoveParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task RemovePluginAsync(string name, PluginRemoveParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Enable a plugin. @@ -88,7 +88,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task EnablePluginAsync(string name, PluginEnableParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task EnablePluginAsync(string name, PluginEnableParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Disable a plugin. @@ -103,7 +103,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task DisablePluginAsync(string name, PluginDisableParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task DisablePluginAsync(string name, PluginDisableParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Upgrade a plugin. @@ -118,7 +118,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task UpgradePluginAsync(string name, PluginUpgradeParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task UpgradePluginAsync(string name, PluginUpgradeParameters parameters, CancellationToken cancellationToken = default); /// /// Create a plugin. @@ -131,7 +131,7 @@ public interface IPluginOperations /// 200 - No error. /// 500 - Server error. /// - Task CreatePluginAsync(PluginCreateParameters parameters, Stream plugin, CancellationToken cancellationToken = default(CancellationToken)); + Task CreatePluginAsync(PluginCreateParameters parameters, Stream plugin, CancellationToken cancellationToken = default); /// /// Push a plugin. @@ -148,7 +148,7 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task PushPluginAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task PushPluginAsync(string name, CancellationToken cancellationToken = default); /// /// Configure a plugin. @@ -163,5 +163,5 @@ public interface IPluginOperations /// 500 - Server error. /// /// The name of the plugin. The `:latest` tag is optional, and is the default if omitted. - Task ConfigurePluginAsync(string name, PluginConfigureParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task ConfigurePluginAsync(string name, PluginConfigureParameters parameters, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ISecretsOperations.cs b/src/Docker.DotNet/Endpoints/ISecretsOperations.cs index 7dcb8bec..e2290a24 100644 --- a/src/Docker.DotNet/Endpoints/ISecretsOperations.cs +++ b/src/Docker.DotNet/Endpoints/ISecretsOperations.cs @@ -9,7 +9,7 @@ public interface ISecretsOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task> ListAsync(CancellationToken cancellationToken = default); /// /// Create a secret @@ -20,7 +20,7 @@ public interface ISecretsOperations /// 409 - Name conflicts with an existing object. /// 500 - Server error. /// - Task CreateAsync(SwarmSecretSpec body, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(SwarmSecretSpec body, CancellationToken cancellationToken = default); /// /// Inspect a secret @@ -32,7 +32,7 @@ public interface ISecretsOperations /// 500 - Server error. /// /// ID of the secret. - Task InspectAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectAsync(string id, CancellationToken cancellationToken = default); /// /// Delete a secret @@ -43,5 +43,5 @@ public interface ISecretsOperations /// 500 - Server error. /// /// ID of the secret. - Task DeleteAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task DeleteAsync(string id, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ISwarmOperations.cs b/src/Docker.DotNet/Endpoints/ISwarmOperations.cs index 4d2b5a8c..1648e5ee 100644 --- a/src/Docker.DotNet/Endpoints/ISwarmOperations.cs +++ b/src/Docker.DotNet/Endpoints/ISwarmOperations.cs @@ -12,7 +12,7 @@ public interface ISwarmOperations /// 500 - Server Error. /// 503 - Node is not part of a swarm. /// - Task GetSwarmUnlockKeyAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task GetSwarmUnlockKeyAsync(CancellationToken cancellationToken = default); /// /// Initialize a new swarm. @@ -25,7 +25,7 @@ public interface ISwarmOperations /// /// The join parameters. /// The node id. - Task InitSwarmAsync(SwarmInitParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task InitSwarmAsync(SwarmInitParameters parameters, CancellationToken cancellationToken = default); /// /// Inspect swarm. @@ -36,7 +36,7 @@ public interface ISwarmOperations /// 500 - Server Error. /// 503 - Node is not part of a swarm. /// - Task InspectSwarmAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task InspectSwarmAsync(CancellationToken cancellationToken = default); /// /// Join an existing swarm. @@ -47,7 +47,7 @@ public interface ISwarmOperations /// 503 - Node is already part of a swarm. /// /// The join parameters. - Task JoinSwarmAsync(SwarmJoinParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task JoinSwarmAsync(SwarmJoinParameters parameters, CancellationToken cancellationToken = default); /// /// Leave a swarm. @@ -58,7 +58,7 @@ public interface ISwarmOperations /// 503 - Node not part of a swarm. /// /// The leave parameters. - Task LeaveSwarmAsync(SwarmLeaveParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task LeaveSwarmAsync(SwarmLeaveParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Unlock a locked manager. @@ -69,7 +69,7 @@ public interface ISwarmOperations /// 503 - Node is not part of a swarm. /// /// The swarm's unlock key. - Task UnlockSwarmAsync(SwarmUnlockParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task UnlockSwarmAsync(SwarmUnlockParameters parameters, CancellationToken cancellationToken = default); /// /// Update a swarm. @@ -81,7 +81,7 @@ public interface ISwarmOperations /// 503 - Node is not part of a swarm. /// /// The update parameters. - Task UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken = default); #endregion Swarm @@ -98,7 +98,7 @@ public interface ISwarmOperations /// 500 - Server error. /// 503 - Node is not part of a swarm. /// - Task CreateServiceAsync(ServiceCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateServiceAsync(ServiceCreateParameters parameters, CancellationToken cancellationToken = default); /// /// Inspect a service. @@ -111,7 +111,7 @@ public interface ISwarmOperations /// /// ID or name of service. /// The service spec. - Task InspectServiceAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectServiceAsync(string id, CancellationToken cancellationToken = default); /// /// List services with optional serviceFilters. @@ -121,7 +121,7 @@ public interface ISwarmOperations /// 500 - Server error. /// 503 - Node is not part of a swarm. /// - Task> ListServicesAsync(ServiceListParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task> ListServicesAsync(ServiceListParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Update a service. @@ -135,7 +135,7 @@ public interface ISwarmOperations /// /// ID or name of service. /// The service spec. - Task UpdateServiceAsync(string id, ServiceUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task UpdateServiceAsync(string id, ServiceUpdateParameters parameters, CancellationToken cancellationToken = default); /// /// Delete a service. @@ -147,7 +147,7 @@ public interface ISwarmOperations /// 503 - Node is not part of a swarm. /// /// ID or name of service. - Task RemoveServiceAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveServiceAsync(string id, CancellationToken cancellationToken = default); /// /// Gets stdout and stderr logs from services. @@ -167,7 +167,7 @@ public interface ISwarmOperations /// 500 - Server error. /// 503 - Node is not part of a swarm. /// - Task GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default); /// /// Gets stdout and stderr logs from services. @@ -183,7 +183,7 @@ public interface ISwarmOperations /// /// This method is only suited for services with the json-file or journald logging driver. /// - Task GetServiceLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task GetServiceLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default); #endregion Services @@ -198,7 +198,7 @@ public interface ISwarmOperations /// 503 - Node is not part of a swarm. /// /// - Task> ListNodesAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task> ListNodesAsync(CancellationToken cancellationToken = default); /// /// Inspect a node. @@ -209,7 +209,7 @@ public interface ISwarmOperations /// 500 - Server error. /// 503 - Node is not part of a swarm. /// - Task InspectNodeAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectNodeAsync(string id, CancellationToken cancellationToken = default); /// /// Delete a node. @@ -220,7 +220,7 @@ public interface ISwarmOperations /// 500 - Server error. /// 503 - Node is not part of a swarm. /// - Task RemoveNodeAsync(string id, bool force, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveNodeAsync(string id, bool? force = null, CancellationToken cancellationToken = default); /// /// Update node. @@ -234,7 +234,7 @@ public interface ISwarmOperations /// ID or name of the node. /// Current version of the node object. /// Parameters to update. - Task UpdateNodeAsync(string id, ulong version, NodeUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task UpdateNodeAsync(string id, ulong version, NodeUpdateParameters parameters, CancellationToken cancellationToken = default); #endregion } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ISystemOperations.cs b/src/Docker.DotNet/Endpoints/ISystemOperations.cs index 94a2fdec..8ee5811e 100644 --- a/src/Docker.DotNet/Endpoints/ISystemOperations.cs +++ b/src/Docker.DotNet/Endpoints/ISystemOperations.cs @@ -12,7 +12,7 @@ public interface ISystemOperations /// 204 - No error. /// 500 - Server error. /// - Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)); + Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default); /// /// Get version. @@ -25,7 +25,7 @@ public interface ISystemOperations /// 200 - No error. /// 500 - Server error. /// - Task GetVersionAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task GetVersionAsync(CancellationToken cancellationToken = default); /// /// Ping. @@ -36,7 +36,7 @@ public interface ISystemOperations /// 200 - No error. /// 500 - Server error. /// - Task PingAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task PingAsync(CancellationToken cancellationToken = default); /// /// Get system information. @@ -47,10 +47,10 @@ public interface ISystemOperations /// 200 - No error. /// 500 - Server error. /// - Task GetSystemInfoAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task GetSystemInfoAsync(CancellationToken cancellationToken = default); - [Obsolete("Use 'Task MonitorEventsAsync(ContainerEventsParameters parameters, CancellationToken cancellationToken, IProgress progress)'")] - Task MonitorEventsAsync(ContainerEventsParameters parameters, CancellationToken cancellationToken); + [Obsolete("Use 'Task MonitorEventsAsync(ContainerEventsParameters parameters, IProgress progress, CancellationToken cancellationToken)'")] + Task MonitorEventsAsync(ContainerEventsParameters parameters, CancellationToken cancellationToken = default); /// /// Monitor events. @@ -73,5 +73,5 @@ public interface ISystemOperations /// 200 - No error. /// 500 - Server error. /// - Task MonitorEventsAsync(ContainerEventsParameters parameters, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)); + Task MonitorEventsAsync(ContainerEventsParameters parameters, IProgress progress, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ITasksOperations.cs b/src/Docker.DotNet/Endpoints/ITasksOperations.cs index 3b5926ae..8b488585 100644 --- a/src/Docker.DotNet/Endpoints/ITasksOperations.cs +++ b/src/Docker.DotNet/Endpoints/ITasksOperations.cs @@ -14,7 +14,7 @@ public interface ITasksOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task> ListAsync(CancellationToken cancellationToken = default); /// /// List tasks @@ -25,7 +25,7 @@ public interface ITasksOperations /// 200 - No error. /// 500 - Server error. /// - Task> ListAsync(TasksListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task> ListAsync(TasksListParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Inspect a task @@ -38,5 +38,5 @@ public interface ITasksOperations /// 500 - Server error. /// /// ID of the task. - Task InspectAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectAsync(string id, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/IVolumeOperations.cs b/src/Docker.DotNet/Endpoints/IVolumeOperations.cs index 47ef9201..c87b458e 100644 --- a/src/Docker.DotNet/Endpoints/IVolumeOperations.cs +++ b/src/Docker.DotNet/Endpoints/IVolumeOperations.cs @@ -9,7 +9,7 @@ public interface IVolumeOperations /// 200 - No error. /// 500 - Server error. /// - Task ListAsync(CancellationToken cancellationToken = default(CancellationToken)); + Task ListAsync(CancellationToken cancellationToken = default); /// /// List volumes @@ -18,7 +18,7 @@ public interface IVolumeOperations /// 200 - No error. /// 500 - Server error. /// - Task ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task ListAsync(VolumesListParameters? parameters = null, CancellationToken cancellationToken = default); /// /// Create a volume. @@ -28,7 +28,7 @@ public interface IVolumeOperations /// 500 - Server error. /// /// Volume parameters to create. - Task CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken = default); /// /// Inspect a volume. @@ -39,7 +39,7 @@ public interface IVolumeOperations /// 500 - Server error. /// /// Volume name or ID. - Task InspectAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task InspectAsync(string name, CancellationToken cancellationToken = default); /// /// Remove a volume. @@ -54,7 +54,7 @@ public interface IVolumeOperations /// /// Volume name or ID. /// Force the removal of the volume. - Task RemoveAsync(string name, bool? force = null, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveAsync(string name, bool? force = null, CancellationToken cancellationToken = default); /// /// Delete unused volumes. @@ -65,5 +65,5 @@ public interface IVolumeOperations /// 200 - No error. /// 500 - Server error. /// - Task PruneAsync(VolumesPruneParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken)); + Task PruneAsync(VolumesPruneParameters? parameters = null, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/ImageOperations.cs b/src/Docker.DotNet/Endpoints/ImageOperations.cs index f6d6abe6..aad92789 100644 --- a/src/Docker.DotNet/Endpoints/ImageOperations.cs +++ b/src/Docker.DotNet/Endpoints/ImageOperations.cs @@ -25,18 +25,20 @@ internal ImageOperations(DockerClient client) _client = client; } - public async Task> ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/json", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/json", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task BuildImageFromDockerfileAsync(Stream contents, ImageBuildParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task BuildImageFromDockerfileAsync(Stream contents, ImageBuildParameters parameters, CancellationToken cancellationToken = default) { if (contents == null) { @@ -48,7 +50,7 @@ internal ImageOperations(DockerClient client) throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); var data = new BinaryRequestContent(contents, TarContentType); @@ -56,7 +58,7 @@ internal ImageOperations(DockerClient client) .ConfigureAwait(false); } - public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Stream contents, IEnumerable authConfigs, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default) + public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Stream contents, IEnumerable? authConfigs, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default) { if (contents == null) { @@ -68,97 +70,96 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea throw new ArgumentNullException(nameof(parameters)); } - HttpMethod httpMethod = HttpMethod.Post; + var queryParameters = new QueryString(parameters); var data = new BinaryRequestContent(contents, TarContentType); - IQueryString queryParameters = new QueryString(parameters); - - Dictionary customHeaders = RegistryConfigHeaders(authConfigs); + var customHeaders = RegistryConfigHeaders(authConfigs); if (headers != null) { - foreach (string key in headers.Keys) + foreach (var key in headers.Keys) { customHeaders[key] = headers[key]; } } return StreamUtil.MonitorResponseForMessagesAsync( - _client.MakeRequestForRawResponseAsync(httpMethod, "build", queryParameters, data, customHeaders, cancellationToken), + _client.MakeRequestForRawResponseAsync(HttpMethod.Post, "build", queryParameters, data, customHeaders, cancellationToken), progress, cancellationToken); } - public Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default) { - return CreateImageAsync(parameters, null, authConfig, progress, cancellationToken); + return CreateImageAsync(parameters, null, authConfig, null, progress, cancellationToken); } - public Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default) { return CreateImageAsync(parameters, null, authConfig, headers, progress, cancellationToken); } - public Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateImageAsync(ImagesCreateParameters parameters, Stream? imageStream, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default) { return CreateImageAsync(parameters, imageStream, authConfig, null, progress, cancellationToken); } - public Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IDictionary headers, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateImageAsync(ImagesCreateParameters parameters, Stream? imageStream, AuthConfig authConfig, IDictionary? headers, IProgress progress, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } - HttpMethod httpMethod = HttpMethod.Post; - BinaryRequestContent content = null; + BinaryRequestContent? content = null; if (imageStream != null) { content = new BinaryRequestContent(imageStream, TarContentType); parameters.FromSrc = ImportFromBodySource; } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); - Dictionary customHeaders = RegistryAuthHeaders(authConfig); + var customHeaders = RegistryAuthHeaders(authConfig); - if(headers != null) + if (headers != null) { - foreach(var key in headers.Keys) + foreach (var key in headers.Keys) { customHeaders[key] = headers[key]; } } return StreamUtil.MonitorResponseForMessagesAsync( - _client.MakeRequestForRawResponseAsync(httpMethod, "images/create", queryParameters, content, customHeaders, cancellationToken), + _client.MakeRequestForRawResponseAsync(HttpMethod.Post, "images/create", queryParameters, content, customHeaders, cancellationToken), progress, cancellationToken); } - public async Task InspectImageAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) + public async Task InspectImageAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/json", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchImageHandler], HttpMethod.Get, $"images/{name}/json", cancellationToken) + .ConfigureAwait(false); } - public async Task> GetImageHistoryAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetImageHistoryAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return await _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, $"images/{name}/history", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchImageHandler], HttpMethod.Get, $"images/{name}/history", cancellationToken) + .ConfigureAwait(false); } - public Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress progress, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -170,7 +171,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); return StreamUtil.MonitorStreamForMessagesAsync( _client.MakeRequestForStreamAsync(_client.NoErrorHandlers, HttpMethod.Post, $"images/{name}/push", queryParameters, null, RegistryAuthHeaders(authConfig), cancellationToken), @@ -178,7 +179,7 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea cancellationToken); } - public Task TagImageAsync(string name, ImageTagParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task TagImageAsync(string name, ImageTagParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -190,11 +191,13 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Post, $"images/{name}/tag", queryParameters, cancellationToken); + var queryParameters = new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchImageHandler], HttpMethod.Post, $"images/{name}/tag", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task>> DeleteImageAsync(string name, ImageDeleteParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task>> DeleteImageAsync(string name, ImageDeleteParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -206,59 +209,67 @@ public Task BuildImageFromDockerfileAsync(ImageBuildParameters parameters, Strea throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync[]>(new[] { NoSuchImageHandler }, HttpMethod.Delete, $"images/{name}", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync[]>([NoSuchImageHandler], HttpMethod.Delete, $"images/{name}", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task> SearchImagesAsync(ImagesSearchParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> SearchImagesAsync(ImagesSearchParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/search", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "images/search", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task PruneImagesAsync(ImagesPruneParameters parameters, CancellationToken cancellationToken) + public async Task PruneImagesAsync(ImagesPruneParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "images/prune", queryParameters, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "images/prune", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task CommitContainerChangesAsync(CommitContainerChangesParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task CommitContainerChangesAsync(CommitContainerChangesParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } + var queryParameters = new QueryString(parameters); + var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - IQueryString queryParameters = new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "commit", queryParameters, data, cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "commit", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } - public Task SaveImageAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) + public Task SaveImageAsync(string name, CancellationToken cancellationToken = default) { - return SaveImagesAsync(new[] { name }, cancellationToken); + return SaveImagesAsync([name], cancellationToken); } - public async Task SaveImagesAsync(string[] names, CancellationToken cancellationToken = default(CancellationToken)) + public async Task SaveImagesAsync(string[]? names, CancellationToken cancellationToken = default) { - EnumerableQueryString queryString = null; + EnumerableQueryString? queryString = null; if (names?.Length > 0) { queryString = new EnumerableQueryString("names", names); } - return await _client.MakeRequestForStreamAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, "images/get", queryString, cancellationToken) + return await _client.MakeRequestForStreamAsync([NoSuchImageHandler], HttpMethod.Get, "images/get", queryString, cancellationToken) .ConfigureAwait(false); } - public Task LoadImageAsync(ImageLoadParameters parameters, Stream imageStream, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task LoadImageAsync(ImageLoadParameters parameters, Stream imageStream, IProgress progress, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -270,9 +281,9 @@ public async Task PruneImagesAsync(ImagesPruneParameters pa throw new ArgumentNullException(nameof(imageStream)); } - BinaryRequestContent content = new BinaryRequestContent(imageStream, TarContentType); + var content = new BinaryRequestContent(imageStream, TarContentType); - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); return StreamUtil.MonitorStreamForMessagesAsync( _client.MakeRequestForStreamAsync(_client.NoErrorHandlers, HttpMethod.Post, "images/load", queryParameters, content, cancellationToken), @@ -280,14 +291,13 @@ public async Task PruneImagesAsync(ImagesPruneParameters pa cancellationToken); } - private Dictionary RegistryAuthHeaders(AuthConfig authConfig) + private static Dictionary RegistryAuthHeaders(AuthConfig? authConfig) { return new Dictionary { { RegistryAuthHeaderKey, - Convert.ToBase64String(DockerClient.JsonSerializer.SerializeToUtf8Bytes(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. // See RFC 4648 Section 5. Padding (=) needs to be kept. @@ -295,7 +305,7 @@ private Dictionary RegistryAuthHeaders(AuthConfig authConfig) }; } - private Dictionary RegistryConfigHeaders(IEnumerable? authConfig) + private static Dictionary RegistryConfigHeaders(IEnumerable? authConfig) { var configDictionary = (authConfig ?? Array.Empty()).ToDictionary(e => e.ServerAddress, e => e); return new Dictionary diff --git a/src/Docker.DotNet/Endpoints/NetworkOperations.cs b/src/Docker.DotNet/Endpoints/NetworkOperations.cs index 01be4630..9476e864 100644 --- a/src/Docker.DotNet/Endpoints/NetworkOperations.cs +++ b/src/Docker.DotNet/Endpoints/NetworkOperations.cs @@ -17,33 +17,37 @@ internal NetworkOperations(DockerClient client) _client = client; } - async Task> INetworkOperations.ListNetworksAsync(NetworksListParameters parameters, CancellationToken cancellationToken) + public async Task> ListNetworksAsync(NetworksListParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "networks", queryParameters, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "networks", queryParameters, cancellationToken) + .ConfigureAwait(false); } - async Task INetworkOperations.InspectNetworkAsync(string id, CancellationToken cancellationToken) + public async Task InspectNetworkAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Get, $"networks/{id}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NoSuchNetworkHandler], HttpMethod.Get, $"networks/{id}", cancellationToken) + .ConfigureAwait(false); } - Task INetworkOperations.DeleteNetworkAsync(string id, CancellationToken cancellationToken) + public async Task DeleteNetworkAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Delete, $"networks/{id}", cancellationToken); + await _client.MakeRequestAsync([NoSuchNetworkHandler], HttpMethod.Delete, $"networks/{id}", cancellationToken) + .ConfigureAwait(false); } - async Task INetworkOperations.CreateNetworkAsync(NetworksCreateParameters parameters, CancellationToken cancellationToken) + public async Task CreateNetworkAsync(NetworksCreateParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -51,49 +55,67 @@ async Task INetworkOperations.CreateNetworkAsync(Network } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "networks/create", null, data, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "networks/create", null, data, cancellationToken) + .ConfigureAwait(false); } - Task INetworkOperations.ConnectNetworkAsync(string id, NetworkConnectParameters parameters, CancellationToken cancellationToken) + public async Task ConnectNetworkAsync(string id, NetworkConnectParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - if (string.IsNullOrEmpty(parameters?.Container)) + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrEmpty(parameters.Container)) { throw new ArgumentNullException(nameof(parameters)); } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Post, $"networks/{id}/connect", null, data, cancellationToken); + + await _client.MakeRequestAsync([NoSuchNetworkHandler], HttpMethod.Post, $"networks/{id}/connect", null, data, cancellationToken) + .ConfigureAwait(false); } - Task INetworkOperations.DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters, CancellationToken cancellationToken) + public async Task DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - if (string.IsNullOrEmpty(parameters?.Container)) + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + if (string.IsNullOrEmpty(parameters.Container)) { throw new ArgumentNullException(nameof(parameters)); } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return _client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Post, $"networks/{id}/disconnect", null, data, cancellationToken); + + await _client.MakeRequestAsync([NoSuchNetworkHandler], HttpMethod.Post, $"networks/{id}/disconnect", null, data, cancellationToken) + .ConfigureAwait(false); } - Task INetworkOperations.DeleteUnusedNetworksAsync(NetworksDeleteUnusedParameters parameters, CancellationToken cancellationToken) + public Task DeleteUnusedNetworksAsync(NetworksDeleteUnusedParameters? parameters = null, CancellationToken cancellationToken = default) { - return ((INetworkOperations)this).PruneNetworksAsync(parameters, cancellationToken); + return PruneNetworksAsync(parameters, cancellationToken); } - async Task INetworkOperations.PruneNetworksAsync(NetworksDeleteUnusedParameters parameters, CancellationToken cancellationToken) + public async Task PruneNetworksAsync(NetworksDeleteUnusedParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(null, HttpMethod.Post, "networks/prune", queryParameters, cancellationToken); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "networks/prune", queryParameters, cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/PluginOperations.cs b/src/Docker.DotNet/Endpoints/PluginOperations.cs index 5b3cdb64..704cb23e 100644 --- a/src/Docker.DotNet/Endpoints/PluginOperations.cs +++ b/src/Docker.DotNet/Endpoints/PluginOperations.cs @@ -19,24 +19,28 @@ internal PluginOperations(DockerClient client) _client = client; } - public async Task> ListPluginsAsync(PluginListParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> ListPluginsAsync(PluginListParameters? parameters = null, CancellationToken cancellationToken = default) { - IQueryString queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins", queryParameters, cancellationToken).ConfigureAwait(false); + var queryParameters = parameters == null ? null : new QueryString(parameters); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public async Task> GetPrivilegesAsync(PluginGetPrivilegeParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetPrivilegesAsync(PluginGetPrivilegeParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } - var query = new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins/privileges", query, cancellationToken).ConfigureAwait(false); + var queryParameters = new QueryString(parameters); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "plugins/privileges", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task InstallPluginAsync(PluginInstallParameters parameters, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task InstallPluginAsync(PluginInstallParameters parameters, IProgress progress, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -48,9 +52,9 @@ internal PluginOperations(DockerClient client) throw new ArgumentNullException(nameof(parameters.Privileges)); } - var data = new JsonRequestContent>(parameters.Privileges, DockerClient.JsonSerializer); + var queryParameters = new QueryString(parameters); - IQueryString queryParameters = new QueryString(parameters); + var data = new JsonRequestContent>(parameters.Privileges, DockerClient.JsonSerializer); return StreamUtil.MonitorStreamForMessagesAsync( _client.MakeRequestForStreamAsync(_client.NoErrorHandlers, HttpMethod.Post, $"plugins/pull", queryParameters, data, null, cancellationToken), @@ -58,50 +62,57 @@ internal PluginOperations(DockerClient client) cancellationToken); } - public async Task InspectPluginAsync(string name, CancellationToken cancellationToken) + public async Task InspectPluginAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return await _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Get, $"plugins/{name}/json", cancellationToken); + return await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Get, $"plugins/{name}/json", cancellationToken) + .ConfigureAwait(false); } - public Task RemovePluginAsync(string name, PluginRemoveParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task RemovePluginAsync(string name, PluginRemoveParameters? parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - IQueryString queryParameters = parameters == null ? null : new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Delete, $"plugins/{name}", queryParameters, cancellationToken); + var queryParameters = parameters == null ? null : new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Delete, $"plugins/{name}", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task EnablePluginAsync(string name, PluginEnableParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task EnablePluginAsync(string name, PluginEnableParameters? parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - IQueryString queryParameters = parameters == null ? null : new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/enable", queryParameters, cancellationToken); + var queryParameters = parameters == null ? null : new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Post, $"plugins/{name}/enable", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task DisablePluginAsync(string name, PluginDisableParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DisablePluginAsync(string name, PluginDisableParameters? parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - IQueryString queryParameters = parameters == null ? null : new QueryString(parameters); - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/disable", queryParameters, cancellationToken); + var queryParameters = parameters == null ? null : new QueryString(parameters); + + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Post, $"plugins/{name}/disable", queryParameters, cancellationToken) + .ConfigureAwait(false); } - public Task UpgradePluginAsync(string name, PluginUpgradeParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpgradePluginAsync(string name, PluginUpgradeParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -118,12 +129,15 @@ public async Task InspectPluginAsync(string name, CancellationToken canc throw new ArgumentNullException(nameof(parameters.Privileges)); } - var query = new QueryString(parameters); + var queryParameters = new QueryString(parameters); + var data = new JsonRequestContent>(parameters.Privileges, DockerClient.JsonSerializer); - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/upgrade", query, data, cancellationToken); + + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Post, $"plugins/{name}/upgrade", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } - public Task CreatePluginAsync(PluginCreateParameters parameters, Stream plugin, CancellationToken cancellationToken = default(CancellationToken)) + public async Task CreatePluginAsync(PluginCreateParameters parameters, Stream plugin, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -135,22 +149,26 @@ public async Task InspectPluginAsync(string name, CancellationToken canc throw new ArgumentNullException(nameof(plugin)); } - var query = new QueryString(parameters); + var queryParameters = new QueryString(parameters); + var data = new BinaryRequestContent(plugin, TarContentType); - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, $"plugins/create", query, data, cancellationToken); + + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, $"plugins/create", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } - public Task PushPluginAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) + public async Task PushPluginAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/push", cancellationToken); + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Post, $"plugins/{name}/push", cancellationToken) + .ConfigureAwait(false); } - public Task ConfigurePluginAsync(string name, PluginConfigureParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task ConfigurePluginAsync(string name, PluginConfigureParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -167,7 +185,9 @@ public async Task InspectPluginAsync(string name, CancellationToken canc throw new ArgumentNullException(nameof(parameters.Args)); } - var body = new JsonRequestContent>(parameters.Args, DockerClient.JsonSerializer); - return _client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/set", null, body, cancellationToken); + var data = new JsonRequestContent>(parameters.Args, DockerClient.JsonSerializer); + + await _client.MakeRequestAsync([NoSuchPluginHandler], HttpMethod.Post, $"plugins/{name}/set", null, data, cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/SecretsOperations.cs b/src/Docker.DotNet/Endpoints/SecretsOperations.cs index f9862bcc..01e36b2e 100644 --- a/src/Docker.DotNet/Endpoints/SecretsOperations.cs +++ b/src/Docker.DotNet/Endpoints/SecretsOperations.cs @@ -9,12 +9,13 @@ internal SecretsOperations(DockerClient client) _client = client; } - async Task> ISecretsOperations.ListAsync(CancellationToken cancellationToken) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "secrets", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "secrets", cancellationToken) + .ConfigureAwait(false); } - async Task ISecretsOperations.CreateAsync(SwarmSecretSpec body, CancellationToken cancellationToken) + public async Task CreateAsync(SwarmSecretSpec body, CancellationToken cancellationToken) { if (body == null) { @@ -22,26 +23,30 @@ async Task ISecretsOperations.CreateAsync(SwarmSecretSpec } var data = new JsonRequestContent(body, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "secrets/create", null, data, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "secrets/create", null, data, cancellationToken) + .ConfigureAwait(false); } - async Task ISecretsOperations.InspectAsync(string id, CancellationToken cancellationToken) + public async Task InspectAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"secrets/{id}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"secrets/{id}", cancellationToken) + .ConfigureAwait(false); } - Task ISecretsOperations.DeleteAsync(string id, CancellationToken cancellationToken) + public async Task DeleteAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"secrets/{id}", cancellationToken); + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"secrets/{id}", cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/SwarmOperations.cs b/src/Docker.DotNet/Endpoints/SwarmOperations.cs index 075d9558..8609a63e 100644 --- a/src/Docker.DotNet/Endpoints/SwarmOperations.cs +++ b/src/Docker.DotNet/Endpoints/SwarmOperations.cs @@ -2,7 +2,7 @@ namespace Docker.DotNet; internal class SwarmOperations : ISwarmOperations { - private static readonly ApiResponseErrorHandlingDelegate SwarmResponseHandler = (statusCode, responseBody) => + private static readonly ApiResponseErrorHandlingDelegate NotInSwarmResponseHandler = (statusCode, responseBody) => { if (statusCode == HttpStatusCode.ServiceUnavailable) { @@ -11,6 +11,15 @@ internal class SwarmOperations : ISwarmOperations } }; + private static readonly ApiResponseErrorHandlingDelegate AlreadyInSwarmResponseHandler = (statusCode, responseBody) => + { + if (statusCode == HttpStatusCode.ServiceUnavailable) + { + // TODO: Make typed error. + throw new Exception("Node is already part of a swarm."); + } + }; + private readonly DockerClient _client; internal SwarmOperations(DockerClient client) @@ -18,128 +27,111 @@ internal SwarmOperations(DockerClient client) _client = client; } - async Task ISwarmOperations.CreateServiceAsync(ServiceCreateParameters parameters, CancellationToken cancellationToken) + public async Task CreateServiceAsync(ServiceCreateParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) throw new ArgumentNullException(nameof(parameters)); var data = new JsonRequestContent(parameters.Service, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "services/create", null, data, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, "services/create", null, data, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.GetSwarmUnlockKeyAsync(CancellationToken cancellationToken) + public async Task GetSwarmUnlockKeyAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm/unlockkey", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, "swarm/unlockkey", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.InitSwarmAsync(SwarmInitParameters parameters, CancellationToken cancellationToken) + public async Task InitSwarmAsync(SwarmInitParameters parameters, CancellationToken cancellationToken = default) { var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync( - new ApiResponseErrorHandlingDelegate[] - { - (statusCode, responseBody) => - { - if (statusCode == HttpStatusCode.NotAcceptable) - { - // TODO: Make typed error. - throw new Exception("Node is already part of a swarm."); - } - } - }, - HttpMethod.Post, - "swarm/init", - null, - data, - cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync([AlreadyInSwarmResponseHandler], HttpMethod.Post, "swarm/init", null, data, cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.InspectServiceAsync(string id, CancellationToken cancellationToken) + public async Task InspectServiceAsync(string id, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, $"services/{id}", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.InspectSwarmAsync(CancellationToken cancellationToken) + public async Task InspectSwarmAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "swarm", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, "swarm", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.JoinSwarmAsync(SwarmJoinParameters parameters, CancellationToken cancellationToken) + public async Task JoinSwarmAsync(SwarmJoinParameters parameters, CancellationToken cancellationToken = default) { var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - await _client.MakeRequestAsync( - new ApiResponseErrorHandlingDelegate[] - { - (statusCode, responseBody) => - { - if (statusCode == HttpStatusCode.ServiceUnavailable) - { - // TODO: Make typed error. - throw new Exception("Node is already part of a swarm."); - } - } - }, - HttpMethod.Post, - "swarm/join", - null, - data, - cancellationToken).ConfigureAwait(false); - } - - async Task ISwarmOperations.LeaveSwarmAsync(SwarmLeaveParameters parameters, CancellationToken cancellationToken) - { - var query = parameters == null ? null : new QueryString(parameters); - await _client.MakeRequestAsync( - new ApiResponseErrorHandlingDelegate[] - { - (statusCode, responseBody) => - { - if (statusCode == HttpStatusCode.ServiceUnavailable) - { - // TODO: Make typed error. - throw new Exception("Node is not part of a swarm."); - } - } - }, - HttpMethod.Post, - "swarm/leave", - query, - cancellationToken).ConfigureAwait(false); + + await _client.MakeRequestAsync([AlreadyInSwarmResponseHandler], HttpMethod.Post, "swarm/join", null, data, cancellationToken) + .ConfigureAwait(false); + } + + public async Task LeaveSwarmAsync(SwarmLeaveParameters? parameters = null, CancellationToken cancellationToken = default) + { + var queryParameters = parameters == null ? null : new QueryString(parameters); + + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, "swarm/leave", queryParameters, cancellationToken) + .ConfigureAwait(false); } - async Task> ISwarmOperations.ListServicesAsync(ServiceListParameters parameters, CancellationToken cancellationToken) + public async Task> ListServicesAsync(ServiceListParameters? parameters = null, CancellationToken cancellationToken = default) { - var queryParameters = parameters != null ? new QueryString(parameters) : null; - return await _client - .MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "services", queryParameters, cancellationToken) + var queryParameters = parameters == null ? null : new QueryString(parameters); + + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, "services", queryParameters, cancellationToken) .ConfigureAwait(false); } - async Task ISwarmOperations.RemoveServiceAsync(string id, CancellationToken cancellationToken) + public async Task RemoveServiceAsync(string id, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } - await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Delete, $"services/{id}", cancellationToken).ConfigureAwait(false); + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Delete, $"services/{id}", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.UnlockSwarmAsync(SwarmUnlockParameters parameters, CancellationToken cancellationToken) + public async Task UnlockSwarmAsync(SwarmUnlockParameters parameters, CancellationToken cancellationToken = default) { - var body = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "swarm/unlock", null, body, cancellationToken).ConfigureAwait(false); + var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); + + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, "swarm/unlock", null, data, cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.UpdateServiceAsync(string id, ServiceUpdateParameters parameters, CancellationToken cancellationToken) + public async Task UpdateServiceAsync(string id, ServiceUpdateParameters parameters, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); - if (parameters == null) throw new ArgumentNullException(nameof(parameters)); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } + + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var queryParameters = new QueryString(parameters); - var query = new QueryString(parameters); - var body = new JsonRequestContent(parameters.Service, DockerClient.JsonSerializer); - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"services/{id}/update", query, body, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken).ConfigureAwait(false); + var data = new JsonRequestContent(parameters.Service, DockerClient.JsonSerializer); + + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, $"services/{id}/update", queryParameters, data, RegistryAuthHeaders(parameters.RegistryAuth), cancellationToken) + .ConfigureAwait(false); } - public async Task GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -151,13 +143,13 @@ async Task ISwarmOperations.UpdateServiceAsync(string id, throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); - return await _client.MakeRequestForStreamAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken) + return await _client.MakeRequestForStreamAsync([NotInSwarmResponseHandler], HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken) .ConfigureAwait(false); } - public async Task GetServiceLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetServiceLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { @@ -169,37 +161,25 @@ async Task ISwarmOperations.UpdateServiceAsync(string id, throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); - var response = await _client.MakeRequestForStreamAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken).ConfigureAwait(false); + var response = await _client.MakeRequestForStreamAsync([NotInSwarmResponseHandler], HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken) + .ConfigureAwait(false); return new MultiplexedStream(response, !tty); } - async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken) + public async Task UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken = default) { - var query = new QueryString(parameters); - var body = new JsonRequestContent(parameters.Spec, DockerClient.JsonSerializer); - await _client.MakeRequestAsync( - new ApiResponseErrorHandlingDelegate[] - { - (statusCode, responseBody) => - { - if (statusCode == HttpStatusCode.ServiceUnavailable) - { - // TODO: Make typed error. - throw new Exception("Node is not part of a swarm."); - } - } - }, - HttpMethod.Post, - "swarm/update", - query, - body, - cancellationToken).ConfigureAwait(false); - } - - private IDictionary RegistryAuthHeaders(AuthConfig authConfig) + var queryParameters = new QueryString(parameters); + + var data = new JsonRequestContent(parameters.Spec, DockerClient.JsonSerializer); + + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, "swarm/update", queryParameters, data, cancellationToken) + .ConfigureAwait(false); + } + + private static Dictionary RegistryAuthHeaders(AuthConfig? authConfig) { if (authConfig == null) { @@ -215,30 +195,50 @@ private IDictionary RegistryAuthHeaders(AuthConfig authConfig) }; } - async Task> ISwarmOperations.ListNodesAsync(CancellationToken cancellationToken) + public async Task> ListNodesAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, "nodes", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, "nodes", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.InspectNodeAsync(string id, CancellationToken cancellationToken) + public async Task InspectNodeAsync(string id, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); - return await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"nodes/{id}", cancellationToken).ConfigureAwait(false); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } + + return await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Get, $"nodes/{id}", cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.RemoveNodeAsync(string id, bool force, CancellationToken cancellationToken) + public async Task RemoveNodeAsync(string id, bool? force = null, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } + var parameters = new NodeRemoveParameters { Force = force }; - var query = new QueryString(parameters); - await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Delete, $"nodes/{id}", query, cancellationToken).ConfigureAwait(false); + + var queryParameters = new QueryString(parameters); + + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Delete, $"nodes/{id}", queryParameters, cancellationToken) + .ConfigureAwait(false); } - async Task ISwarmOperations.UpdateNodeAsync(string id, ulong version, NodeUpdateParameters parameters, CancellationToken cancellationToken) + public async Task UpdateNodeAsync(string id, ulong version, NodeUpdateParameters parameters, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id)); - var query = new EnumerableQueryString("version", new[] { version.ToString() }); - var body = new JsonRequestContent(parameters, DockerClient.JsonSerializer); - await _client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"nodes/{id}/update", query, body, cancellationToken); + if (string.IsNullOrEmpty(id)) + { + throw new ArgumentNullException(nameof(id)); + } + + var queryParameters = new EnumerableQueryString("version", [version.ToString()]); + + var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); + + await _client.MakeRequestAsync([NotInSwarmResponseHandler], HttpMethod.Post, $"nodes/{id}/update", queryParameters, data, cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/SystemOperations.cs b/src/Docker.DotNet/Endpoints/SystemOperations.cs index 6aab066f..e8492d44 100644 --- a/src/Docker.DotNet/Endpoints/SystemOperations.cs +++ b/src/Docker.DotNet/Endpoints/SystemOperations.cs @@ -9,46 +9,51 @@ internal SystemOperations(DockerClient client) _client = client; } - public Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)) + public async Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default) { if (authConfig == null) { throw new ArgumentNullException(nameof(authConfig)); } + var data = new JsonRequestContent(authConfig, DockerClient.JsonSerializer); - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken); + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken) + .ConfigureAwait(false); } - public async Task GetVersionAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetVersionAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "version", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "version", cancellationToken) + .ConfigureAwait(false); } - public Task PingAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task PingAsync(CancellationToken cancellationToken = default) { - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "_ping", cancellationToken); + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "_ping", cancellationToken) + .ConfigureAwait(false); } - public async Task GetSystemInfoAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetSystemInfoAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "info", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "info", cancellationToken) + .ConfigureAwait(false); } - public async Task MonitorEventsAsync(ContainerEventsParameters parameters, CancellationToken cancellationToken) + public async Task MonitorEventsAsync(ContainerEventsParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); return await _client.MakeRequestForStreamAsync(_client.NoErrorHandlers, HttpMethod.Get, "events", queryParameters, cancellationToken) .ConfigureAwait(false); } - public Task MonitorEventsAsync(ContainerEventsParameters parameters, IProgress progress, CancellationToken cancellationToken = default(CancellationToken)) + public Task MonitorEventsAsync(ContainerEventsParameters parameters, IProgress progress, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -60,7 +65,7 @@ public async Task MonitorEventsAsync(ContainerEventsParameters parameter throw new ArgumentNullException(nameof(progress)); } - IQueryString queryParameters = new QueryString(parameters); + var queryParameters = new QueryString(parameters); return StreamUtil.MonitorStreamForMessagesAsync( _client.MakeRequestForStreamAsync(_client.NoErrorHandlers, HttpMethod.Get, "events", queryParameters, cancellationToken), diff --git a/src/Docker.DotNet/Endpoints/TasksOperations.cs b/src/Docker.DotNet/Endpoints/TasksOperations.cs index f97f83da..1fe89878 100644 --- a/src/Docker.DotNet/Endpoints/TasksOperations.cs +++ b/src/Docker.DotNet/Endpoints/TasksOperations.cs @@ -9,28 +9,27 @@ internal TasksOperations(DockerClient client) _client = client; } - Task> ITasksOperations.ListAsync(CancellationToken cancellationToken) + public Task> ListAsync(CancellationToken cancellationToken = default) { - return ((ITasksOperations)this).ListAsync(null, cancellationToken); + return ListAsync(null, cancellationToken); } - async Task> ITasksOperations.ListAsync(TasksListParameters parameters, CancellationToken cancellationToken) + public async Task> ListAsync(TasksListParameters? parameters = null, CancellationToken cancellationToken = default) { - IQueryString query = null; - if (parameters != null) { - query = new QueryString(parameters); - } + var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "tasks", query, cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync>(_client.NoErrorHandlers, HttpMethod.Get, "tasks", queryParameters, cancellationToken) + .ConfigureAwait(false); } - async Task ITasksOperations.InspectAsync(string id, CancellationToken cancellationToken) + public async Task InspectAsync(string id, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"tasks/{id}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"tasks/{id}", cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Docker.DotNet/Endpoints/VolumeOperations.cs b/src/Docker.DotNet/Endpoints/VolumeOperations.cs index 6ff17330..72f777a0 100644 --- a/src/Docker.DotNet/Endpoints/VolumeOperations.cs +++ b/src/Docker.DotNet/Endpoints/VolumeOperations.cs @@ -9,18 +9,20 @@ internal VolumeOperations(DockerClient client) _client = client; } - async Task IVolumeOperations.ListAsync(CancellationToken cancellationToken) + public Task ListAsync(CancellationToken cancellationToken = default) { - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "volumes", cancellationToken).ConfigureAwait(false); + return ListAsync(null, cancellationToken); } - async Task IVolumeOperations.ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken) + public async Task ListAsync(VolumesListParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "volumes", queryParameters, null, cancellationToken).ConfigureAwait(false); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, "volumes", queryParameters, cancellationToken) + .ConfigureAwait(false); } - async Task IVolumeOperations.CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken) + public async Task CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { @@ -28,32 +30,37 @@ async Task IVolumeOperations.CreateAsync(VolumesCreateParameters } var data = new JsonRequestContent(parameters, DockerClient.JsonSerializer); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "volumes/create", null, data, cancellationToken); } - async Task IVolumeOperations.InspectAsync(string name, CancellationToken cancellationToken) + public async Task InspectAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"volumes/{name}", cancellationToken).ConfigureAwait(false); + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Get, $"volumes/{name}", cancellationToken) + .ConfigureAwait(false); } - Task IVolumeOperations.RemoveAsync(string name, bool? force, CancellationToken cancellationToken) + public async Task RemoveAsync(string name, bool? force = null, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } - return _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"volumes/{name}", cancellationToken); + await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Delete, $"volumes/{name}", cancellationToken) + .ConfigureAwait(false); } - async Task IVolumeOperations.PruneAsync(VolumesPruneParameters parameters, CancellationToken cancellationToken) + public async Task PruneAsync(VolumesPruneParameters? parameters = null, CancellationToken cancellationToken = default) { var queryParameters = parameters == null ? null : new QueryString(parameters); - return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "volumes/prune", queryParameters, cancellationToken); + + return await _client.MakeRequestAsync(_client.NoErrorHandlers, HttpMethod.Post, "volumes/prune", queryParameters, cancellationToken) + .ConfigureAwait(false); } } \ No newline at end of file