Skip to content

Commit

Permalink
Rydder
Browse files Browse the repository at this point in the history
  • Loading branch information
espenwaaga committed Apr 27, 2023
1 parent cc8d9f6 commit be7e7ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,37 @@ static String contextPathFor(FpApplication application, Environment currentEnvir
throw new IllegalArgumentException("Utviklerfeil: angitt app er ikke i fp-familien");
}
var appname = application.name().toLowerCase();
var cluster = currentEnvironment.getCluster();

if (cluster.isLocal()) {
return Optional.ofNullable(currentEnvironment.getProperty(application.name().toLowerCase() + ".override.url"))
.orElseGet(() -> String.format("http://localhost:%s/%s", LOCAL_PORTS.get(application), appname));
if (currentEnvironment.isLocal()) {
return urlForLocal(application, currentEnvironment, appname);
}

var clusterForApplication = getClusterTilFPApplikasjonenSomSkalKalles(application, currentEnvironment);
if (cluster.isCoLocated(clusterForApplication)) {
return String.format("http://%s/%s", appname, appname);
} else {
var prefix = "https://" + appname;
if (currentEnvironment.isFss()) { // Kaller fra FSS til GCP
return prefix + ".intern" + (cluster.isProd() ? "" : ".dev") + ".nav.no/" + appname;
} else { // Kaller fra GCP til FSS
if (FPSAK.equals(application)) {
prefix += "-api";
}
return prefix + "." + clusterForApplication.clusterName() + "-pub.nais.io/" + appname;
if (currentEnvironment.getCluster().isCoLocated(clusterForApplication)) {
return String.format("http://%s/%s", appname, appname); // service discovery
}

return urlForCommunicationBetweenDifferentClusters(application, currentEnvironment, appname, clusterForApplication);

}

private static String urlForCommunicationBetweenDifferentClusters(FpApplication application, Environment currentEnvironment, String appname, Cluster clusterForApplication) {
var prefix = "https://" + appname;
if (currentEnvironment.isFss()) { // Kaller fra FSS til GCP
return prefix + ".intern" + (currentEnvironment.isProd() ? "" : ".dev") + ".nav.no/" + appname;
} else { // Kaller fra GCP til FSS
if (FPSAK.equals(application)) {
prefix += "-api";
}
return prefix + "." + clusterForApplication.clusterName() + "-pub.nais.io/" + appname;
}
}

private static String urlForLocal(FpApplication application, Environment currentEnvironment, String appname) {
return Optional.ofNullable(currentEnvironment.getProperty(application.name().toLowerCase() + ".override.url"))
.orElseGet(() -> String.format("http://localhost:%s/%s", LOCAL_PORTS.get(application), appname));
}

static String scopesFor(FpApplication application, Environment currentEnvironment) {
if (currentEnvironment.isLocal()) {
return "api://" + Cluster.VTP.clusterName() + "." + FORELDREPENGER.getName() + "." + Cluster.VTP.clusterName() + "/.default";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class FpApplicationTest {

Check notice

Code scanning / CodeQL

Unused classes and interfaces Note

Unused class: FpApplicationTest is not referenced within this codebase. If not used as an external API it should be removed.

private Environment environment = Mockito.mock(Environment.class);
private final Environment environment = Mockito.mock(Environment.class);

@Test
void test_at_service_discovery_brukes_mellom_FPAppp_i_samme_cluster() {
Expand Down Expand Up @@ -49,7 +49,7 @@ void test_at_gcp_til_fpsak_i_fss_bruker_ingress_av_type_pub() {
@Test
void test_at_vi_bruker_default_lokalhost_ved_lokal_kjøring_uten_override_url_satt() {
when(environment.getCluster()).thenReturn(Cluster.VTP);
when(environment.isDev()).thenReturn(true);
when(environment.isLocal()).thenReturn(true);
when(environment.getProperty("fpabakus.override.url")).thenReturn(null);
var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, environment);
assertThat(contextPath).isEqualTo("http://localhost:8015/fpabakus");
Expand All @@ -59,6 +59,7 @@ void test_at_gcp_til_fpsak_i_fss_bruker_ingress_av_type_pub() {
void bruk_override_url_hvis_oppgitt_og_cluster_er_vtp() {
var overrideUrl = "http://override.url/";
when(environment.getCluster()).thenReturn(Cluster.VTP);
when(environment.isLocal()).thenReturn(true);
when(environment.getProperty("fpabakus.override.url")).thenReturn(overrideUrl);
var contextPath = FpApplication.contextPathFor(FpApplication.FPABAKUS, environment);
assertThat(contextPath).isEqualTo(overrideUrl);
Expand Down

0 comments on commit be7e7ad

Please sign in to comment.