Skip to content

Commit

Permalink
Revert "change/opensearch_config_cleanup (#3693)"
Browse files Browse the repository at this point in the history
This reverts commit ce0806d.
  • Loading branch information
stigus committed Dec 16, 2024
1 parent ce0806d commit 891f4c8
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 76 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,17 +13,18 @@
@Service
public class ElasticParamsConsumer {

private final WebClient webClient;
private final String username;
private final String password;
private final String index;
private WebClient webClient;
private String username;
private String password;
private 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: 3 additions & 1 deletion apps/dolly-backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 @@ -30,6 +29,9 @@ management:

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

consumers:
Expand Down
10 changes: 6 additions & 4 deletions apps/dolly-backend/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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 @@ -11,8 +10,11 @@ jira:

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

consumers:
kodeverk-api:
Expand Down
2 changes: 2 additions & 0 deletions apps/oppsummeringsdokument-service/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ 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,5 +1,6 @@
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 @@ -8,6 +9,7 @@
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 @@ -16,7 +18,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,11 +1,4 @@
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
index: local
uri: http://localhost:9200
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
@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("#{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
@Value("${AZURE_NAV_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_NAV_APP_CLIENT_SECRET:#{null}}") String clientSecret
) {
super(clientId, clientSecret);
this.tokenEndpoint = tokenEndpoint;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 @@ -9,20 +8,23 @@
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("#{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
@Value("${AZURE_TRYGDEETATEN_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_TRYGDEETATEN_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 @@ -36,5 +38,4 @@ 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,16 +6,9 @@
@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("#{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
@Value("${AZURE_APP_CLIENT_ID:#{null}}") String clientId,
@Value("${AZURE_APP_CLIENT_SECRET:#{null}}") String clientSecret
) {
super(clientId, clientSecret);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package no.nav.testnav.libs.securitycore.domain.azuread;

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

@EqualsAndHashCode
@Getter
@Data
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

This file was deleted.

0 comments on commit 891f4c8

Please sign in to comment.