From 636975b755544ef35975b9215c8cbd26cd109ef5 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Mon, 21 Oct 2024 14:41:55 +0200 Subject: [PATCH] Add protocol support for R2DBC configuration #deploy-levende-arbeidsforhold-ansettelse Introduced protocol field in R2DBC configuration to enhance flexibility. Adjusted configurations to conditionally include host and protocol options if they are present. Updated application configuration files to use the new protocol setting. --- .../config/ApplicationConfig.java | 28 ++++++++++++++----- .../src/main/resources/application-dev.yml | 2 +- .../src/test/resources/application.yaml | 9 ++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/ApplicationConfig.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/ApplicationConfig.java index 46d12627730..43e36d3369b 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/ApplicationConfig.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/ApplicationConfig.java @@ -3,6 +3,7 @@ import io.r2dbc.spi.ConnectionFactories; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryOptions; +import lombok.extern.slf4j.Slf4j; import no.nav.testnav.libs.reactivecore.config.CoreConfig; import no.nav.testnav.libs.reactivesecurity.config.SecureOAuth2ServerToServerConfiguration; import no.nav.testnav.libs.standalone.servletsecurity.config.InsecureJwtServerToServerConfiguration; @@ -20,8 +21,11 @@ import static io.r2dbc.spi.ConnectionFactoryOptions.HOST; import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD; import static io.r2dbc.spi.ConnectionFactoryOptions.PORT; +import static io.r2dbc.spi.ConnectionFactoryOptions.PROTOCOL; import static io.r2dbc.spi.ConnectionFactoryOptions.USER; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +@Slf4j @Configuration @Import({ CoreConfig.class, @@ -37,9 +41,12 @@ public class ApplicationConfig { @Value("${config.r2dbc.driver}") private String driver; - @Value("${config.r2dbc.host}") + @Value("${config.r2dbc.host:null}") private String host; + @Value("${config.r2dbc.protocol:null}") + private String protocol; + @Value("${config.r2dbc.port}") private int port; @@ -56,14 +63,21 @@ public class ApplicationConfig { @Bean ConnectionFactory connectionFactory() { - return ConnectionFactories.get(ConnectionFactoryOptions.builder() + var factory = ConnectionFactoryOptions.builder() .option(DRIVER, driver) - .option(HOST, host) .option(PORT, port) .option(USER, username) .option(PASSWORD, password) - .option(DATABASE, database) - .build()); - } -} + .option(DATABASE, database); + if (isNotBlank(host)) { + factory.option(HOST, host); + } + if (isNotBlank(protocol)) { + factory.option(PROTOCOL, protocol); + } + + log.info("ConnectionFactory: {}", factory.build()); + return ConnectionFactories.get(factory.build()); + } +} \ No newline at end of file diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/resources/application-dev.yml b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/application-dev.yml index 670bcd3d42d..ad82e8c59fc 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/resources/application-dev.yml +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/application-dev.yml @@ -17,7 +17,7 @@ spring: config: r2dbc: driver: h2 - host: localhost + protocol: mem port: 5432 database: testdb username: sa diff --git a/apps/levende-arbeidsforhold-ansettelse/src/test/resources/application.yaml b/apps/levende-arbeidsforhold-ansettelse/src/test/resources/application.yaml index 1f3777c0854..c39ae8c3c2c 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/test/resources/application.yaml +++ b/apps/levende-arbeidsforhold-ansettelse/src/test/resources/application.yaml @@ -1,6 +1,9 @@ -spring: - flyway: - url: jdbc:h2:mem:testdb +config: + r2dbc: + driver: h2 + protocol: mem + port: 5432 + database: testdb username: sa password: \ No newline at end of file