diff --git a/apps/testnorge-statisk-data-forvalter/README.md b/apps/testnorge-statisk-data-forvalter/README.md index ec6f24d12e6..491189e18b5 100644 --- a/apps/testnorge-statisk-data-forvalter/README.md +++ b/apps/testnorge-statisk-data-forvalter/README.md @@ -48,10 +48,6 @@ sterkt anbefalt å følge. Disse applikasjonen er ansvarlige for å opprette man ## Lokal kjøring -Ha naisdevice kjørende og kjør StatiskDataForvalterApplicationStarter med følgende argumenter: -``` --Dspring.cloud.vault.token=[kopier token fra vault] --Dspring.profiles.active=local -``` -Swagger på [http://localhost:8080/swagger](http://localhost:4390/swagger). +* [Generelt.](../../docs/local_general.md) +* [Vault.](../../docs/local_vault.md) diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/StatiskDataForvalterApplicationStarter.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/StatiskDataForvalterApplicationStarter.java index 1caf883368d..51a6ec52371 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/StatiskDataForvalterApplicationStarter.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/StatiskDataForvalterApplicationStarter.java @@ -1,19 +1,18 @@ package no.nav.registre.sdforvalter; -import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.util.VaultUtil; +import no.nav.testnav.libs.vault.VaultUtil; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@Slf4j @SpringBootApplication public class StatiskDataForvalterApplicationStarter { public static void main(String[] args) { + if ("prod".equals(System.getProperty("spring.profiles.active"))) { VaultUtil.initCloudVaultToken(); } - SpringApplication.run(StatiskDataForvalterApplicationStarter.class, args); + } } \ No newline at end of file diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/util/VaultUtil.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/util/VaultUtil.java deleted file mode 100644 index 806c7964b35..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/util/VaultUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -package no.nav.registre.sdforvalter.util; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; - -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.core.env.ConfigurableEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import no.nav.registre.sdforvalter.exception.UgyldigVaultTokenException; - -@Slf4j -public final class VaultUtil { - - private VaultUtil() { - } - - private static final String VAULT_TOKEN_PROPERTY = "VAULT_TOKEN"; - - private static String getVaultToken() { - - AnnotationConfigApplicationContext context = - new AnnotationConfigApplicationContext(); - ConfigurableEnvironment environment = context.getEnvironment(); - - try { - if (environment.containsProperty(VAULT_TOKEN_PROPERTY) && !"".equals(environment.getProperty(VAULT_TOKEN_PROPERTY))) { - return environment.getProperty(VAULT_TOKEN_PROPERTY); - } else if (Files.exists(Paths.get("/var/run/secrets/nais.io/vault/vault_token"))) { - byte[] encoded = Files.readAllBytes(Paths.get("/var/run/secrets/nais.io/vault/vault_token")); - return new String(encoded, StandardCharsets.UTF_8).trim(); - } else { - throw new UgyldigVaultTokenException("Neither VAULT_TOKEN or VAULT_TOKEN_PATH is set"); - } - } catch (Exception e) { - throw new UgyldigVaultTokenException("Could not get a vault token for authentication", e); - } - } - - public static void initCloudVaultToken() { - System.setProperty("spring.cloud.vault.token", getVaultToken()); - log.info(getVaultToken()); - } -}