Fix declaration of authentication environment variables and add test. (#459)

* Fix declaration of authentication environment variables and add test.

* Run dotnet format

* Run dotnet format
This commit is contained in:
Richard Semmens
2020-06-28 06:44:14 +01:00
committed by GitHub
parent 187ec8fb18
commit b5f5681b21
3 changed files with 61 additions and 14 deletions

View File

@@ -407,16 +407,7 @@ namespace k8s
throw new KubeConfigException("Refresh not supported.");
}
/// <summary>
/// Implementation of the proposal for out-of-tree client
/// authentication providers as described here --
/// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md
/// Took inspiration from python exec_provider.py --
/// https://github.com/kubernetes-client/python-base/blob/master/config/exec_provider.py
/// </summary>
/// <param name="config">The external command execution configuration</param>
/// <returns>The token received from the external command execution</returns>
public static string ExecuteExternalCommand(ExternalExecution config)
public static Process CreateRunnableExternalProcess(ExternalExecution config)
{
var execInfo = new Dictionary<string, dynamic>
{
@@ -430,10 +421,19 @@ namespace k8s
process.StartInfo.EnvironmentVariables.Add("KUBERNETES_EXEC_INFO", JsonConvert.SerializeObject(execInfo));
if (config.EnvironmentVariables != null)
{
foreach (var configEnvironmentVariableKey in config.EnvironmentVariables.Keys)
foreach (var configEnvironmentVariable in config.EnvironmentVariables)
{
process.StartInfo.EnvironmentVariables.Add(key: configEnvironmentVariableKey,
value: config.EnvironmentVariables[configEnvironmentVariableKey]);
if (configEnvironmentVariable.ContainsKey("name") && configEnvironmentVariable.ContainsKey("value"))
{
process.StartInfo.EnvironmentVariables.Add(
configEnvironmentVariable["name"],
configEnvironmentVariable["value"]);
}
else
{
var badVariable = string.Join(",", configEnvironmentVariable.Select(x => $"{x.Key}={x.Value}"));
throw new KubeConfigException($"Invalid environment variable defined: {badVariable}");
}
}
}
@@ -447,6 +447,22 @@ namespace k8s
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
return process;
}
/// <summary>
/// Implementation of the proposal for out-of-tree client
/// authentication providers as described here --
/// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md
/// Took inspiration from python exec_provider.py --
/// https://github.com/kubernetes-client/python-base/blob/master/config/exec_provider.py
/// </summary>
/// <param name="config">The external command execution configuration</param>
/// <returns>The token received from the external command execution</returns>
public static string ExecuteExternalCommand(ExternalExecution config)
{
var process = CreateRunnableExternalProcess(config);
try
{
process.Start();