1313package io .kubernetes .client .util ;
1414
1515import io .kubernetes .client .ApiClient ;
16+ import okio .ByteString ;
1617import org .apache .log4j .Logger ;
1718
1819import javax .net .ssl .KeyManager ;
2526import java .io .InputStream ;
2627import java .io .InputStreamReader ;
2728import java .io .Reader ;
29+ import java .nio .charset .Charset ;
2830
2931public class Config {
3032 public static final String SERVICEACCOUNT_ROOT =
@@ -38,6 +40,7 @@ public class Config {
3840 public static final String ENV_SERVICE_PORT = "KUBERNETES_SERVICE_PORT" ;
3941 // The last resort host to try
4042 public static final String DEFAULT_FALLBACK_HOST = "http://localhost:8080" ;
43+ public static final Charset BASIC_AUTH_CHARSET = Charset .forName ("ISO-8859-1" );
4144
4245 private static final Logger log = Logger .getLogger (Config .class );
4346
@@ -75,8 +78,9 @@ public static ApiClient fromUserPassword(String url, String user, String passwor
7578
7679 public static ApiClient fromUserPassword (String url , String user , String password , boolean validateSSL ) {
7780 ApiClient client = fromUrl (url , validateSSL );
78- client .setUsername (user );
79- client .setPassword (password );
81+ final String usernameAndPassword = user + ":" + password ;
82+ client .setApiKeyPrefix ("Basic" );
83+ client .setApiKey (ByteString .of (usernameAndPassword .getBytes (BASIC_AUTH_CHARSET )).base64 ());
8084 return client ;
8185 }
8286
@@ -86,7 +90,8 @@ public static ApiClient fromToken(String url, String token) {
8690
8791 public static ApiClient fromToken (String url , String token , boolean validateSSL ) {
8892 ApiClient client = fromUrl (url , validateSSL );
89- client .setAccessToken (token );
93+ client .setApiKeyPrefix ("Bearer" );
94+ client .setApiKey (token );
9095 return client ;
9196 }
9297
0 commit comments