@@ -444,15 +444,21 @@ private void SetUserDetails(K8SConfiguration k8SConfig, Context activeContext)
444
444
throw new KubeConfigException ( "External command execution missing ApiVersion key" ) ;
445
445
}
446
446
447
- var ( accessToken , clientCertificateData , clientCertificateKeyData ) = ExecuteExternalCommand ( userDetails . UserCredentials . ExternalExecution ) ;
448
- AccessToken = accessToken ;
447
+ var response = ExecuteExternalCommand ( userDetails . UserCredentials . ExternalExecution ) ;
448
+ AccessToken = response . Status . Token ;
449
449
// When reading ClientCertificateData from a config file it will be base64 encoded, and code later in the system (see CertUtils.GeneratePfx)
450
450
// expects ClientCertificateData and ClientCertificateKeyData to be base64 encoded because of this. However the string returned by external
451
451
// auth providers is the raw certificate and key PEM text, so we need to take that and base64 encoded it here so it can be decoded later.
452
- ClientCertificateData = clientCertificateData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( clientCertificateData ) ) ;
453
- ClientCertificateKeyData = clientCertificateKeyData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( clientCertificateKeyData ) ) ;
452
+ ClientCertificateData = response . Status . ClientCertificateData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( response . Status . ClientCertificateData ) ) ;
453
+ ClientCertificateKeyData = response . Status . ClientKeyData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( response . Status . ClientKeyData ) ) ;
454
454
455
455
userCredentialsFound = true ;
456
+
457
+ // TODO: support client certificates here too.
458
+ if ( AccessToken != null )
459
+ {
460
+ TokenProvider = new ExecTokenProvider ( userDetails . UserCredentials . ExternalExecution ) ;
461
+ }
456
462
}
457
463
458
464
if ( ! userCredentialsFound )
@@ -525,7 +531,7 @@ public static Process CreateRunnableExternalProcess(ExternalExecution config)
525
531
/// <returns>
526
532
/// The token, client certificate data, and the client key data received from the external command execution
527
533
/// </returns>
528
- public static ( string , string , string ) ExecuteExternalCommand ( ExternalExecution config )
534
+ public static ExecCredentialResponse ExecuteExternalCommand ( ExternalExecution config )
529
535
{
530
536
if ( config == null )
531
537
{
@@ -562,18 +568,9 @@ public static (string, string, string) ExecuteExternalCommand(ExternalExecution
562
568
$ "external exec failed because api version { responseObject . ApiVersion } does not match { config . ApiVersion } ") ;
563
569
}
564
570
565
- if ( responseObject . Status . ContainsKey ( "token" ) )
566
- {
567
- return ( responseObject . Status [ "token" ] , null , null ) ;
568
- }
569
- else if ( responseObject . Status . ContainsKey ( "clientCertificateData" ) )
571
+ if ( responseObject . Status . IsValid ( ) )
570
572
{
571
- if ( ! responseObject . Status . ContainsKey ( "clientKeyData" ) )
572
- {
573
- throw new KubeConfigException ( $ "external exec failed missing clientKeyData field in plugin output") ;
574
- }
575
-
576
- return ( null , responseObject . Status [ "clientCertificateData" ] , responseObject . Status [ "clientKeyData" ] ) ;
573
+ return responseObject ;
577
574
}
578
575
else
579
576
{
0 commit comments