forked from dotnet/Docker.DotNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client support for Swarm Logs and Swarm Config (dotnet#589)
* expose Swam Config as client.Configs * Expose Swam Service Logs * send SwarmConfigSpec to api * Update src/Docker.DotNet/Endpoints/ISwarmOperations.cs Co-authored-by: Andre Hofmeister <[email protected]> * Update src/Docker.DotNet/Endpoints/ISwarmOperations.cs Co-authored-by: Andre Hofmeister <[email protected]> * rename to standard add logging test * add logging test fix naming convention * Update src/Docker.DotNet/Endpoints/IConfigsOperations.cs Co-authored-by: Andre Hofmeister <[email protected]> * Update src/Docker.DotNet/Endpoints/IConfigsOperations.cs Co-authored-by: Andre Hofmeister <[email protected]> * Update src/Docker.DotNet/Endpoints/ConfigsOperations.cs Co-authored-by: Andre Hofmeister <[email protected]> * Add Config Tests, some Renaming fixes * updated test with retry and increased buffer. Improved cancelation handling. --------- Co-authored-by: Jasim Schluter <[email protected]> Co-authored-by: Andre Hofmeister <[email protected]>
- Loading branch information
1 parent
3ca9743
commit 1c3a067
Showing
9 changed files
with
745 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Autodetect text files | ||
* text=auto | ||
|
||
# Definitively text files | ||
*.cs text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Docker.DotNet.Models; | ||
|
||
namespace Docker.DotNet | ||
{ | ||
internal class ConfigOperations : IConfigOperations | ||
{ | ||
private readonly DockerClient _client; | ||
|
||
internal ConfigOperations(DockerClient client) | ||
{ | ||
this._client = client; | ||
} | ||
|
||
async Task<IList<SwarmConfig>> IConfigOperations.ListConfigsAsync(CancellationToken cancellationToken) | ||
{ | ||
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false); | ||
return this._client.JsonSerializer.DeserializeObject<IList<SwarmConfig>>(response.Body); | ||
} | ||
|
||
async Task<SwarmCreateConfigResponse> IConfigOperations.CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken) | ||
{ | ||
if (body == null) | ||
{ | ||
throw new ArgumentNullException(nameof(body)); | ||
} | ||
|
||
var data = new JsonRequestContent<SwarmConfigSpec>(body.Config, this._client.JsonSerializer); | ||
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "configs/create", null, data, cancellationToken).ConfigureAwait(false); | ||
return this._client.JsonSerializer.DeserializeObject<SwarmCreateConfigResponse>(response.Body); | ||
} | ||
|
||
async Task<SwarmConfig> IConfigOperations.InspectConfigAsync(string id, CancellationToken cancellationToken) | ||
{ | ||
if (string.IsNullOrEmpty(id)) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
|
||
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false); | ||
return this._client.JsonSerializer.DeserializeObject<SwarmConfig>(response.Body); | ||
} | ||
|
||
Task IConfigOperations.RemoveConfigAsync(string id, CancellationToken cancellationToken) | ||
{ | ||
if (string.IsNullOrEmpty(id)) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
|
||
return this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Delete, $"configs/{id}", cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Docker.DotNet.Models; | ||
|
||
namespace Docker.DotNet | ||
{ | ||
public interface IConfigOperations | ||
{ | ||
/// <summary> | ||
/// List configs | ||
/// </summary> | ||
/// <remarks> | ||
/// 200 - No error. | ||
/// 500 - Server error. | ||
/// </remarks> | ||
Task<IList<SwarmConfig>> ListConfigsAsync(CancellationToken cancellationToken = default(CancellationToken)); | ||
|
||
/// <summary> | ||
/// Create a configs | ||
/// </summary> | ||
/// <remarks> | ||
/// 201 - No error. | ||
/// 406 - Server error or node is not part of a swarm. | ||
/// 409 - Name conflicts with an existing object. | ||
/// 500 - Server error. | ||
/// </remarks> | ||
Task<SwarmCreateConfigResponse> CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default(CancellationToken)); | ||
|
||
/// <summary> | ||
/// Inspect a configs | ||
/// </summary> | ||
/// <remarks> | ||
/// 200 - No error. | ||
/// 404 - Secret not found. | ||
/// 406 - Node is not part of a swarm. | ||
/// 500 - Server error. | ||
/// </remarks> | ||
/// <param name="id">ID of the config.</param> | ||
Task<SwarmConfig> InspectConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); | ||
|
||
/// <summary> | ||
/// Remove a configs | ||
/// </summary> | ||
/// <remarks> | ||
/// 204 - No error. | ||
/// 404 - Secret not found. | ||
/// 500 - Server error. | ||
/// </remarks> | ||
/// <param name="id">ID of the config.</param> | ||
Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.