Skip to content

Commit ce0806d

Browse files
authored
change/opensearch_config_cleanup (#3693)
Endret noe config knyttet til OpenSearch.
1 parent 40028ab commit ce0806d

File tree

14 files changed

+76
-44
lines changed

14 files changed

+76
-44
lines changed

apps/dolly-backend/src/main/java/no/nav/dolly/config/OpenSearchConfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
@EnableElasticsearchRepositories("no.nav.dolly.elastic")
2121
public class OpenSearchConfig extends AbstractOpenSearchConfiguration {
2222

23-
@Value("${open.search.username}")
23+
@Value("${OPEN_SEARCH_USERNAME}")
2424
private String username;
2525

26-
@Value("${open.search.password}")
26+
@Value("${OPEN_SEARCH_PASSWORD}")
2727
private String password;
2828

29-
@Value("${open.search.uri}")
29+
@Value("${OPEN_SEARCH_URI}")
3030
private String uri;
3131

3232
@Override

apps/dolly-backend/src/main/java/no/nav/dolly/config/OpenSearchLocalConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@EnableElasticsearchRepositories("no.nav.dolly.elastic")
2121
public class OpenSearchLocalConfig extends AbstractOpenSearchConfiguration {
2222

23-
@Value("${open.search.uri}")
23+
@Value("${OPEN_SEARCH_URI}")
2424
private String uri;
2525

2626
@Override

apps/dolly-backend/src/main/java/no/nav/dolly/elastic/consumer/ElasticParamsConsumer.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
@Service
1414
public class ElasticParamsConsumer {
1515

16-
private WebClient webClient;
17-
private String username;
18-
private String password;
19-
private String index;
16+
private final WebClient webClient;
17+
private final String username;
18+
private final String password;
19+
private final String index;
2020

2121
public ElasticParamsConsumer(
2222
WebClient.Builder webClientBuilder,
23-
@Value("${open.search.username}") String username,
24-
@Value("${open.search.password}") String password,
25-
@Value("${open.search.uri}") String uri,
23+
@Value("${OPEN_SEARCH_USERNAME:''}") String username,
24+
@Value("${OPEN_SEARCH_PASSWORD:''}") String password,
25+
@Value("${OPEN_SEARCH_URI}") String uri,
2626
@Value("${open.search.index}") String index) {
27-
2827
webClient = webClientBuilder
2928
.baseUrl(uri)
3029
.build();

apps/dolly-backend/src/main/resources/application-local.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
AZURE_APP_CLIENT_ID: ${sm://azure-app-client-id}
22
AZURE_APP_CLIENT_SECRET: ${sm://azure-app-client-secret}
3+
OPEN_SEARCH_URI: http://localhost:9200
34

45
dolly:
56
client:
@@ -29,9 +30,6 @@ management:
2930

3031
open:
3132
search:
32-
uri: http://localhost:9200
33-
username: dummy
34-
password: dummy
3533
index: local
3634

3735
consumers:

apps/dolly-backend/src/test/resources/application-test.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
OPEN_SEARCH_URI: dummy
2+
TOKEN_X_ISSUER: dummy
3+
14
APP_NAME: dolly
25
APP_VERSION: ${application.version}
3-
environment: localhost
4-
TOKEN_X_ISSUER: dummy
56

67
jira:
78
host: http://localhost:${wiremock.server.port:0}/jira
@@ -10,11 +11,8 @@ jira:
1011

1112
open:
1213
search:
13-
uri: dummy
14-
username: dummy
15-
password: dummy
1614
total-fields: 150
17-
index: dummy
15+
index: test
1816

1917
consumers:
2018
kodeverk-api:

apps/oppsummeringsdokument-service/config.yml

-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,5 @@ spec:
6464
memory: 1024Mi
6565
limits:
6666
memory: 2048Mi
67-
envFrom:
68-
- secret: teamdolly-opensearch
6967
ingresses:
7068
- "https://testnav-oppsummeringsdokument-service.intern.dev.nav.no"

apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/OpenSearchLocalConfig.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package no.nav.testnav.apps.oppsummeringsdokumentservice.config;
22

3-
import lombok.RequiredArgsConstructor;
43
import lombok.extern.slf4j.Slf4j;
54
import org.opensearch.client.RestHighLevelClient;
65
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration;
@@ -9,7 +8,6 @@
98
import org.springframework.beans.factory.annotation.Value;
109
import org.springframework.context.annotation.Configuration;
1110
import org.springframework.context.annotation.Profile;
12-
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
1311

1412
import java.time.Duration;
1513

@@ -18,7 +16,7 @@
1816
@Profile("dev")
1917
public class OpenSearchLocalConfig extends AbstractOpenSearchConfiguration {
2018

21-
@Value("${open.search.uri}")
19+
@Value("${OPEN_SEARCH_URI}")
2220
private String uri;
2321

2422
@Override

apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/OpensearchConfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
@Configuration
1515
public class OpensearchConfig extends AbstractOpenSearchConfiguration {
1616

17-
@Value("${open.search.username}")
17+
@Value("${OPEN_SEARCH_USERNAME}")
1818
private String username;
1919

20-
@Value("${open.search.password}")
20+
@Value("${OPEN_SEARCH_PASSWORD}")
2121
private String password;
2222

23-
@Value("${open.search.uri}")
23+
@Value("${OPEN_SEARCH_URI}")
2424
private String uri;
2525

2626
@Override
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
AZURE_APP_CLIENT_ID: ${sm://azure-app-client-id}
2+
AZURE_APP_CLIENT_SECRET: ${sm://azure-app-client-secret}
3+
OPEN_SEARCH_URI: http://localhost:9200
4+
5+
spring:
6+
config:
7+
import: "sm://"
8+
19
open:
210
search:
3-
index: local
4-
uri: http://localhost:9200
11+
index: local

libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/domain/AzureNavProxyClientCredential.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
@EqualsAndHashCode(callSuper = false)
1212
@Configuration
1313
public class AzureNavProxyClientCredential extends ClientCredential {
14+
1415
private final String tokenEndpoint;
1516

1617
public AzureNavProxyClientCredential(
1718
@Value("${AZURE_NAV_OPENID_CONFIG_TOKEN_ENDPOINT:#{null}}") String tokenEndpoint,
18-
@Value("${AZURE_NAV_APP_CLIENT_ID:#{null}}") String clientId,
19-
@Value("${AZURE_NAV_APP_CLIENT_SECRET:#{null}}") String clientSecret
19+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
20+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
2021
) {
2122
super(clientId, clientSecret);
2223
this.tokenEndpoint = tokenEndpoint;
2324
}
25+
2426
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.testnav.libs.reactivesecurity.domain;
22

3+
import lombok.Getter;
34
import org.springframework.beans.factory.annotation.Value;
45
import org.springframework.context.annotation.Configuration;
56

@@ -8,23 +9,20 @@
89
import no.nav.testnav.libs.securitycore.domain.azuread.ClientCredential;
910

1011
@Configuration
12+
@Getter
1113
public class AzureTrygdeetatenClientCredential extends ClientCredential {
14+
1215
private final String tokenEndpoint;
1316

1417
public AzureTrygdeetatenClientCredential(
1518
@Value("${AZURE_TRYGDEETATEN_OPENID_CONFIG_TOKEN_ENDPOINT:#{null}}") String tokenEndpoint,
16-
@Value("${AZURE_TRYGDEETATEN_APP_CLIENT_ID:#{null}}") String clientId,
17-
@Value("${AZURE_TRYGDEETATEN_APP_CLIENT_SECRET:#{null}}") String clientSecret
19+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
20+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
1821
) {
1922
super(clientId, clientSecret);
2023
this.tokenEndpoint = tokenEndpoint;
2124
}
2225

23-
public String getTokenEndpoint() {
24-
return tokenEndpoint;
25-
}
26-
27-
2826
@Override
2927
public boolean equals(Object o) {
3028
if (this == o) return true;
@@ -38,4 +36,5 @@ public boolean equals(Object o) {
3836
public int hashCode() {
3937
return Objects.hash(super.hashCode(), tokenEndpoint);
4038
}
39+
4140
}

libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavClientCredential.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
@Configuration
77
public class AzureNavClientCredential extends ClientCredential {
88

9+
/*
10+
TODO: A better solution, for another day:
11+
1. No longer import AzureNavClientCredential - generify this, or use factories. It cannot be a @Configuration for its own @Bean.
12+
2. Create two beans, one for @Profile("test"), one on @ConditionalOnMissingBean.
13+
3. Check if we really need subclasses for this, or if ClientCredential will suffice. Check all other extends ClientCredential.
14+
This class is effectively both a @Configuration and a @Bean with immutable config, which doesn't play nice.
15+
*/
916
public AzureNavClientCredential(
10-
@Value("${AZURE_APP_CLIENT_ID:#{null}}") String clientId,
11-
@Value("${AZURE_APP_CLIENT_SECRET:#{null}}") String clientSecret
17+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
18+
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
1219
) {
1320
super(clientId, clientSecret);
1421
}

libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredential.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package no.nav.testnav.libs.securitycore.domain.azuread;
22

3-
import lombok.Data;
3+
import lombok.EqualsAndHashCode;
4+
import lombok.Getter;
5+
import org.springframework.util.Assert;
46

5-
@Data
7+
@EqualsAndHashCode
8+
@Getter
69
public class ClientCredential {
10+
11+
private static final String MISSING_CONFIG_MESSAGE = "AZURE_NAV_APP_CLIENT_ID and AZURE_NAV_APP_CLIENT_SECRET must be set";
12+
713
private final String clientId;
814
private final String clientSecret;
915

16+
public ClientCredential(String clientId, String clientSecret) {
17+
Assert.noNullElements(new String[]{clientId, clientSecret}, MISSING_CONFIG_MESSAGE);
18+
19+
this.clientId = clientId;
20+
this.clientSecret = clientSecret;
21+
}
22+
1023
@Override
1124
public final String toString() {
1225
return "ClientCredential{" +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "AZURE_APP_CLIENT_ID",
5+
"type": "java.lang.String",
6+
"description": "Settes av NAIS i pod, må overstyres med secret ved kjøring lokalt."
7+
},
8+
{
9+
"name": "AZURE_APP_CLIENT_SECRET",
10+
"type": "java.lang.String",
11+
"description": "Settes av NAIS i pod, må overstyres med secret ved kjøring lokalt."
12+
}
13+
] }

0 commit comments

Comments
 (0)