-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setter registreringsdato til dagen etter stiftelsesdato for nye org (#…
…3439) * Setter registreringsdato til dagen etter stiftelsesdato for nye organisasjoner * Ereg batch status spør mot modapp isteden på q2 * Mer logging og svarer med 404 dersom kall ikke kommer gjennom, slik at org-service ikke blir stuck i loop * Refaktor av batch status henting fra modapp-q2 * Skrevet om ereg-batch-status-service til reactive * Lagt til modapp ereg proxy * Endret oppsett for ereg-batch-status-service og flyttet den til gcp * Refaktorert apper til å fungere med nye ereg-batch-status-service i dev-gcp * Refaktorert org-bestilling-service
- Loading branch information
Showing
42 changed files
with
982 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: modapp-ereg-proxy | ||
|
||
on: | ||
push: | ||
paths: | ||
- libs/reactive-core | ||
- libs/reactive-proxy | ||
- libs/reactive-security | ||
- libs/security-core | ||
- proxies/modapp-ereg-proxy/** | ||
- .github/workflows/proxy.modapp-ereg-proxy.yml | ||
|
||
jobs: | ||
workflow: | ||
uses: ./.github/workflows/common.workflow.backend.yml | ||
with: | ||
cluster: "dev-fss" | ||
working-directory: "proxies/modapp-ereg-proxy" | ||
deploy-tag: "#deploy-proxy" | ||
permissions: | ||
contents: read | ||
id-token: write | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
.../main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/ApplicationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...vice/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/Consumers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package no.nav.registre.testnorge.eregbatchstatusservice.config; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import no.nav.testnav.libs.securitycore.domain.ServerProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static lombok.AccessLevel.PACKAGE; | ||
|
||
/** | ||
* Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. | ||
* <br/><br/> | ||
* Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> | ||
* mellom configuration properties og field names. | ||
* | ||
* @see ServerProperties | ||
*/ | ||
@Configuration | ||
@ConfigurationProperties(prefix = "consumers") | ||
@NoArgsConstructor(access = PACKAGE) | ||
@Getter | ||
@Setter(PACKAGE) | ||
public class Consumers { | ||
|
||
private ServerProperties modappEregProxy; | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
...src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/EregProperties.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 22 additions & 23 deletions
45
...src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/EregConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
package no.nav.registre.testnorge.eregbatchstatusservice.consumer; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.registre.testnorge.eregbatchstatusservice.config.EregProperties; | ||
import no.nav.registre.testnorge.eregbatchstatusservice.config.Consumers; | ||
import no.nav.registre.testnorge.eregbatchstatusservice.consumer.command.GetBatchStatusCommand; | ||
import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; | ||
import no.nav.testnav.libs.securitycore.domain.ServerProperties; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Slf4j | ||
@Component | ||
public class EregConsumer { | ||
private final Map<String, WebClient> envWebClientMap; | ||
private final ServerProperties serverProperties; | ||
private final WebClient webClient; | ||
private final TokenExchange tokenService; | ||
|
||
|
||
public EregConsumer(EregProperties eregProperties) { | ||
public EregConsumer(TokenExchange tokenService, | ||
Consumers consumers | ||
) { | ||
|
||
this.envWebClientMap = eregProperties | ||
.getEnvHostMap() | ||
.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap( | ||
Map.Entry::getKey, | ||
entry -> WebClient.builder() | ||
.baseUrl(entry.getValue()) | ||
.build() | ||
)); | ||
this.tokenService = tokenService; | ||
this.serverProperties = consumers.getModappEregProxy(); | ||
this.webClient = WebClient.builder() | ||
.baseUrl(consumers.getModappEregProxy().getUrl()) | ||
.build(); | ||
} | ||
|
||
public Long getStatusKode(String miljo, Long id) { | ||
if (!envWebClientMap.containsKey(miljo)) { | ||
throw new RuntimeException("Stotter ikke miljo: " + miljo + " i EREG."); | ||
} else { | ||
return new GetBatchStatusCommand(envWebClientMap.get(miljo), id).call(); | ||
} | ||
public Mono<Long> getStatusKode(String miljo, Long id) { | ||
return tokenService | ||
.exchange(serverProperties) | ||
.flatMap(accessToken -> | ||
new GetBatchStatusCommand(webClient, miljo, id, accessToken.getTokenValue()).call()); | ||
} | ||
} | ||
} |
28 changes: 23 additions & 5 deletions
28
...nav/registre/testnorge/eregbatchstatusservice/consumer/command/GetBatchStatusCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
package no.nav.registre.testnorge.eregbatchstatusservice.consumer.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.registre.testnorge.eregbatchstatusservice.util.WebClientFilter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.retry.Retry; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.Callable; | ||
|
||
import static org.springframework.http.HttpHeaders.AUTHORIZATION; | ||
|
||
@RequiredArgsConstructor | ||
public class GetBatchStatusCommand implements Callable<Long> { | ||
@Slf4j | ||
public class GetBatchStatusCommand implements Callable<Mono<Long>> { | ||
private final WebClient webClient; | ||
private final String miljoe; | ||
private final Long id; | ||
private final String token; | ||
|
||
@Override | ||
public Long call() { | ||
public Mono<Long> call() { | ||
return webClient | ||
.get() | ||
.uri(builder -> builder.path("/ereg/internal/batch/poll/{id}").build(id)) | ||
.uri(builder -> builder.path("/{miljoe}/ereg/internal/batch/poll/{id}").build(miljoe, id)) | ||
.header(AUTHORIZATION, "Bearer " + token) | ||
.retrieve() | ||
.onStatus(HttpStatusCode::is4xxClientError, clientResponse -> { | ||
if (clientResponse.statusCode().equals(HttpStatus.UNAUTHORIZED)) { | ||
log.error("Unauthorized error occurred when calling modapp-ereg-proxy"); | ||
return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found")); | ||
} | ||
log.error("Client error occurred when calling modapp-ereg-proxy"); | ||
return Mono.error(new ResponseStatusException(clientResponse.statusCode(), "Client error occurred")); | ||
}) | ||
.bodyToMono(Long.class) | ||
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) | ||
.filter(WebClientFilter::is5xxException)) | ||
.block(); | ||
.filter(WebClientFilter::is5xxException)); | ||
} | ||
} |
Oops, something went wrong.