Skip to content

Commit

Permalink
Initial models for supporting client-go credential plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tintoy committed Nov 9, 2019
1 parent e5d4cf9 commit c2abb9e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/KubeClient.Extensions.KubeConfig/Models/AuthPluginConfig.cs
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class UserIdentityConfig
[YamlMember(Alias = "auth-provider")]
public AuthProviderConfig AuthProvider { get; set; }

/// <summary>
/// Optional configuration for a client-go credential plugin.
/// </summary>
[YamlMember(Alias = "exec")]
public CredentialPluginConfig Exec { get; set; }

/// <summary>
/// A file containing the PEM-encoded client certificate to use.
/// </summary>
Expand Down
46 changes: 46 additions & 0 deletions src/KubeClient/Models/ExecCredentialV1Beta1.cs
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;
}
}
}

0 comments on commit c2abb9e

Please sign in to comment.