-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial models for supporting client-go credential plugins
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/KubeClient.Extensions.KubeConfig/Models/AuthPluginConfig.cs
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 KubeClient.Models; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace KubeClient.Extensions.KubeConfig.Models | ||
{ | ||
/// <summary> | ||
/// Configuration for a K8s client-go credential plugin. | ||
/// </summary> | ||
public class CredentialPluginConfig | ||
{ | ||
/// <summary> | ||
/// The plugin command. | ||
/// </summary> | ||
[YamlMember(Alias = "command")] | ||
public string Command { get; set; } | ||
|
||
/// <summary> | ||
/// The API version to use when decoding the ExecCredentials resource. | ||
/// </summary> | ||
/// <remarks> | ||
/// The API version returned by the plugin MUST match the version specified here. | ||
/// </remarks> | ||
[YamlMember(Alias = "apiVersion")] | ||
public string ApiVersion { get; set; } | ||
|
||
/// <summary> | ||
/// Environment variables (if any) to set when running the plugin command. | ||
/// </summary> | ||
public List<EnvVarV1> EnvironmentVariables { get; } = new List<EnvVarV1>(); | ||
|
||
/// <summary> | ||
/// Should <see cref="EnvironmentVariables"/> be serialised? | ||
/// </summary> | ||
/// <returns> | ||
/// <c>true</c>, if <see cref="EnvironmentVariables"/> should be serialised; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool ShouldSerializeEnvironmentVariables() => EnvironmentVariables.Count > 0; | ||
|
||
/// <summary> | ||
/// Command-line arguments (if any) to pass to the plugin command. | ||
/// </summary> | ||
public List<string> Arguments { get; } = new List<string>(); | ||
|
||
/// <summary> | ||
/// Should <see cref="Arguments"/> be serialised? | ||
/// </summary> | ||
/// <returns> | ||
/// <c>true</c>, if <see cref="Arguments"/> should be serialised; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool ShouldSerializeArguments() => Arguments.Count > 0; | ||
} | ||
} |
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,46 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace KubeClient.Models | ||
{ | ||
/// <summary> | ||
/// The model for the response returned by client-go credential plugins. | ||
/// </summary> | ||
[KubeObject("ExecCredential", "client.authentication.k8s.io/v1beta1")] | ||
public class ExecCredentialV1Beta1 | ||
: KubeObjectV1 | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="ExecCredentialV1Beta1"/>. | ||
/// </summary> | ||
public ExecCredentialV1Beta1() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// The credential plugin's status. | ||
/// </summary> | ||
public Dictionary<string, object> Status { get; } = new Dictionary<string, object>(); | ||
|
||
/// <summary> | ||
/// Determine whether the credential status should be serialised. | ||
/// </summary> | ||
/// <returns> | ||
/// <c>true</c>, if the credential status should be serialised; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool ShouldSerializeStatus() => Status.Count > 0; | ||
|
||
/// <summary> | ||
/// Get the value of the "status/token" field (if present). | ||
/// </summary> | ||
/// <returns> | ||
/// The token, or <c>null</c> if the field is not present. | ||
/// </returns> | ||
public string GetToken() | ||
{ | ||
if (Status.TryGetValue("token", out object token)) | ||
return token as string; | ||
|
||
return null; | ||
} | ||
} | ||
} |