-
Notifications
You must be signed in to change notification settings - Fork 23
/
LightblueClientConfiguration.java
368 lines (318 loc) · 11.5 KB
/
LightblueClientConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package com.redhat.lightblue.client;
import com.redhat.lightblue.client.MongoExecution.ReadPreference;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class LightblueClientConfiguration {
public enum Compression {
NONE, LZF;
public static Compression parseCompression(String str) {
switch (str) {
case "NONE":
return NONE;
case "LZF":
return LZF;
default:
throw new IllegalArgumentException("Invalid compression " + str + ". Supported values are: NONE, LZF");
}
}
}
public static String CA_CERT_FILE_DELIMITER = ",";
private String dataServiceURI;
private String metadataServiceURI;
private boolean acceptSelfSignedCert = false;
private boolean useCertAuth = false;
private String basicAuthUsername;
private String basicAuthPassword;
public String getBasicAuthUsername() {
return basicAuthUsername;
}
public void setBasicAuthUsername(String basicAuthUsername) {
this.basicAuthUsername = basicAuthUsername;
}
public String getBasicAuthPassword() {
return basicAuthPassword;
}
public void setBasicAuthPassword(String basicAuthPassword) {
this.basicAuthPassword = basicAuthPassword;
}
private String caFilePath;
private String certFilePath;
private String certPassword;
private String certAlias;
private Compression compression = Compression.LZF;
private ReadPreference readPreference;
private String writeConcern;
private Integer maxQueryTimeMS;
private transient Execution execution;
public LightblueClientConfiguration() {
}
/**
* Copy constructor.
*/
public LightblueClientConfiguration(LightblueClientConfiguration configuration) {
dataServiceURI = configuration.dataServiceURI;
metadataServiceURI = configuration.metadataServiceURI;
acceptSelfSignedCert = configuration.acceptSelfSignedCert;
useCertAuth = configuration.useCertAuth;
caFilePath = configuration.caFilePath;
certFilePath = configuration.certFilePath;
certPassword = configuration.certPassword;
certAlias = configuration.certAlias;
compression = configuration.compression;
readPreference = configuration.readPreference;
writeConcern = configuration.writeConcern;
maxQueryTimeMS = configuration.maxQueryTimeMS;
}
/**
*
* @return boolean whether or not the caFilePath value is actually a delimited list
* representing multiple CA certs
*/
public boolean hasMultipleCaCerts() {
return (caFilePath.contains(CA_CERT_FILE_DELIMITER));
}
/**
*
* @return List<String> of caFilePaths generated from parsing the caFilePath
* value using the value specified by the CA_CERT_FILE_DELIMITER constant.
* If caFilePath value is not delimited, returns a List with only one path in it.
*/
public List<String> getCaFilePaths() {
List<String> caFilePaths = new ArrayList<>();
if(StringUtils.isNotBlank(caFilePath)) {
if(hasMultipleCaCerts()) {
caFilePaths = Arrays.asList(caFilePath.split(CA_CERT_FILE_DELIMITER));
} else {
caFilePaths.add(caFilePath);
}
}
return caFilePaths;
}
public String getDataServiceURI() {
return dataServiceURI;
}
public void setDataServiceURI(String dataServiceURI) {
this.dataServiceURI = dataServiceURI;
}
public String getMetadataServiceURI() {
return metadataServiceURI;
}
public void setMetadataServiceURI(String metadataServiceURI) {
this.metadataServiceURI = metadataServiceURI;
}
public boolean useCertAuth() {
return useCertAuth;
}
public void setUseCertAuth(boolean useCertAuth) {
this.useCertAuth = useCertAuth;
}
/**
* @return Reference for the CA file used to authenticate the validity of
* the LB server certificate. Should either be on the classpath, or prefixed
* with 'file://'.
*/
public String getCaFilePath() {
if(StringUtils.isNotBlank(caFilePath) && hasMultipleCaCerts()) {
throw new IllegalStateException("There are multiple CA cert paths defined, use getCaFilePaths() instead");
}
return caFilePath;
}
/**
* @param caFilePath Reference for the CA file used to authenticate the
* validity of the LB server certificate. Should either be on the classpath,
* or prefixed with 'file://'.
*/
public void setCaFilePath(String caFilePath) {
this.caFilePath = caFilePath;
}
/**
* @return Reference for the private key of the LB client. Should either be
* on the classpath, or prefixed with 'file://'/
*/
public String getCertFilePath() {
return certFilePath;
}
/**
* @param certFilePath Reference for the private key of the LB client.
* Should either be on the classpath, or prefixed with 'file://'/
*/
public void setCertFilePath(String certFilePath) {
this.certFilePath = certFilePath;
}
public String getCertPassword() {
return certPassword;
}
public void setCertPassword(String certPassword) {
this.certPassword = certPassword;
}
public String getCertAlias() {
return certAlias;
}
public Compression getCompression() {
return compression;
}
public void setCompression(Compression compression) {
this.compression = compression;
}
public ReadPreference getReadPreference() {
return readPreference;
}
public void setReadPreference(ReadPreference readPreference) {
this.readPreference = readPreference;
}
public String getWriteConcern() {
return writeConcern;
}
public void setWriteConcern(String writeConcern) {
this.writeConcern = writeConcern;
}
public Integer getMaxQueryTimeMS() {
return maxQueryTimeMS;
}
public void setMaxQueryTimeMS(Integer maxQueryTimeMS) {
this.maxQueryTimeMS = maxQueryTimeMS;
}
public Execution getExecution() {
if (execution == null) {
MongoExecution mongoExecution = new MongoExecution();
if (getReadPreference() != null) {
mongoExecution.addReadPreference(getReadPreference());
execution = mongoExecution;
}
if (getWriteConcern() != null) {
mongoExecution.addWriteConcern(getWriteConcern());
execution = mongoExecution;
}
if (getMaxQueryTimeMS() != null) {
mongoExecution.addMaxQueryTimeMS(getMaxQueryTimeMS());
execution = mongoExecution;
}
}
return execution;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LightblueClientConfiguration other = (LightblueClientConfiguration) obj;
if (caFilePath == null) {
if (other.caFilePath != null) {
return false;
}
} else if (!caFilePath.equals(other.caFilePath)) {
return false;
}
if (certAlias == null) {
if (other.certAlias != null) {
return false;
}
} else if (!certAlias.equals(other.certAlias)) {
return false;
}
if (certFilePath == null) {
if (other.certFilePath != null) {
return false;
}
} else if (!certFilePath.equals(other.certFilePath)) {
return false;
}
if (certPassword == null) {
if (other.certPassword != null) {
return false;
}
} else if (!certPassword.equals(other.certPassword)) {
return false;
}
if (compression != other.compression) {
return false;
}
if (dataServiceURI == null) {
if (other.dataServiceURI != null) {
return false;
}
} else if (!dataServiceURI.equals(other.dataServiceURI)) {
return false;
}
if (maxQueryTimeMS == null) {
if (other.maxQueryTimeMS != null) {
return false;
}
} else if (!maxQueryTimeMS.equals(other.maxQueryTimeMS)) {
return false;
}
if (metadataServiceURI == null) {
if (other.metadataServiceURI != null) {
return false;
}
} else if (!metadataServiceURI.equals(other.metadataServiceURI)) {
return false;
}
if (readPreference != other.readPreference) {
return false;
}
if (useCertAuth != other.useCertAuth) {
return false;
}
if (writeConcern == null) {
if (other.writeConcern != null) {
return false;
}
} else if (!writeConcern.equals(other.writeConcern)) {
return false;
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((caFilePath == null) ? 0 : caFilePath.hashCode());
result = prime * result + ((certAlias == null) ? 0 : certAlias.hashCode());
result = prime * result + ((certFilePath == null) ? 0 : certFilePath.hashCode());
result = prime * result + ((certPassword == null) ? 0 : certPassword.hashCode());
result = prime * result + ((compression == null) ? 0 : compression.hashCode());
result = prime * result + ((dataServiceURI == null) ? 0 : dataServiceURI.hashCode());
result = prime * result + ((maxQueryTimeMS == null) ? 0 : maxQueryTimeMS.hashCode());
result = prime * result + ((metadataServiceURI == null) ? 0 : metadataServiceURI.hashCode());
result = prime * result + ((readPreference == null) ? 0 : readPreference.hashCode());
result = prime * result + (acceptSelfSignedCert ? 1232 : 1238);
result = prime * result + (useCertAuth ? 1231 : 1237);
result = prime * result + ((writeConcern == null) ? 0 : writeConcern.hashCode());
return result;
}
@Override
public String toString() {
return "LightblueClientConfiguration [dataServiceURI=" + dataServiceURI
+ ", metadataServiceURI=" + metadataServiceURI
+ ", acceptSelfSignedCert=" + acceptSelfSignedCert
+ ", useCertAuth=" + useCertAuth
+ ", caFilePath=" + caFilePath
+ ", certFilePath=" + certFilePath
+ ", certPassword=" + certPassword
+ ", certAlias=" + certAlias
+ ", compression=" + compression
+ ", readPreference=" + readPreference
+ ", writeConcern=" + writeConcern
+ ", maxQueryTimeMS=" + maxQueryTimeMS
+ "]";
}
public boolean isAcceptSelfSignedCert() {
return acceptSelfSignedCert;
}
public void setAcceptSelfSignedCert(boolean acceptSelfSignedCert) {
this.acceptSelfSignedCert = acceptSelfSignedCert;
}
public void setCertAlias(String certAlias) {
this.certAlias = certAlias;
}
}