22
22
import java .io .FileReader ;
23
23
import java .io .IOException ;
24
24
25
+ import java .io .InputStream ;
25
26
import java .nio .charset .Charset ;
26
27
import java .nio .file .Files ;
27
28
import java .nio .file .Paths ;
40
41
public class ClientBuilder {
41
42
42
43
private String basePath = Config .DEFAULT_FALLBACK_HOST ;
43
- private File certificateAuthorityFile = null ;
44
- private String certificateAuthorityData = null ;
44
+ private byte [] caCertBytes = null ;
45
45
private boolean verifyingSsl = true ;
46
46
private CredentialProvider credentialProvider ;
47
47
@@ -95,7 +95,7 @@ public static ClientBuilder fromCluster() throws IOException {
95
95
96
96
final String token = new String (Files .readAllBytes (Paths .get (SERVICEACCOUNT_TOKEN_PATH )),
97
97
Charset .defaultCharset ());
98
- builder .setCertificateAuthority (new File ( SERVICEACCOUNT_CA_PATH ));
98
+ builder .setCertificateAuthority (Files . readAllBytes ( Paths . get ( SERVICEACCOUNT_CA_PATH ) ));
99
99
builder .setCredentialProvider (new AccessTokenCredentialProvider (token ));
100
100
101
101
return builder ;
@@ -114,7 +114,9 @@ public static ClientBuilder fromKubeConfig(KubeConfig config) throws IOException
114
114
}
115
115
116
116
if (config .verifySSL ()) {
117
- builder .setCertificateAuthority ();
117
+ final byte [] caBytes = KubeConfig .getDataOrFile (config .getCertificateAuthorityData (),
118
+ config .getCertificateAuthorityFile ());
119
+ builder .setCertificateAuthority (caBytes );
118
120
} else {
119
121
builder .setVerifyingSsl (false );
120
122
}
@@ -142,22 +144,8 @@ public ClientBuilder setCredentialProvider(final CredentialProvider credentialPr
142
144
return this ;
143
145
}
144
146
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 ;
161
149
this .verifyingSsl = true ;
162
150
return this ;
163
151
}
@@ -171,7 +159,7 @@ public ClientBuilder setVerifyingSsl(boolean verifyingSsl) {
171
159
return this ;
172
160
}
173
161
174
- public ApiClient build () throws FileNotFoundException {
162
+ public ApiClient build () {
175
163
final ApiClient client = new ApiClient ();
176
164
177
165
if (basePath != null ) {
@@ -183,13 +171,8 @@ public ApiClient build() throws FileNotFoundException {
183
171
184
172
client .setVerifyingSsl (verifyingSsl );
185
173
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 ));
193
176
}
194
177
195
178
if (credentialProvider != null ) {
0 commit comments