From 40fbcfc4c8421a92c0b250033f3b110d64f219c1 Mon Sep 17 00:00:00 2001
From: Bastian <bastian.heppener@mgm-tp.com>
Date: Mon, 14 Apr 2025 11:36:09 +0200
Subject: [PATCH] ozg-8071 adjust zufi search url

---
 src/main/helm/templates/_helpers.tpl        | 22 +++++++++++-
 src/main/helm/templates/deployment.yaml     |  2 +-
 src/main/helm/values.yaml                   |  2 +-
 src/test/helm/deployment_zufi_test.yaml     | 38 +++++++++++++++------
 src/test/helm/keycloak_client_crd_test.yaml |  1 +
 5 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl
index 05eff90d..0ca938a6 100644
--- a/src/main/helm/templates/_helpers.tpl
+++ b/src/main/helm/templates/_helpers.tpl
@@ -24,7 +24,11 @@
 
 
 {{- define "app.baseDomain" -}}
-{{- printf "%s-%s.%s" (.Values.ozgcloud).bezeichner (.Values.ozgcloud).adminDomainSuffix .Values.baseUrl }}
+{{- printf "%s-%s.%s" (.Values.ozgcloud).bezeichner (.Values.ozgcloud).adminDomainSuffix  ( include "app.getBaseUrl" . ) }}
+{{- end -}}
+
+{{- define "app.getBaseUrl" -}}
+{{- required "baseUrl muss angegeben sein" .Values.baseUrl }}
 {{- end -}}
 
 {{/* Namespace */}}
@@ -101,3 +105,19 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }}
 {{- define "app.serviceAccountName" -}}
 {{ printf "%s" ( (.Values.serviceAccount).name | default "administration-service-account" ) }}
 {{- end -}}
+
+{{- define "app.getZufiSearchUri" -}}
+{{ if ((.Values.ozgcloud).organisationEinheit).zufiSearchUri }}
+{{- printf "%s" .Values.ozgcloud.organisationEinheit.zufiSearchUri }}
+{{- else -}}
+{{- printf "https://%s/api/organisationseinheits?searchBy={searchBy}" ( include "app.generateAlfaUrl" . ) }}
+{{- end -}}
+{{- end -}}
+
+{{- define "app.generateAlfaUrl" -}}
+{{ if (.Values.ozgcloud).alfaUrl }}
+{{- printf "%s" .Values.ozgcloud.alfaUrl }}
+{{- else -}}
+{{- printf "%s.%s" ( include "app.ozgcloudBezeichner" . ) ( include "app.getBaseUrl" . ) }}
+{{- end -}}
+{{- end -}}
\ No newline at end of file
diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml
index 7131cc9d..45406990 100644
--- a/src/main/helm/templates/deployment.yaml
+++ b/src/main/helm/templates/deployment.yaml
@@ -129,7 +129,7 @@ spec:
           {{- end }}
           {{- if eq ((.Values.ozgcloud).feature).organisationsEinheiten "true" }}
           - name: ozgcloud_organisationeinheit_zufisearchuri
-            value: {{ required "ozgcloud.organisationEinheit.zufiSearchUri must be set if feature organisationsEinheiten is activated" ((.Values.ozgcloud).organisationEinheit).zufiSearchUri}}
+            value: {{ include "app.getZufiSearchUri" . }}
           {{- end }}
         envFrom:
           {{- if (.Values.database).useExternal }}
diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml
index 4d2e4848..86aaec61 100644
--- a/src/main/helm/values.yaml
+++ b/src/main/helm/values.yaml
@@ -23,7 +23,7 @@
 #
 
 replicaCount: 1
-baseUrl: ozg-sh.de
+baseUrl:
 
 ozgcloud:
   bezeichner: helm
diff --git a/src/test/helm/deployment_zufi_test.yaml b/src/test/helm/deployment_zufi_test.yaml
index e342ff4b..b7a2350f 100644
--- a/src/test/helm/deployment_zufi_test.yaml
+++ b/src/test/helm/deployment_zufi_test.yaml
@@ -41,8 +41,6 @@ tests:
       ozgcloud:
         feature:
           organisationsEinheiten: "false"
-        organisationEinheit:
-          zufiSearchUri: alfa/zufi/search/endpoint?searchBy={searchBy}
     asserts:
       - notContains:
           path: spec.template.spec.containers[0].env
@@ -50,34 +48,54 @@ tests:
             name: ozgcloud_organisationeinheit_zufisearchuri
           any: true
   - it: should not contain zufi search uri if organisationseinheit feature toggle is disabled
-    set:
-      ozgcloud:
-        organisationEinheit:
-          zufiSearchUri: alfa/zufi/search/endpoint?searchBy={searchBy}
     asserts:
       - notContains:
           path: spec.template.spec.containers[0].env
           content:
             name: ozgcloud_organisationeinheit_zufisearchuri
           any: true
+  - it: should generate zufi search uri
+    set:
+      ozgcloud:
+        feature:
+          organisationsEinheiten: "true"
+      baseUrl: ozg-sh.de
+    asserts:
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: ozgcloud_organisationeinheit_zufisearchuri
+            value: https://helm.ozg-sh.de/api/organisationseinheits?searchBy={searchBy}
   - it: should set zufi search uri
     set:
       ozgcloud:
         feature:
           organisationsEinheiten: "true"
         organisationEinheit:
-          zufiSearchUri: alfa/zufi/search/endpoint?searchBy={searchBy}
+          zufiSearchUri: "https://company.local/api/organisationseinheits?searchBy={searchBy}"
+    asserts:
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: ozgcloud_organisationeinheit_zufisearchuri
+            value: "https://company.local/api/organisationseinheits?searchBy={searchBy}"
+  - it: should set alfa url
+    set:
+      ozgcloud:
+        feature:
+          organisationsEinheiten: "true"
+        alfaUrl: "alfa.local"
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
             name: ozgcloud_organisationeinheit_zufisearchuri
-            value: alfa/zufi/search/endpoint?searchBy={searchBy}
-  - it: should fail if zufi search uri is not set
+            value: "https://alfa.local/api/organisationseinheits?searchBy={searchBy}"
+  - it: should fail without baseUrl and alfaUrl and zufiSearchUrl
     set:
       ozgcloud:
         feature:
           organisationsEinheiten: "true"
     asserts:
       - failedTemplate:
-          errorMessage: "ozgcloud.organisationEinheit.zufiSearchUri must be set if feature organisationsEinheiten is activated"
+          errorMessage: "baseUrl muss angegeben sein"
\ No newline at end of file
diff --git a/src/test/helm/keycloak_client_crd_test.yaml b/src/test/helm/keycloak_client_crd_test.yaml
index 2ab407d1..eb5c6003 100644
--- a/src/test/helm/keycloak_client_crd_test.yaml
+++ b/src/test/helm/keycloak_client_crd_test.yaml
@@ -33,6 +33,7 @@ set:
     bundesland: by
     bezeichner: helm
     environment: test
+  baseUrl: ozg-sh.de
 tests:
   - it: should contain header data
     set:
-- 
GitLab