@@ -224,22 +224,7 @@ private void CreateHttpClient(DelegatingHandler[] handlers)
224
224
/// Set credentials for the Client
225
225
/// </summary>
226
226
/// <param name="config">k8s client configuration</param>
227
- private void SetCredentials ( KubernetesClientConfiguration config )
228
- {
229
- // set the Credentails for token based auth
230
- if ( ! string . IsNullOrWhiteSpace ( config . AccessToken ) )
231
- {
232
- Credentials = new TokenCredentials ( config . AccessToken ) ;
233
- }
234
- else if ( ! string . IsNullOrWhiteSpace ( config . Username ) && ! string . IsNullOrWhiteSpace ( config . Password ) )
235
- {
236
- Credentials = new BasicAuthenticationCredentials
237
- {
238
- UserName = config . Username ,
239
- Password = config . Password
240
- } ;
241
- }
242
- }
227
+ private void SetCredentials ( KubernetesClientConfiguration config ) => Credentials = CreateCredentials ( config ) ;
243
228
244
229
/// <summary>
245
230
/// SSl Cert Validation Callback
@@ -296,5 +281,22 @@ public static bool CertificateValidationCallBack(
296
281
// In all other cases, return false.
297
282
return false ;
298
283
}
284
+
285
+ /// <summary>Creates <see cref="ServiceClientCredentials"/> based on the given config, or returns null if no such credentials are
286
+ /// needed.
287
+ /// </summary>
288
+ public static ServiceClientCredentials CreateCredentials ( KubernetesClientConfiguration config )
289
+ {
290
+ if ( config == null ) throw new ArgumentNullException ( nameof ( config ) ) ;
291
+ if ( ! string . IsNullOrEmpty ( config . AccessToken ) )
292
+ {
293
+ return new TokenCredentials ( config . AccessToken ) ;
294
+ }
295
+ else if ( ! string . IsNullOrEmpty ( config . Username ) )
296
+ {
297
+ return new BasicAuthenticationCredentials ( ) { UserName = config . Username , Password = config . Password } ;
298
+ }
299
+ return null ;
300
+ }
299
301
}
300
302
}
0 commit comments