Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Environment tilbyr nais app image name (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Feb 6, 2023
1 parent a9f2502 commit 66de9eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/no/nav/foreldrepenger/konfig/Environment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.nav.foreldrepenger.konfig;

import static java.lang.System.getenv;

import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -29,13 +31,19 @@ public final class Environment {
static final class Init {
// Josh Bloch's lazy load singleton (ref "Effective Java").
// Siden Init ikke lastes før den referes blir feltet her initiert først når den aksesseres første gang.
static final Environment CURRENT = of(Cluster.current(), Namespace.current(), Application.current(), ClientId.current());
static final Environment CURRENT = of(Cluster.current(), Namespace.current(), Application.current(),
ClientId.current(), currentImage());

private Init() {
}

private static Environment of(Cluster cluster, Namespace namespace, Application application, ClientId clientId) {
return new Environment(cluster, namespace, application, clientId);
private static Environment of(Cluster cluster, Namespace namespace, Application application,
ClientId clientId, String image) {
return new Environment(cluster, namespace, application, clientId, image);
}

private static String currentImage() {
return getenv(NaisProperty.IMAGE.propertyName());
}

}
Expand All @@ -44,13 +52,15 @@ private static Environment of(Cluster cluster, Namespace namespace, Application
private final Namespace namespace;
private final Application application;
private final ClientId clientId;
private final String imageName;
private final List<KonfigVerdiProvider> propertySources;

private Environment(Cluster cluster, Namespace namespace, Application application, ClientId clientId) {
private Environment(Cluster cluster, Namespace namespace, Application application, ClientId clientId, String imageName) {
this.cluster = cluster;
this.namespace = namespace;
this.application = application;
this.clientId = clientId;
this.imageName = imageName;
this.propertySources = List.of(
new SystemPropertiesKonfigVerdiProvider(),
new EnvPropertiesKonfigVerdiProvider(),
Expand Down Expand Up @@ -109,6 +119,10 @@ public String clientId() {
return Optional.ofNullable(clientId).map(ClientId::getClientId).orElse(null);
}

public String imageName() {
return imageName;
}

public String getNaisAppName() {
return getProperty(NaisProperty.APPLICATION.propertyName(), "local-app");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum NaisProperty {
NAMESPACE("NAIS_NAMESPACE"),
APPLICATION("NAIS_APP_NAME"),
CLIENTID("NAIS_CLIENT_ID"), // Format <cluster>:<namespace>:<application>
IMAGE("NAIS_APP_IMAGE"), // Format <path>/<app>:<date>-<git hash >
;

private final String name;
Expand Down

0 comments on commit 66de9eb

Please sign in to comment.