diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 3c96fe6..7910a1c 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -14,14 +14,19 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Limit branch name + id: branch + run: | + BRANCH_NAME=${GITHUB_REF#refs/heads/} + echo "shortname=$(echo "$BRANCH_NAME" | cut -c1-40)" >> $GITHUB_OUTPUT + - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} tags: | - type=ref,event=branch,suffix=-{{sha}} - type=ref,event=pr,suffix=-{{sha}} + type=raw,value=${{ steps.branch.outputs.shortname }}-{{sha}} type=sha,prefix={{date 'YYYY-MM-DD-'}},enable={{is_default_branch}} type=raw,value=latest,enable={{is_default_branch}} @@ -47,13 +52,8 @@ jobs: strategy: fail-fast: false matrix: - org: [ fintlabs-no, ofk-no, tromsfylke-no, bfk-no, afk-no, vlfk-no, rogfk-no, innlandetfylke-no, mrfylke-no ] + org: [ fintlabs-no, ofk-no, tromsfylke-no, bfk-no, afk-no, vlfk-no, rogfk-no, innlandetfylke-no, agderfk-no, mrfylke-no ] cluster: [ aks-beta-fint-2021-11-23, aks-api-fint-2022-02-08 ] - include: - - cluster: aks-beta-fint-2021-11-23 - org: bfk-no - deploy-every-branch: true - exclude: - cluster: aks-api-fint-2022-02-08 org: fintlabs-no diff --git a/bruno/environments/api: agderfk-no.bru b/bruno/environments/api: agderfk-no.bru new file mode 100644 index 0000000..5d7924b --- /dev/null +++ b/bruno/environments/api: agderfk-no.bru @@ -0,0 +1,7 @@ +vars { + org: agderfk-no + env: +} +vars:secret [ + user_session +] diff --git a/bruno/environments/beta: agderfk-no.bru b/bruno/environments/beta: agderfk-no.bru new file mode 100644 index 0000000..1ae0082 --- /dev/null +++ b/bruno/environments/beta: agderfk-no.bru @@ -0,0 +1,7 @@ +vars { + org: agderfk-no + env: beta/ +} +vars:secret [ + user_session +] diff --git a/build.gradle b/build.gradle index 527cc8a..4cfbac8 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ dependencies { implementation 'no.fintlabs:fint-kafka:4.0.1' implementation 'no.fintlabs:fint-flyt-kafka:3.1.1' - implementation 'no.fintlabs:fint-flyt-instance-gateway:5.0.5' - implementation 'no.fintlabs:fint-flyt-resource-server:2.1.0' + implementation 'no.fintlabs:fint-flyt-instance-gateway:6.0.0' + implementation 'no.fintlabs:fint-flyt-resource-server:5.0.0' runtimeOnly 'io.micrometer:micrometer-registry-prometheus' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' diff --git a/kustomize/overlays/agderfk-no/api/kustomization.yaml b/kustomize/overlays/agderfk-no/api/kustomization.yaml new file mode 100644 index 0000000..3cfbce9 --- /dev/null +++ b/kustomize/overlays/agderfk-no/api/kustomization.yaml @@ -0,0 +1,33 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: agderfk-no + +resources: + - ../../../base + +commonLabels: + app.kubernetes.io/instance: fint-flyt-vigo-gateway_agderfk_no + fintlabs.no/org-id: agderfk.no + +patches: + - patch: |- + - op: replace + path: "/spec/kafka/acls/0/topic" + value: "agderfk-no.flyt.*" + - op: replace + path: "/spec/orgId" + value: "agderfk.no" + - op: add + path: "/spec/url/basePath" + value: "/agderfk-no" + - op: replace + path: "/spec/ingress/basePath" + value: "/agderfk-no/api/vigo" + - op: add + path: "/spec/env/-" + value: + name: "logging.level.no.fintlabs.instance.gateway" + value: "INFO" + target: + kind: Application + name: fint-flyt-vigo-gateway diff --git a/kustomize/overlays/agderfk-no/beta/kustomization.yaml b/kustomize/overlays/agderfk-no/beta/kustomization.yaml new file mode 100644 index 0000000..2b42b27 --- /dev/null +++ b/kustomize/overlays/agderfk-no/beta/kustomization.yaml @@ -0,0 +1,33 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: agderfk-no + +resources: + - ../../../base + +commonLabels: + app.kubernetes.io/instance: fint-flyt-vigo-gateway_agderfk_no + fintlabs.no/org-id: agderfk.no + +patches: + - patch: |- + - op: replace + path: "/spec/kafka/acls/0/topic" + value: "agderfk-no.flyt.*" + - op: replace + path: "/spec/orgId" + value: "agderfk.no" + - op: add + path: "/spec/url/basePath" + value: "/beta/agderfk-no" + - op: replace + path: "/spec/ingress/basePath" + value: "/beta/agderfk-no/api/vigo" + - op: add + path: "/spec/env/-" + value: + name: "logging.level.no.fintlabs.instance.gateway" + value: "DEBUG" + target: + kind: Application + name: fint-flyt-vigo-gateway diff --git a/src/main/java/no/fintlabs/instance/gateway/IncomingInstanceMappingService.java b/src/main/java/no/fintlabs/instance/gateway/IncomingInstanceMappingService.java index cb8601f..be6c372 100644 --- a/src/main/java/no/fintlabs/instance/gateway/IncomingInstanceMappingService.java +++ b/src/main/java/no/fintlabs/instance/gateway/IncomingInstanceMappingService.java @@ -4,7 +4,6 @@ import no.fintlabs.gateway.instance.InstanceMapper; import no.fintlabs.gateway.instance.model.File; import no.fintlabs.gateway.instance.model.instance.InstanceObject; -import no.fintlabs.gateway.instance.web.FileClient; import no.fintlabs.instance.gateway.model.vigo.IncomingInstance; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -15,6 +14,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -22,22 +22,18 @@ @Slf4j public class IncomingInstanceMappingService implements InstanceMapper { - private final FileClient fileClient; - - public IncomingInstanceMappingService( - FileClient fileClient - ) { - this.fileClient = fileClient; - } - @Override - public Mono map(Long sourceApplicationId, IncomingInstance incomingInstance) { + public Mono map( + Long sourceApplicationId, + IncomingInstance incomingInstance, + Function> persistFile + ) { if (incomingInstance.getDokument() == null) { return Mono.just(InstanceObject.builder() .valuePerKey(toValuePerKey(incomingInstance, null)) .build()); } else { - return postFile(sourceApplicationId, incomingInstance) + return postFile(sourceApplicationId, incomingInstance, persistFile) .map(uuid -> InstanceObject.builder() .valuePerKey(toValuePerKey(incomingInstance, uuid)) .build()); @@ -57,22 +53,22 @@ private static Map toValuePerKey(IncomingInstance incomingInstan entries.add(Map.entry("tilpassetNavn1", Stream.of(incomingInstance.getPersonalia().getFornavn(), - incomingInstance.getPersonalia().getMellomnavn(), - incomingInstance.getPersonalia().getEtternavn()) - .filter(s -> StringUtils.hasLength(s)) - .collect(Collectors.joining(" ")) + incomingInstance.getPersonalia().getMellomnavn(), + incomingInstance.getPersonalia().getEtternavn()) + .filter(s -> StringUtils.hasLength(s)) + .collect(Collectors.joining(" ")) )); entries.add(Map.entry("tilpassetNavn2", Stream.of(incomingInstance.getPersonalia().getEtternavn(), - incomingInstance.getPersonalia().getFornavn(), - incomingInstance.getPersonalia().getMellomnavn()) - .filter(s -> StringUtils.hasLength(s)) - .collect(Collectors.joining(" ")) + incomingInstance.getPersonalia().getFornavn(), + incomingInstance.getPersonalia().getMellomnavn()) + .filter(s -> StringUtils.hasLength(s)) + .collect(Collectors.joining(" ")) )); entries.add(Map.entry("tilpassetNavn3", - Stream.of(incomingInstance.getPersonalia().getEtternavn() +",", + Stream.of(incomingInstance.getPersonalia().getEtternavn() + ",", incomingInstance.getPersonalia().getFornavn(), incomingInstance.getPersonalia().getMellomnavn()) .filter(s -> StringUtils.hasLength(s)) @@ -88,7 +84,7 @@ private static Map toValuePerKey(IncomingInstance incomingInstan Optional.ofNullable(formatedDate(fodselsdato, "dd.MM.yyyy")).ifPresent(formatedFodselsdato -> entries.add(Map.entry("tilpassetFodselsdato2", formatedFodselsdato))); - + }); entries.add(Map.entry("kontaktinformasjonTelefonnummer", incomingInstance.getKontaktinformasjon().getTelefonnummer())); @@ -142,15 +138,19 @@ private static String formatedDate(String fodselsdato, String format) { } - private Mono postFile(Long sourceApplicationId, IncomingInstance incomingInstance) { - return fileClient.postFile( + private Mono postFile( + Long sourceApplicationId, + IncomingInstance incomingInstance, + Function> persistFile + ) { + return persistFile.apply( File.builder() - .name(incomingInstance.getDokument().getFilnavn()) - .type(MediaType.parseMediaType(incomingInstance.getDokument().getFormat())) - .sourceApplicationId(sourceApplicationId) - .sourceApplicationInstanceId(incomingInstance.getInstansId()) - .encoding("UTF-8") - .base64Contents(incomingInstance.getDokument().getFil()) - .build()); + .name(incomingInstance.getDokument().getFilnavn()) + .type(MediaType.parseMediaType(incomingInstance.getDokument().getFormat())) + .sourceApplicationId(sourceApplicationId) + .sourceApplicationInstanceId(incomingInstance.getInstansId()) + .encoding("UTF-8") + .base64Contents(incomingInstance.getDokument().getFil()) + .build()); } } diff --git a/src/main/java/no/fintlabs/instance/gateway/InstanceController.java b/src/main/java/no/fintlabs/instance/gateway/InstanceController.java index b5b0039..95bb56f 100644 --- a/src/main/java/no/fintlabs/instance/gateway/InstanceController.java +++ b/src/main/java/no/fintlabs/instance/gateway/InstanceController.java @@ -5,7 +5,7 @@ import no.fintlabs.gateway.instance.kafka.ArchiveCaseIdRequestService; import no.fintlabs.instance.gateway.model.Status; import no.fintlabs.instance.gateway.model.vigo.IncomingInstance; -import no.fintlabs.resourceserver.security.client.sourceapplication.SourceApplicationAuthorizationUtil; +import no.fintlabs.resourceserver.security.client.sourceapplication.SourceApplicationAuthorizationService; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -23,10 +23,16 @@ public class InstanceController { private final ArchiveCaseIdRequestService archiveCaseIdRequestService; - public InstanceController(InstanceProcessor instanceProcessor, - ArchiveCaseIdRequestService archiveCaseIdRequestService) { + private final SourceApplicationAuthorizationService sourceApplicationAuthorizationService; + + public InstanceController( + InstanceProcessor instanceProcessor, + ArchiveCaseIdRequestService archiveCaseIdRequestService, + SourceApplicationAuthorizationService sourceApplicationAuthorizationService + ) { this.instanceProcessor = instanceProcessor; this.archiveCaseIdRequestService = archiveCaseIdRequestService; + this.sourceApplicationAuthorizationService = sourceApplicationAuthorizationService; } @PostMapping("instance") @@ -51,22 +57,22 @@ public Mono> getInstanceStatus( ) { return authenticationMono.map(authentication -> { - Long applicationId = SourceApplicationAuthorizationUtil.getSourceApplicationId(authentication); + Long applicationId = sourceApplicationAuthorizationService.getSourceApplicationId(authentication); log.debug("Get status for instance: {} in sourceApplication: {}", instanceId, applicationId); return archiveCaseIdRequestService.getArchiveCaseId(applicationId, instanceId) .map(caseId -> ResponseEntity.ok(Status.builder() - .instansId(instanceId) - .destinasjonsId(caseId) - .status("Instans godtatt av destinasjon").build() + .instansId(instanceId) + .destinasjonsId(caseId) + .status("Instans godtatt av destinasjon").build() ) ) .orElse(ResponseEntity .badRequest() .body(Status.builder() - .instansId(instanceId) - .status("Ukjent status").build() + .instansId(instanceId) + .status("Ukjent status").build() ) ); } diff --git a/src/test/java/no/fintlabs/instance/gateway/IncomingInstanceMappingServiceTest.java b/src/test/java/no/fintlabs/instance/gateway/IncomingInstanceMappingServiceTest.java index 7a0d261..4e25fad 100644 --- a/src/test/java/no/fintlabs/instance/gateway/IncomingInstanceMappingServiceTest.java +++ b/src/test/java/no/fintlabs/instance/gateway/IncomingInstanceMappingServiceTest.java @@ -2,7 +2,6 @@ import no.fintlabs.gateway.instance.model.File; import no.fintlabs.gateway.instance.model.instance.InstanceObject; -import no.fintlabs.gateway.instance.web.FileClient; import no.fintlabs.instance.gateway.model.vigo.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,33 +12,37 @@ import java.util.Map; import java.util.UUID; +import java.util.function.Function; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; class IncomingInstanceMappingServiceTest { - @Mock - private FileClient fileClient; + Function> persistFile; @InjectMocks private IncomingInstanceMappingService incomingInstanceMappingService; + @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); - when(fileClient.postFile(any(File.class))).thenReturn(Mono.just(UUID.randomUUID())); + when(persistFile.apply(any(File.class))).thenReturn(Mono.just(UUID.randomUUID())); } @Test void shouldReturnInstanceObjectWhenIncomingInstanceIsValid() { UUID uuid = UUID.randomUUID(); - when(fileClient.postFile(any(File.class))).thenReturn(Mono.just(uuid)); + when(persistFile.apply(any(File.class))).thenReturn(Mono.just(uuid)); InstanceObject result = incomingInstanceMappingService - .map(4L, createValidIncomingInstanceWithTilleggsinformasjon().build()).block(); + .map( + 4L, + createValidIncomingInstanceWithTilleggsinformasjon().build(), + persistFile + ).block(); Map valuePerKey = result.getValuePerKey(); assertEquals("Ola", valuePerKey.get("personaliaFornavn")); @@ -72,10 +75,14 @@ void shouldReturnInstanceObjectWhenIncomingInstanceIsValid() { @Test void shouldReturnInstanceObjectWhenIncomingInstanceDoesNotHaveTilleggsinformasjon() { UUID uuid = UUID.randomUUID(); - when(fileClient.postFile(any(File.class))).thenReturn(Mono.just(uuid)); + when(persistFile.apply(any(File.class))).thenReturn(Mono.just(uuid)); InstanceObject result = incomingInstanceMappingService - .map(4L, createIncomingInstance().build()).block(); + .map( + 4L, + createIncomingInstance().build(), + persistFile + ).block(); Map valuePerKey = result.getValuePerKey(); assertEquals("Ola", valuePerKey.get("personaliaFornavn")); @@ -100,9 +107,13 @@ void shouldReturnInstanceObjectWhenIncomingInstanceDoesNotHaveTilleggsinformasjo @Test void shouldReturnInstanceObjectWhenIncomingInstanceDoesHaveSomeTilleggsinformasjon() { UUID uuid = UUID.randomUUID(); - when(fileClient.postFile(any(File.class))).thenReturn(Mono.just(uuid)); + when(persistFile.apply(any(File.class))).thenReturn(Mono.just(uuid)); - InstanceObject result = incomingInstanceMappingService.map(4L, createValidIncomingInstanceWithSomeTilleggsinformasjon()).block(); + InstanceObject result = incomingInstanceMappingService.map( + 4L, + createValidIncomingInstanceWithSomeTilleggsinformasjon(), + persistFile + ).block(); Map valuePerKey = result.getValuePerKey(); assertEquals("Ola", valuePerKey.get("personaliaFornavn")); @@ -125,10 +136,14 @@ void shouldReturnInstanceObjectWhenIncomingInstanceDoesHaveSomeTilleggsinformasj @Test void shouldReturnInstanceObjectWhenIncomingInstanceDoesNotHaveDocument() { UUID uuid = UUID.randomUUID(); - when(fileClient.postFile(any(File.class))).thenReturn(Mono.just(uuid)); + when(persistFile.apply(any(File.class))).thenReturn(Mono.just(uuid)); InstanceObject result = incomingInstanceMappingService - .map(4L, createIncomingInstanceWithoutDocument().build()).block(); + .map( + 4L, + createIncomingInstanceWithoutDocument().build(), + persistFile + ).block(); Map valuePerKey = result.getValuePerKey(); assertEquals("Ola", valuePerKey.get("personaliaFornavn")); @@ -153,7 +168,11 @@ void shouldReturnInstanceObjectWhenIncomingInstanceDoesNotHaveDocument() { @Test void shouldAcceptFodselsdatoAsNull() { InstanceObject result = incomingInstanceMappingService - .map(4L, createValidIncomingInstanceWithFodselsdatoAsNull().build()).block(); + .map( + 4L, + createValidIncomingInstanceWithFodselsdatoAsNull().build(), + persistFile + ).block(); assertFalse(result.getValuePerKey().containsKey("personaliaFodselsdato")); } @@ -161,7 +180,11 @@ void shouldAcceptFodselsdatoAsNull() { @Test void shouldCreateCustomizedFodselsdato() { InstanceObject result = incomingInstanceMappingService - .map(4L, createIncomingInstance().build()).block(); + .map( + 4L, + createIncomingInstance().build(), + persistFile + ).block(); assertEquals("311280", result.getValuePerKey().get("tilpassetFodselsdato1")); assertEquals("31.12.1980", result.getValuePerKey().get("tilpassetFodselsdato2")); @@ -171,7 +194,11 @@ void shouldCreateCustomizedFodselsdato() { @Test void shouldCreateCustomizedFullName() { InstanceObject result = incomingInstanceMappingService - .map(4L, createIncomingInstance().build()).block(); + .map( + 4L, + createIncomingInstance().build(), + persistFile + ).block(); assertEquals("Ola Nordmann Nordmannsen", result.getValuePerKey().get("tilpassetNavn1")); assertEquals("Nordmannsen Ola Nordmann", result.getValuePerKey().get("tilpassetNavn2")); @@ -182,12 +209,14 @@ void shouldCreateCustomizedFullName() { void shouldCreateCustomizedFullNameWitoutMiddleName() { InstanceObject result = incomingInstanceMappingService .map(4L, createIncomingInstance() - .personalia(Personalia.builder() - .fodselsnummer("12345678901") - .fornavn("Ola") - .etternavn("Nordmannsen") - .fodselsdato("19-12-3100") - .build()).build()).block(); + .personalia(Personalia.builder() + .fodselsnummer("12345678901") + .fornavn("Ola") + .etternavn("Nordmannsen") + .fodselsdato("19-12-3100") + .build()).build(), + persistFile + ).block(); assertEquals("Ola Nordmannsen", result.getValuePerKey().get("tilpassetNavn1")); assertEquals("Nordmannsen Ola", result.getValuePerKey().get("tilpassetNavn2")); @@ -204,7 +233,8 @@ void shouldCreateCustomizedFullNameWithEmptyMiddleName() { .mellomnavn("") .etternavn("Nordmannsen") .fodselsdato("19-12-3100") - .build()).build() + .build()).build(), + persistFile ).block(); assertEquals("Ola Nordmannsen", result.getValuePerKey().get("tilpassetNavn1")); @@ -222,7 +252,8 @@ void shouldCreateCustomizedFullNameWithNullMiddleName() { .mellomnavn(null) .etternavn("Nordmannsen") .fodselsdato("19-12-3100") - .build()).build() + .build()).build(), + persistFile ).block(); assertEquals("Ola Nordmannsen", result.getValuePerKey().get("tilpassetNavn1")); @@ -234,23 +265,29 @@ void shouldCreateCustomizedFullNameWithNullMiddleName() { void shouldNotAcceptInvalidFodselsdato() { InstanceObject result = incomingInstanceMappingService .map(4L, createIncomingInstance() - .personalia(Personalia.builder() - .fodselsnummer("12345678901") - .fornavn("Ola") - .mellomnavn("Nordmann") - .etternavn("Nordmannsen") - .fodselsdato("19-12-3100") - .build()) - .build()).block(); + .personalia(Personalia.builder() + .fodselsnummer("12345678901") + .fornavn("Ola") + .mellomnavn("Nordmann") + .etternavn("Nordmannsen") + .fodselsdato("19-12-3100") + .build()) + .build(), + persistFile + ).block(); assertFalse(result.getValuePerKey().containsKey("tilpassetFodselsdato1")); assertFalse(result.getValuePerKey().containsKey("tilpassetFodselsdato2")); } @Test - void shouldNotReturnInstansId(){ + void shouldNotReturnInstansId() { InstanceObject result = incomingInstanceMappingService - .map(4L, createValidIncomingInstanceWithTilleggsinformasjon().build()).block(); + .map( + 4L, + createValidIncomingInstanceWithTilleggsinformasjon().build(), + persistFile + ).block(); assertFalse(result.getValuePerKey().containsKey("instansId")); }