diff --git a/Jenkinsfile b/Jenkinsfile index 85957c49659b2e981c84bb034943420e89f5f068..4ab8e499fa2398ba259c2367e39440597822d448 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -157,8 +157,8 @@ pipeline { script { FAILED_STAGE=env.STAGE_NAME - namespace = createNamespaceName(env.STAGE_NAME) - createKEycloakUser(env.STAGE_NAME) + namespace = generateNamespaceName(env.STAGE_NAME) + createKeycloakUser(env.STAGE_NAME) container("k8s") { println(namespace) @@ -333,17 +333,51 @@ pipeline { // } } -String createNamespaceName(String stage) { +String generateNamespaceName(String stage) { branchName = env.BRANCH_NAME.replaceAll(/[^a-zA-Z0-9]+/, "").toLowerCase() stageName = stage.replaceAll(/[^a-zA-Z0-9]+/, "").toLowerCase() return "e2e-${branchName}${stageName}-dev" } -Void createKEycloakUser(String stage) { - namespace = createNamespaceName(stage) - dir('goofy-client/apps/goofy-e2e/deployment-values/goofy') { - userYaml = readYaml file: "user.yaml" - println(userYaml) +Void createKeycloakUser(String stage) { + namespace = generateNamespaceName(stage) + + e2eUserFiles = sh (script: 'ls goofy-client/apps/goofy-e2e/src/fixtures/user', returnStdout: true) + + baseUserYaml = readYaml file: "goofy-client/apps/goofy-e2e/deployment-values/goofy/user/user.yaml" + + e2eUserFiles.split("\\n").each { user -> + dir('goofy-client/apps/goofy-e2e/src/fixtures/user') { + userJson = readJSON file: user + + baseUserYaml.metadata.name = namespace + "-" + userJson.name + baseUserYaml.metadata.labels.realm = namespace + baseUserYaml.spec.realmSelector.matchLabels.realm = namespace + + baseUserYaml.spec.user.username = userJson.name + baseUserYaml.spec.user.credentials = [[type: 'password', value: userJson.password]] + + if(userJson.firstName) { + baseUserYaml.spec.user.firstName = userJson.firstName + } + + if(userJson.lastName) { + baseUserYaml.spec.user.lastName = userJson.lastName + } + + if(userJson.einheitlicherAnsprechpartner) { + baseUserYaml.spec.user.clientRoles = [namespace: ['EINHEITLICHER_ANSPRECHPARTNER']] + } + + if(userJson.verwaltungUser) { + baseUserYaml.spec.user.clientRoles = [namespace: ['VERWALTUNG_USER']] + } + } + + writeYaml file: "kc-user.yaml", data: baseUserYaml + + sh "kubectl apply -f kc-user.yaml" + sh "rm kc-user.yaml" } } \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/deployment-values/goofy/user/user.yaml b/goofy-client/apps/goofy-e2e/deployment-values/goofy/user/user.yaml index befa449a9736437643a3ce1c9baa2a42a22d8765..48734a2a6f33899f5e4c31354f0ef0cc1bd3d35d 100644 --- a/goofy-client/apps/goofy-e2e/deployment-values/goofy/user/user.yaml +++ b/goofy-client/apps/goofy-e2e/deployment-values/goofy/user/user.yaml @@ -1,26 +1,17 @@ apiVersion: keycloak.org/v1alpha1 kind: KeycloakUser metadata: - name: e2e-ozg1784e2eeakc-dev-emil + name: null namespace: keycloak labels: - realm: e2e-ozg1784e2eeakc-dev + realm: null spec: realmSelector: matchLabels: - realm: e2e-ozg1784e2eeakc-dev + realm: null user: - username: "emil" - firstName: "Emil" - lastName: "Ernst" enabled: True emailVerified: False - credentials: - - type: "password" - value: "Einfallsreich" realmRoles: - "offline_access" - "uma_authorization" - clientRoles: - e2e-ozg1784e2eeakc-dev: - - "VERWALTUNG_USER" diff --git a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_emil.json b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_emil.json index e2c1804a7d67970f57c5b150d41205d5f2230972..b5e05e2c6fb04d863475bc9bd81f9c3379484528 100644 --- a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_emil.json +++ b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_emil.json @@ -5,5 +5,6 @@ "lastName": "Ernst", "fullName": "Emil Ernst", "initials": "EE", - "dataTestId": "Emil_Ernst" + "dataTestId": "Emil_Ernst", + "einheitlicherAnsprechpartner": true } \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_sabine.json b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_sabine.json index 4bdb6c17638652b566d3e0bbe5c899a59c58045e..65897a1c189a162f6d6fbe45a171231f836ed892 100644 --- a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_sabine.json +++ b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_sabine.json @@ -6,5 +6,6 @@ "lastName": "Solala", "fullName": "Sabine Solala", "initials": "SS", - "dataTestId": "Sabine_Solala" + "dataTestId": "Sabine_Solala", + "verwaltungUser": true } \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_zonk.json b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_zonk.json index 3aa593b0cd51f5229b60f8695f343cbf4390e645..eab922b306de631007bd71bbf2615f2fa61ce6c0 100644 --- a/goofy-client/apps/goofy-e2e/src/fixtures/user/user_zonk.json +++ b/goofy-client/apps/goofy-e2e/src/fixtures/user/user_zonk.json @@ -1,4 +1,5 @@ { "name": "zonk", - "password": "Zonk4Nothing" + "password": "Zonk4Nothing", + "verwaltungUser": true } \ No newline at end of file