2222import java .io .FileReader ;
2323import java .io .IOException ;
2424
25+ import java .io .InputStream ;
2526import java .nio .charset .Charset ;
2627import java .nio .file .Files ;
2728import java .nio .file .Paths ;
4041public class ClientBuilder {
4142
4243 private String basePath = Config .DEFAULT_FALLBACK_HOST ;
43- private File certificateAuthorityFile = null ;
44- private String certificateAuthorityData = null ;
44+ private byte [] caCertBytes = null ;
4545 private boolean verifyingSsl = true ;
4646 private CredentialProvider credentialProvider ;
4747
@@ -95,7 +95,7 @@ public static ClientBuilder fromCluster() throws IOException {
9595
9696 final String token = new String (Files .readAllBytes (Paths .get (SERVICEACCOUNT_TOKEN_PATH )),
9797 Charset .defaultCharset ());
98- builder .setCertificateAuthority (new File ( SERVICEACCOUNT_CA_PATH ));
98+ builder .setCertificateAuthority (Files . readAllBytes ( Paths . get ( SERVICEACCOUNT_CA_PATH ) ));
9999 builder .setCredentialProvider (new AccessTokenCredentialProvider (token ));
100100
101101 return builder ;
@@ -114,7 +114,9 @@ public static ClientBuilder fromKubeConfig(KubeConfig config) throws IOException
114114 }
115115
116116 if (config .verifySSL ()) {
117- builder .setCertificateAuthority ();
117+ final byte [] caBytes = KubeConfig .getDataOrFile (config .getCertificateAuthorityData (),
118+ config .getCertificateAuthorityFile ());
119+ builder .setCertificateAuthority (caBytes );
118120 } else {
119121 builder .setVerifyingSsl (false );
120122 }
@@ -142,22 +144,8 @@ public ClientBuilder setCredentialProvider(final CredentialProvider credentialPr
142144 return this ;
143145 }
144146
145- public File getCertificateAuthorityFile () {
146- return certificateAuthorityFile ;
147- }
148-
149- public ClientBuilder setCertificateAuthority (File certificateAuthorityFile ) {
150- this .certificateAuthorityFile = certificateAuthorityFile ;
151- this .verifyingSsl = true ;
152- return this ;
153- }
154-
155- public String getCertificateAuthorityData () {
156- return certificateAuthorityData ;
157- }
158-
159- public ClientBuilder setCertificateAuthority (String certificateAuthorityData ) {
160- this .certificateAuthorityData = certificateAuthorityData ;
147+ public ClientBuilder setCertificateAuthority (final byte [] caCertBytes ) {
148+ this .caCertBytes = caCertBytes ;
161149 this .verifyingSsl = true ;
162150 return this ;
163151 }
@@ -171,7 +159,7 @@ public ClientBuilder setVerifyingSsl(boolean verifyingSsl) {
171159 return this ;
172160 }
173161
174- public ApiClient build () throws FileNotFoundException {
162+ public ApiClient build () {
175163 final ApiClient client = new ApiClient ();
176164
177165 if (basePath != null ) {
@@ -183,13 +171,8 @@ public ApiClient build() throws FileNotFoundException {
183171
184172 client .setVerifyingSsl (verifyingSsl );
185173
186- if (certificateAuthorityFile != null ) {
187- client .setSslCaCert (new FileInputStream (certificateAuthorityFile ));
188- }
189-
190- if (certificateAuthorityData != null ) {
191- byte [] bytes = Base64 .decodeBase64 (certificateAuthorityData );
192- client .setSslCaCert (new ByteArrayInputStream (bytes ));
174+ if (caCertBytes != null ) {
175+ client .setSslCaCert (new ByteArrayInputStream (caCertBytes ));
193176 }
194177
195178 if (credentialProvider != null ) {
0 commit comments