Skip to content

Commit c291fa8

Browse files
committed
try with ssl conditionally
1 parent 088621e commit c291fa8

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

klass-api/src/main/java/no/ssb/klass/api/config/OpenSearchConfig.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,27 @@ public class OpenSearchConfig extends AbstractOpenSearchConfiguration {
2828
@Value("${opensearch.password}")
2929
private String password;
3030

31+
@Value("${opensearch.ssl}") // default false
32+
private boolean ssl;
33+
3134
@Override
3235
@Bean
3336
public RestHighLevelClient opensearchClient() {
34-
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
35-
.connectedTo(opensearchUri.replace("http://", "").replace("https://", ""))
36-
.usingSsl()
37-
.withBasicAuth(username, password)
38-
.withConnectTimeout(Duration.ofSeconds(10))
39-
.withSocketTimeout(Duration.ofSeconds(5))
40-
.build();
37+
ClientConfiguration clientConfiguration =
38+
(ssl
39+
? ClientConfiguration.builder()
40+
.connectedTo(opensearchUri.replace("http://", "").replace("https://", ""))
41+
.usingSsl()
42+
.withBasicAuth(username, password)
43+
.withConnectTimeout(Duration.ofSeconds(10))
44+
.withSocketTimeout(Duration.ofSeconds(5))
45+
: ClientConfiguration.builder()
46+
.connectedTo(opensearchUri.replace("http://", "").replace("https://", ""))
47+
.withBasicAuth(username, password)
48+
.withConnectTimeout(Duration.ofSeconds(10))
49+
.withSocketTimeout(Duration.ofSeconds(5))
50+
).build();
51+
4152
return RestClients.create(clientConfiguration).rest();
4253
}
4354

klass-api/src/main/resources/application-open-search-test.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ opensearch.url=https://localhost:9200
33
opensearch.username=admin
44
opensearch.password=admin
55

6+
opensearch.ssl=False

klass-api/src/main/resources/application-remote-open-search.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ klass.env.search.elasticsearch.index=klass
22
opensearch.username=${OPEN_SEARCH_USERNAME}
33
opensearch.url=${OPEN_SEARCH_URI}
44
opensearch.password=${OPEN_SEARCH_PASSWORD}
5+
opensearch.ssl=True
56

67
logging.level.org.apache.http=DEBUG
78
logging.level.org.opensearch.client=DEBUG

0 commit comments

Comments
 (0)