From 616fc61a5934d56728ffd8cbc4fe3f3c75c5cca5 Mon Sep 17 00:00:00 2001
From: li <381574533@qq.com>
Date: Thu, 2 May 2019 20:07:15 +0800
Subject: [PATCH] Add Swarm Config Api
---
.../Endpoints/ISwarmOperations.cs | 76 ++++++++++++++++++-
.../Endpoints/SwarmOperations.cs | 47 ++++++++++++
.../Models/ConfigCreateResponse.Generated.cs | 16 ++++
.../Models/ConfigSpec.Generated.cs | 41 ++++++++++
.../ConfigUpdateParameters.Generated.cs | 25 ++++++
.../Models/ConfigUpdateResponse.Generated.cs | 13 ++++
.../Models/ConfigsListParameters.cs | 41 ++++++++++
.../Models/SwarmConfig.Generated.cs | 34 +++++++++
.../SwarmCreateConfigParameters.Generated.cs | 21 +++++
src/Docker.DotNet/Models/Templating.cs | 19 +++++
10 files changed, 331 insertions(+), 2 deletions(-)
create mode 100644 src/Docker.DotNet/Models/ConfigCreateResponse.Generated.cs
create mode 100644 src/Docker.DotNet/Models/ConfigSpec.Generated.cs
create mode 100644 src/Docker.DotNet/Models/ConfigUpdateParameters.Generated.cs
create mode 100644 src/Docker.DotNet/Models/ConfigUpdateResponse.Generated.cs
create mode 100644 src/Docker.DotNet/Models/ConfigsListParameters.cs
create mode 100644 src/Docker.DotNet/Models/SwarmConfig.Generated.cs
create mode 100644 src/Docker.DotNet/Models/SwarmCreateConfigParameters.Generated.cs
create mode 100644 src/Docker.DotNet/Models/Templating.cs
diff --git a/src/Docker.DotNet/Endpoints/ISwarmOperations.cs b/src/Docker.DotNet/Endpoints/ISwarmOperations.cs
index 877e2f18d..8f374d976 100644
--- a/src/Docker.DotNet/Endpoints/ISwarmOperations.cs
+++ b/src/Docker.DotNet/Endpoints/ISwarmOperations.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
using Docker.DotNet.Models;
+using System.Collections.Generic;
using System.Threading;
+using System.Threading.Tasks;
namespace Docker.DotNet
{
@@ -206,5 +206,77 @@ public interface ISwarmOperations
Task UpdateNodeAsync(string id, ulong version, NodeUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
#endregion
+
+ #region Configs
+
+ ///
+ /// List configs
+ ///
+ ///
+ /// 200 - No error.
+ /// 500 - Server error
+ /// 503 - Node is not part of a swarm
+ ///
+ ///
+ Task> ListConfigsAsync(ConfigsListParameters parameters = null, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Create a config
+ ///
+ ///
+ /// 201 no error
+ /// 409 name conflicts with an existing object
+ /// 500 server error
+ /// 503 node is not part of a swarm
+ ///
+ ///
+ ///
+ ///
+ Task CreateConfigAsync(SwarmCreateConfigParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Inspect a config
+ ///
+ ///
+ /// 200 no error
+ /// 404 config not found
+ /// 500 server error
+ /// 503 node is not part of a swarm
+ ///
+ /// ID of the config
+ ///
+ ///
+ Task InspectConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Update a Config
+ ///
+ ///
+ /// 200 no error
+ /// 400 bad parameter
+ /// 404 no such config
+ /// 500 server error
+ /// 503 node is not part of a swarm
+ ///
+ /// The ID or name of the config
+ ///
+ ///
+ ///
+ Task UpdateConfigAsync(string id, ConfigUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
+
+ ///
+ /// Delete a config
+ ///
+ ///
+ /// 204 no error
+ /// 404 config not found
+ /// 500 server error
+ /// 503 node is not part of a swarm
+ ///
+ /// ID of the config
+ ///
+ ///
+ Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
+ #endregion
}
}
\ No newline at end of file
diff --git a/src/Docker.DotNet/Endpoints/SwarmOperations.cs b/src/Docker.DotNet/Endpoints/SwarmOperations.cs
index 13d1c819e..e5c1ad664 100644
--- a/src/Docker.DotNet/Endpoints/SwarmOperations.cs
+++ b/src/Docker.DotNet/Endpoints/SwarmOperations.cs
@@ -221,5 +221,52 @@ async Task ISwarmOperations.UpdateNodeAsync(string id, ulong version, NodeUpdate
var body = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), this._client.JsonSerializer);
await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"nodes/{id}/update", query, body, cancellationToken);
}
+
+ async Task> ISwarmOperations.ListConfigsAsync(ConfigsListParameters parameters, CancellationToken cancellationToken)
+ {
+ var queryParameters = parameters != null ? new QueryString(parameters) : null;
+ var response = await this._client
+ .MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"configs", queryParameters, cancellationToken)
+ .ConfigureAwait(false);
+ return this._client.JsonSerializer.DeserializeObject(response.Body);
+ }
+
+ async Task ISwarmOperations.CreateConfigAsync(SwarmCreateConfigParameters parameters, CancellationToken cancellationToken)
+ {
+ if (parameters == null) throw new ArgumentNullException(nameof(parameters));
+
+ var data = new JsonRequestContent(parameters.Config ?? throw new ArgumentNullException(nameof(parameters.Config)), this._client.JsonSerializer);
+ //var data = new JsonRequestContent(parameters ?? throw new ArgumentNullException(nameof(parameters)), this._client.JsonSerializer);
+ var response = await this._client
+ .MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "configs/create", null, data, cancellationToken)
+ .ConfigureAwait(false);
+ return this._client.JsonSerializer.DeserializeObject(response.Body);
+ }
+
+ async Task ISwarmOperations.InspectConfigAsync(string id, CancellationToken cancellationToken)
+ {
+ if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
+
+ var response = await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"configs/{id}", cancellationToken).ConfigureAwait(false);
+ return this._client.JsonSerializer.DeserializeObject(response.Body);
+ }
+
+ async Task ISwarmOperations.UpdateConfigAsync(string id, ConfigUpdateParameters parameters, CancellationToken cancellationToken)
+ {
+ if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
+ if (parameters == null) throw new ArgumentNullException(nameof(parameters));
+
+ var query = new QueryString(parameters);
+ var body = new JsonRequestContent(parameters.Config ?? throw new ArgumentNullException(nameof(parameters.Config)), this._client.JsonSerializer);
+ var response = await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"configs/{id}/update", query, body, cancellationToken).ConfigureAwait(false);
+ //this._client.JsonSerializer.DeserializeObject(response.Body);
+ }
+
+ async Task ISwarmOperations.RemoveConfigAsync(string id, CancellationToken cancellationToken)
+ {
+ if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
+
+ await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Delete, $"configs/{id}", cancellationToken).ConfigureAwait(false);
+ }
}
}
diff --git a/src/Docker.DotNet/Models/ConfigCreateResponse.Generated.cs b/src/Docker.DotNet/Models/ConfigCreateResponse.Generated.cs
new file mode 100644
index 000000000..6d4bf3461
--- /dev/null
+++ b/src/Docker.DotNet/Models/ConfigCreateResponse.Generated.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class ConfigCreateResponse
+ {
+ [DataMember(Name = "ID", EmitDefaultValue = false)]
+ public string Id { get; set; }
+ }
+}
diff --git a/src/Docker.DotNet/Models/ConfigSpec.Generated.cs b/src/Docker.DotNet/Models/ConfigSpec.Generated.cs
new file mode 100644
index 000000000..4067c6779
--- /dev/null
+++ b/src/Docker.DotNet/Models/ConfigSpec.Generated.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class ConfigSpec
+ {
+ public ConfigSpec()
+ {
+ }
+
+ ///
+ /// User-defined name of the config
+ ///
+ [DataMember(Name = "Name", EmitDefaultValue = false)]
+ public string Name { get; set; }
+
+ ///
+ /// User-defined key/value metadata
+ ///
+ [DataMember(Name = "Labels", EmitDefaultValue = false)]
+ public IDictionary Labels { get; set; }
+
+ ///
+ /// Base64-url-safe-encoded (RFC 4648) config data
+ ///
+ [DataMember(Name = "Data", EmitDefaultValue = false)]
+ public string Data { get; set; }
+
+ ///
+ /// Driver represents a driver (network, logging, secrets).
+ ///
+ [DataMember(Name = "Templating", EmitDefaultValue = false)]
+ public Templating Templating { get; set; }
+ }
+}
diff --git a/src/Docker.DotNet/Models/ConfigUpdateParameters.Generated.cs b/src/Docker.DotNet/Models/ConfigUpdateParameters.Generated.cs
new file mode 100644
index 000000000..eb96d1404
--- /dev/null
+++ b/src/Docker.DotNet/Models/ConfigUpdateParameters.Generated.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class ConfigUpdateParameters
+ {
+ ///
+ /// The version number of the config object being updated. This is required to avoid conflicting writes
+ ///
+ [QueryStringParameter("version", true)]
+ public long Version { get; set; }
+
+ ///
+ ///
+ ///
+ [DataMember(Name = "Config", EmitDefaultValue = false)]
+ public ConfigSpec Config { get; set; }
+ }
+}
diff --git a/src/Docker.DotNet/Models/ConfigUpdateResponse.Generated.cs b/src/Docker.DotNet/Models/ConfigUpdateResponse.Generated.cs
new file mode 100644
index 000000000..1334630b8
--- /dev/null
+++ b/src/Docker.DotNet/Models/ConfigUpdateResponse.Generated.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ public class ConfigUpdateResponse
+ {
+
+ }
+}
diff --git a/src/Docker.DotNet/Models/ConfigsListParameters.cs b/src/Docker.DotNet/Models/ConfigsListParameters.cs
new file mode 100644
index 000000000..bbc7faf02
--- /dev/null
+++ b/src/Docker.DotNet/Models/ConfigsListParameters.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ public class ConfigsListParameters
+ {
+ [QueryStringParameter("filters", false, typeof(MapQueryStringConverter))]
+ public ConfigFilter Filters { get; set; }
+ }
+
+ public class ConfigFilter: Dictionary
+ {
+ public string Id
+ {
+ get => this["id"];
+ set => this["id"] = value;
+ }
+
+ public string Label
+ {
+ get => this["label"];
+ set => this["label"] = value;
+ }
+
+ public string Name
+ {
+ get => this["name"];
+ set => this["name"] = value;
+ }
+
+ public string Names
+ {
+ get => this["names"];
+ set => this["names"] = value;
+ }
+ }
+}
diff --git a/src/Docker.DotNet/Models/SwarmConfig.Generated.cs b/src/Docker.DotNet/Models/SwarmConfig.Generated.cs
new file mode 100644
index 000000000..c15808d52
--- /dev/null
+++ b/src/Docker.DotNet/Models/SwarmConfig.Generated.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class SwarmConfig // (configs)
+ {
+
+ public SwarmConfig()
+ {
+
+ }
+
+ [DataMember(Name = "ID", EmitDefaultValue = false)]
+ public string ID { get; set; }
+
+ [DataMember(Name = "Version", EmitDefaultValue = false)]
+ public Version Version { get; set; }
+
+ [DataMember(Name = "CreatedAt", EmitDefaultValue = false)]
+ public DateTime CreatedAt { get; set; }
+
+ [DataMember(Name = "UpdatedAt", EmitDefaultValue = false)]
+ public DateTime UpdatedAt { get; set; }
+
+ [DataMember(Name = "Spec", EmitDefaultValue = false)]
+ public ConfigSpec Spec { get; set; }
+ }
+}
diff --git a/src/Docker.DotNet/Models/SwarmCreateConfigParameters.Generated.cs b/src/Docker.DotNet/Models/SwarmCreateConfigParameters.Generated.cs
new file mode 100644
index 000000000..d41f41f36
--- /dev/null
+++ b/src/Docker.DotNet/Models/SwarmCreateConfigParameters.Generated.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class SwarmCreateConfigParameters
+ {
+ public SwarmCreateConfigParameters()
+ {
+
+ }
+
+ [DataMember(Name = "Config", EmitDefaultValue = false)]
+ public ConfigSpec Config { get; set; }
+ }
+}
diff --git a/src/Docker.DotNet/Models/Templating.cs b/src/Docker.DotNet/Models/Templating.cs
new file mode 100644
index 000000000..7f7779f11
--- /dev/null
+++ b/src/Docker.DotNet/Models/Templating.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Docker.DotNet.Models
+{
+ [DataContract]
+ public class Templating
+ {
+ [DataMember(Name = "Name", EmitDefaultValue = false)]
+ public string Name { get; set; }
+
+ [DataMember(Name = "Options", EmitDefaultValue = false)]
+ public IDictionary Options { get; set; }
+ }
+}