@@ -407,16 +407,7 @@ public static string RenewAzureToken(string tenantId, string clientId, string ap
407
407
throw new KubeConfigException ( "Refresh not supported." ) ;
408
408
}
409
409
410
- /// <summary>
411
- /// Implementation of the proposal for out-of-tree client
412
- /// authentication providers as described here --
413
- /// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md
414
- /// Took inspiration from python exec_provider.py --
415
- /// https://github.com/kubernetes-client/python-base/blob/master/config/exec_provider.py
416
- /// </summary>
417
- /// <param name="config">The external command execution configuration</param>
418
- /// <returns>The token received from the external command execution</returns>
419
- public static string ExecuteExternalCommand ( ExternalExecution config )
410
+ public static Process CreateRunnableExternalProcess ( ExternalExecution config )
420
411
{
421
412
var execInfo = new Dictionary < string , dynamic >
422
413
{
@@ -430,10 +421,19 @@ public static string ExecuteExternalCommand(ExternalExecution config)
430
421
process . StartInfo . EnvironmentVariables . Add ( "KUBERNETES_EXEC_INFO" , JsonConvert . SerializeObject ( execInfo ) ) ;
431
422
if ( config . EnvironmentVariables != null )
432
423
{
433
- foreach ( var configEnvironmentVariableKey in config . EnvironmentVariables . Keys )
424
+ foreach ( var configEnvironmentVariable in config . EnvironmentVariables )
434
425
{
435
- process . StartInfo . EnvironmentVariables . Add ( key : configEnvironmentVariableKey ,
436
- value : config . EnvironmentVariables [ configEnvironmentVariableKey ] ) ;
426
+ if ( configEnvironmentVariable . ContainsKey ( "name" ) && configEnvironmentVariable . ContainsKey ( "value" ) )
427
+ {
428
+ process . StartInfo . EnvironmentVariables . Add (
429
+ configEnvironmentVariable [ "name" ] ,
430
+ configEnvironmentVariable [ "value" ] ) ;
431
+ }
432
+ else
433
+ {
434
+ var badVariable = string . Join ( "," , configEnvironmentVariable . Select ( x => $ "{ x . Key } ={ x . Value } ") ) ;
435
+ throw new KubeConfigException ( $ "Invalid environment variable defined: { badVariable } ") ;
436
+ }
437
437
}
438
438
}
439
439
@@ -447,6 +447,22 @@ public static string ExecuteExternalCommand(ExternalExecution config)
447
447
process . StartInfo . RedirectStandardError = true ;
448
448
process . StartInfo . UseShellExecute = false ;
449
449
450
+ return process ;
451
+ }
452
+
453
+ /// <summary>
454
+ /// Implementation of the proposal for out-of-tree client
455
+ /// authentication providers as described here --
456
+ /// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md
457
+ /// Took inspiration from python exec_provider.py --
458
+ /// https://github.com/kubernetes-client/python-base/blob/master/config/exec_provider.py
459
+ /// </summary>
460
+ /// <param name="config">The external command execution configuration</param>
461
+ /// <returns>The token received from the external command execution</returns>
462
+ public static string ExecuteExternalCommand ( ExternalExecution config )
463
+ {
464
+ var process = CreateRunnableExternalProcess ( config ) ;
465
+
450
466
try
451
467
{
452
468
process . Start ( ) ;
0 commit comments