Skip to content

Commit

Permalink
change/opensearch_config_cleanup (#3693)
Browse files Browse the repository at this point in the history
Endret noe config knyttet til OpenSearch.
  • Loading branch information
rfc3092 authored Dec 13, 2024
1 parent 40028ab commit ce0806d
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
@EnableElasticsearchRepositories("no.nav.dolly.elastic")
public class OpenSearchConfig extends AbstractOpenSearchConfiguration {

@Value("${open.search.username}")
@Value("${OPEN_SEARCH_USERNAME}")
private String username;

@Value("${open.search.password}")
@Value("${OPEN_SEARCH_PASSWORD}")
private String password;

@Value("${open.search.uri}")
@Value("${OPEN_SEARCH_URI}")
private String uri;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@EnableElasticsearchRepositories("no.nav.dolly.elastic")
public class OpenSearchLocalConfig extends AbstractOpenSearchConfiguration {

@Value("${open.search.uri}")
@Value("${OPEN_SEARCH_URI}")
private String uri;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
@Service
public class ElasticParamsConsumer {

private WebClient webClient;
private String username;
private String password;
private String index;
private final WebClient webClient;
private final String username;
private final String password;
private final String index;

public ElasticParamsConsumer(
WebClient.Builder webClientBuilder,
@Value("${open.search.username}") String username,
@Value("${open.search.password}") String password,
@Value("${open.search.uri}") String uri,
@Value("${OPEN_SEARCH_USERNAME:''}") String username,
@Value("${OPEN_SEARCH_PASSWORD:''}") String password,
@Value("${OPEN_SEARCH_URI}") String uri,
@Value("${open.search.index}") String index) {

webClient = webClientBuilder
.baseUrl(uri)
.build();
Expand Down
4 changes: 1 addition & 3 deletions apps/dolly-backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AZURE_APP_CLIENT_ID: ${sm://azure-app-client-id}
AZURE_APP_CLIENT_SECRET: ${sm://azure-app-client-secret}
OPEN_SEARCH_URI: http://localhost:9200

dolly:
client:
Expand Down Expand Up @@ -29,9 +30,6 @@ management:

open:
search:
uri: http://localhost:9200
username: dummy
password: dummy
index: local

consumers:
Expand Down
10 changes: 4 additions & 6 deletions apps/dolly-backend/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
OPEN_SEARCH_URI: dummy
TOKEN_X_ISSUER: dummy

APP_NAME: dolly
APP_VERSION: ${application.version}
environment: localhost
TOKEN_X_ISSUER: dummy

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

open:
search:
uri: dummy
username: dummy
password: dummy
total-fields: 150
index: dummy
index: test

consumers:
kodeverk-api:
Expand Down
2 changes: 0 additions & 2 deletions apps/oppsummeringsdokument-service/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,5 @@ spec:
memory: 1024Mi
limits:
memory: 2048Mi
envFrom:
- secret: teamdolly-opensearch
ingresses:
- "https://testnav-oppsummeringsdokument-service.intern.dev.nav.no"
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.testnav.apps.oppsummeringsdokumentservice.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opensearch.client.RestHighLevelClient;
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration;
Expand All @@ -9,7 +8,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

import java.time.Duration;

Expand All @@ -18,7 +16,7 @@
@Profile("dev")
public class OpenSearchLocalConfig extends AbstractOpenSearchConfiguration {

@Value("${open.search.uri}")
@Value("${OPEN_SEARCH_URI}")
private String uri;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
@Configuration
public class OpensearchConfig extends AbstractOpenSearchConfiguration {

@Value("${open.search.username}")
@Value("${OPEN_SEARCH_USERNAME}")
private String username;

@Value("${open.search.password}")
@Value("${OPEN_SEARCH_PASSWORD}")
private String password;

@Value("${open.search.uri}")
@Value("${OPEN_SEARCH_URI}")
private String uri;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
AZURE_APP_CLIENT_ID: ${sm://azure-app-client-id}
AZURE_APP_CLIENT_SECRET: ${sm://azure-app-client-secret}
OPEN_SEARCH_URI: http://localhost:9200

spring:
config:
import: "sm://"

open:
search:
index: local
uri: http://localhost:9200
index: local
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
@EqualsAndHashCode(callSuper = false)
@Configuration
public class AzureNavProxyClientCredential extends ClientCredential {

private final String tokenEndpoint;

public AzureNavProxyClientCredential(
@Value("${AZURE_NAV_OPENID_CONFIG_TOKEN_ENDPOINT:#{null}}") String tokenEndpoint,
@Value("${AZURE_NAV_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_NAV_APP_CLIENT_SECRET:#{null}}") String clientSecret
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
) {
super(clientId, clientSecret);
this.tokenEndpoint = tokenEndpoint;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.testnav.libs.reactivesecurity.domain;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

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

@Configuration
@Getter
public class AzureTrygdeetatenClientCredential extends ClientCredential {

private final String tokenEndpoint;

public AzureTrygdeetatenClientCredential(
@Value("${AZURE_TRYGDEETATEN_OPENID_CONFIG_TOKEN_ENDPOINT:#{null}}") String tokenEndpoint,
@Value("${AZURE_TRYGDEETATEN_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_TRYGDEETATEN_APP_CLIENT_SECRET:#{null}}") String clientSecret
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
) {
super(clientId, clientSecret);
this.tokenEndpoint = tokenEndpoint;
}

public String getTokenEndpoint() {
return tokenEndpoint;
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -38,4 +36,5 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(super.hashCode(), tokenEndpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
@Configuration
public class AzureNavClientCredential extends ClientCredential {

/*
TODO: A better solution, for another day:
1. No longer import AzureNavClientCredential - generify this, or use factories. It cannot be a @Configuration for its own @Bean.
2. Create two beans, one for @Profile("test"), one on @ConditionalOnMissingBean.
3. Check if we really need subclasses for this, or if ClientCredential will suffice. Check all other extends ClientCredential.
This class is effectively both a @Configuration and a @Bean with immutable config, which doesn't play nice.
*/
public AzureNavClientCredential(
@Value("${AZURE_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_APP_CLIENT_SECRET:#{null}}") String clientSecret
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId,
@Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret
) {
super(clientId, clientSecret);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package no.nav.testnav.libs.securitycore.domain.azuread;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.util.Assert;

@Data
@EqualsAndHashCode
@Getter
public class ClientCredential {

private static final String MISSING_CONFIG_MESSAGE = "AZURE_NAV_APP_CLIENT_ID and AZURE_NAV_APP_CLIENT_SECRET must be set";

private final String clientId;
private final String clientSecret;

public ClientCredential(String clientId, String clientSecret) {
Assert.noNullElements(new String[]{clientId, clientSecret}, MISSING_CONFIG_MESSAGE);

this.clientId = clientId;
this.clientSecret = clientSecret;
}

@Override
public final String toString() {
return "ClientCredential{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"properties": [
{
"name": "AZURE_APP_CLIENT_ID",
"type": "java.lang.String",
"description": "Settes av NAIS i pod, må overstyres med secret ved kjøring lokalt."
},
{
"name": "AZURE_APP_CLIENT_SECRET",
"type": "java.lang.String",
"description": "Settes av NAIS i pod, må overstyres med secret ved kjøring lokalt."
}
] }

0 comments on commit ce0806d

Please sign in to comment.