-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Binali Rustamov
committed
Nov 16, 2023
1 parent
8d52482
commit 25ac4ac
Showing
10 changed files
with
175 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using PortainerClient.Api.Base; | ||
using PortainerClient.Api.Model; | ||
|
||
namespace PortainerClient.Api; | ||
|
||
/// <summary> | ||
/// API implementation for endpoints API | ||
/// </summary> | ||
public class EndpointsApiService : BaseApiService | ||
{ | ||
/// <summary> | ||
/// Get all configs | ||
/// </summary> | ||
/// <param name="endpointId"></param> | ||
/// <returns>List of available configs</returns> | ||
public IEnumerable<DockerDto> GetConfigs(int endpointId) => | ||
Get<List<DockerDto>>($"endpoints/{endpointId}/docker/configs"); | ||
/// <summary> | ||
/// Get all secrets | ||
/// </summary> | ||
/// <param name="endpointId"></param> | ||
/// <returns>List of available secrets</returns> | ||
public IEnumerable<DockerDto> GetSecrets(int endpointId) => | ||
Get<List<DockerDto>>($"endpoints/{endpointId}/docker/secrets"); | ||
} |
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,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace PortainerClient.Api.Model; | ||
|
||
/// <summary> | ||
/// Spec of Docker Swarm Config instance | ||
/// </summary> | ||
public class ConfigSpec | ||
{ | ||
public string Data { get; set; } | ||
public Dictionary<string, object> Labels { get; set; } | ||
public string Name { get; set; } | ||
} |
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,16 @@ | ||
using System; | ||
|
||
namespace PortainerClient.Api.Model; | ||
|
||
/// <summary> | ||
/// Docker specific instance info | ||
/// </summary> | ||
public class DockerDto | ||
{ | ||
public DateTime CreatedAt { get; set; } | ||
public string ID { get; set; } | ||
public Portainer Portainer { get; set; } | ||
public ConfigSpec Spec { get; set; } | ||
public DateTime UpdatedAt { get; set; } | ||
public Version Version { get; set; } | ||
} |
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,12 @@ | ||
namespace PortainerClient.Api.Model; | ||
|
||
/// <summary> | ||
/// Represents info about Docker Resource in Portainer | ||
/// </summary> | ||
public class Portainer | ||
{ | ||
/// <summary> | ||
/// Resource control information from portainer | ||
/// </summary> | ||
public ResourceControl ResourceControl { get; set; } | ||
} |
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,9 @@ | ||
namespace PortainerClient.Api.Model; | ||
|
||
/// <summary> | ||
/// Version of object | ||
/// </summary> | ||
public class Version | ||
{ | ||
public int Index { get; set; } | ||
} |
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,16 @@ | ||
using McMaster.Extensions.CommandLineUtils; | ||
using PortainerClient.Command.Stack; | ||
using PortainerClient.Helpers; | ||
|
||
namespace PortainerClient.Command.Configs; | ||
|
||
/// <summary> | ||
/// CMD command for Configs | ||
/// </summary> | ||
[Command(Name = "configs", Description = "Docker Swarm Configs management commands")] | ||
[Subcommand(typeof(ConfigsLsCmd))] | ||
public class ConfigsCmd : ICommand | ||
{ | ||
/// <inheritdoc /> | ||
public int OnExecute(CommandLineApplication app, IConsole console) => CmdHelpers.SpecifyCommandResult(app, console); | ||
} |
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,32 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using PortainerClient.Api; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace PortainerClient.Command.Configs; | ||
|
||
/// <summary> | ||
/// CMD command for Configs list operation | ||
/// </summary> | ||
[Command(Name = "ls", Description = "List all configs")] | ||
public class ConfigsLsCmd: BaseApiCommand<EndpointsApiService> | ||
{ | ||
/// <summary> | ||
/// Endpoint identifier | ||
/// </summary> | ||
[Argument(order: 0, name: "endpoint-id", description: "ID of endpoint used to deploy (get it from Portainer)")] | ||
[Required] | ||
public int EndpointId { get; set; } | ||
|
||
/// <inheritdoc /> | ||
protected override void Do(CommandLineApplication app, IConsole console) | ||
{ | ||
var list = ApiClient.GetConfigs(EndpointId).Select(c=> c.Spec); | ||
var yamlSerializer = new Serializer(); | ||
Console.WriteLine("--- CONFIGS ---"); | ||
Console.WriteLine(yamlSerializer.Serialize(list)); | ||
Console.WriteLine($"--- Total count: {list.Count()} ---"); | ||
} | ||
} |
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,16 @@ | ||
using McMaster.Extensions.CommandLineUtils; | ||
using PortainerClient.Command.Configs; | ||
using PortainerClient.Helpers; | ||
|
||
namespace PortainerClient.Command.Secrets; | ||
|
||
/// <summary> | ||
/// CMD command for Secrets | ||
/// </summary> | ||
[Command(Name = "secrets", Description = "Docker Swarm Secrets management commands")] | ||
[Subcommand(typeof(SecretsLsCmd))] | ||
public class SecretsCmd : ICommand | ||
{ | ||
/// <inheritdoc /> | ||
public int OnExecute(CommandLineApplication app, IConsole console) => CmdHelpers.SpecifyCommandResult(app, console); | ||
} |
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,32 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using PortainerClient.Api; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace PortainerClient.Command.Configs; | ||
|
||
/// <summary> | ||
/// CMD command for Secrets list operation | ||
/// </summary> | ||
[Command(Name = "ls", Description = "List all secrets")] | ||
public class SecretsLsCmd: BaseApiCommand<EndpointsApiService> | ||
{ | ||
/// <summary> | ||
/// Endpoint identifier | ||
/// </summary> | ||
[Argument(order: 0, name: "endpoint-id", description: "ID of endpoint used to deploy (get it from Portainer)")] | ||
[Required] | ||
public int EndpointId { get; set; } | ||
|
||
/// <inheritdoc /> | ||
protected override void Do(CommandLineApplication app, IConsole console) | ||
{ | ||
var list = ApiClient.GetSecrets(EndpointId).Select(c=> c.Spec); | ||
var yamlSerializer = new Serializer(); | ||
Console.WriteLine("--- SECRETS ---"); | ||
Console.WriteLine(yamlSerializer.Serialize(list)); | ||
Console.WriteLine($"--- Total count: {list.Count()} ---"); | ||
} | ||
} |
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