From 0954e9b6c2cb614f3490dddae56aa187f93d63c5 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 22 Oct 2024 07:32:37 +0200 Subject: [PATCH] feat(seeding): adjust config for seeding data * make authority and credential authorities for operator overwriteable * add configuration to add own config maps for seeding Refs: #77 --- .../configmap-seeding-initialdata.yaml | 83 +++++++++++++++++++ .../templates/job-registry-migrations.yaml | 38 ++++++++- charts/ssi-asr/values.yaml | 17 +++- environments/helm-values/values-int.yaml | 2 + environments/helm-values/values-stable.yaml | 2 + .../Data/{ => overwrite}/authorities.json | 0 .../credential_authorities.json | 0 .../Data/{ => overwrite}/credentials.json | 10 +-- ...iAuthoritySchemaRegistry.Migrations.csproj | 3 + .../appsettings.json | 3 +- 10 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 charts/ssi-asr/templates/configmap-seeding-initialdata.yaml rename src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/{ => overwrite}/authorities.json (100%) rename src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/{ => overwrite}/credential_authorities.json (100%) rename src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/{ => overwrite}/credentials.json (100%) diff --git a/charts/ssi-asr/templates/configmap-seeding-initialdata.yaml b/charts/ssi-asr/templates/configmap-seeding-initialdata.yaml new file mode 100644 index 0000000..ff40a30 --- /dev/null +++ b/charts/ssi-asr/templates/configmap-seeding-initialdata.yaml @@ -0,0 +1,83 @@ +{{- /* +* Copyright (c) 2024 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License, Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0. +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations +* under the License. +* +* SPDX-License-Identifier: Apache-2.0 +*/}} + +{{- if .Values.migrations.seeding.useInitial -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-initial-data + namespace: {{ .Release.Namespace }} +data: + authorities.json: |- + [ + { + "bpn": "{{ .Values.operator.bpn }}" + }, + { + "bpn": "BPNL00000003CRHL" + } + ] + credentials.json: |- + [ + { + "id": "255e01fc-65f6-43cd-8dfa-95e95fa95f60", + "type_id": 1, + "name": "BusinessPartnerCredential" + }, + { + "id": "255e01fc-65f6-43cd-8dfa-95e95fa95f61", + "type_id": 2, + "name": "MembershipCredential" + }, + { + "id": "10df6ecd-faa3-45ed-8da5-96261f6542dd", + "type_id": 3, + "name": "DataExchangeGovernanceCredential" + }, + { + "id": "255e01fc-65f6-43cd-8dfa-95e95fa95f6b", + "type_id": 4, + "name": "DismantlerCredential" + } + ] + credential_authorities.json: |- + [ + { + "credential_id": "255e01fc-65f6-43cd-8dfa-95e95fa95f60", + "bpn": "{{ .Values.operator.bpn }}" + }, + { + "credential_id": "255e01fc-65f6-43cd-8dfa-95e95fa95f61", + "bpn": "{{ .Values.operator.bpn }}" + }, + { + "credential_id": "255e01fc-65f6-43cd-8dfa-95e95fa95f6b", + "bpn": "{{ .Values.operator.bpn }}" + }, + { + "credential_id": "255e01fc-65f6-43cd-8dfa-95e95fa95f6b", + "bpn": "BPNL00000003CRHL" + }, + { + "credential_id": "10df6ecd-faa3-45ed-8da5-96261f6542dd", + "bpn": "{{ .Values.operator.bpn }}" + } + ] + +{{- end }} diff --git a/charts/ssi-asr/templates/job-registry-migrations.yaml b/charts/ssi-asr/templates/job-registry-migrations.yaml index dc16a50..1b55adb 100644 --- a/charts/ssi-asr/templates/job-registry-migrations.yaml +++ b/charts/ssi-asr/templates/job-registry-migrations.yaml @@ -67,10 +67,16 @@ spec: - name: "CONNECTIONSTRINGS__REGISTRYDB" value: "Server={{ .Values.externalDatabase.host }};Database={{ .Values.externalDatabase.database }};Port={{ .Values.externalDatabase.port }};User Id={{ .Values.externalDatabase.username }};Password=$(REGISTRY_PASSWORD);Ssl Mode={{ .Values.dbConnection.sslMode }};" {{- end }} - - name: "SEEDING__TESTDATAENVIRONMENTS__0" - value: "{{ .Values.migrations.seeding.testDataEnvironments }}" - name: "SEEDING__DATAPATHS__0" - value: "{{ .Values.migrations.seeding.testDataPaths }}" + value: "Seeder/Data/" + - name: "SEEDING__DATAPATHS__1" + value: "Seeder/Data/overwrite" + {{- if and (.Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap) (.Values.migrations.seeding.seedTestData.useOwnConfigMap.filename) }} + - name: "SEEDING__DATAPATHS__2" + value: "Seeder/Data/import/custom-test-data" + - name: "SEEDING__TESTDATAENVIRONMENTS__2" + value: "{{ .Values.migrations.seeding.seedTestData.useOwnConfigMap.filename }}" + {{- end }} - name: "SERILOG__MINIMUMLEVEL__Default" value: "{{ .Values.migrations.logging.default }}" ports: @@ -79,3 +85,29 @@ spec: protocol: TCP resources: {{- toYaml .Values.migrations.resources | nindent 10 }} + {{- if or (.Values.migrations.seeding.useInitial) (and (.Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap) (.Values.migrations.seeding.seedTestData.useOwnConfigMap.filename)) }} + volumeMounts: + {{- if (.Values.migrations.seeding.useInitial) }} + - name: data-initial + mountPath: /migrations/Seeder/Data/overwrite + {{- end }} + {{- if and (.Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap) (.Values.migrations.seeding.seedTestData.useOwnConfigMap.filename) }} + - name: test-data-custom + mountPath: /migrations/Seeder/Data/import/custom-test-data + {{- end }} + {{- end }} + {{- if or (.Values.migrations.seeding.useInitial) (and (.Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap) (.Values.migrations.seeding.seedTestData.useOwnConfigMap.filename)) }} + volumes: + {{- if (.Values.migrations.seeding.useInitial) }} + - name: data-initial + configMap: + name: {{ .Release.Name }}-initial-data + optional: true + {{- end }} + {{- if and (.Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap) (.Values.migrations.seeding.seedTestData.useOwnConfigMap.filename) }} + - name: test-data-custom + configMap: + name: "{{ .Values.migrations.seeding.seedTestData.useOwnConfigMap.configMap }}" + optional: true + {{- end }} + {{- end }} diff --git a/charts/ssi-asr/values.yaml b/charts/ssi-asr/values.yaml index 4074e4d..5027592 100644 --- a/charts/ssi-asr/values.yaml +++ b/charts/ssi-asr/values.yaml @@ -17,6 +17,11 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### +# -- Set information related to the operator company +operator: + # -- The bpn of the operator + bpn: "empty" + service: image: name: "docker.io/tractusx/ssi-authority-schema-registry-service" @@ -62,8 +67,16 @@ migrations: cpu: 75m memory: 200M seeding: - testDataEnvironments: "" - testDataPaths: "Seeder/Data" + # -- Enables dynamic seeding of information related to the operator company: operator.bpn; + # If set to `true` the data configured in the config map 'configmap-seeding-initialdata.yaml' will be taken to insert the initial data; + useInitial: true + # -- Option to seed test data provided in a configMap + seedTestData: + useOwnConfigMap: + # -- ConfigMap containing json files for the tables to seed, e.g. credentials.test.json, authorities.test.json, etc. + configMap: "" + # -- Filename identifying the test data files e.g. for credentials.test.json the value would be "test" + filename: "" logging: default: "Information" diff --git a/environments/helm-values/values-int.yaml b/environments/helm-values/values-int.yaml index 82321f6..e6e706c 100644 --- a/environments/helm-values/values-int.yaml +++ b/environments/helm-values/values-int.yaml @@ -16,6 +16,8 @@ # # SPDX-License-Identifier: Apache-2.0 ############################################################### +operator: + bpn: "BPNL00000003CRHK" ingress: enabled: true diff --git a/environments/helm-values/values-stable.yaml b/environments/helm-values/values-stable.yaml index 9c9a6a7..d8ee11c 100644 --- a/environments/helm-values/values-stable.yaml +++ b/environments/helm-values/values-stable.yaml @@ -16,6 +16,8 @@ # # SPDX-License-Identifier: Apache-2.0 ############################################################### +operator: + bpn: "BPNL00000003CRHK" ingress: enabled: true diff --git a/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/authorities.json b/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/authorities.json similarity index 100% rename from src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/authorities.json rename to src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/authorities.json diff --git a/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/credential_authorities.json b/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/credential_authorities.json similarity index 100% rename from src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/credential_authorities.json rename to src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/credential_authorities.json diff --git a/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/credentials.json b/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/credentials.json similarity index 100% rename from src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/credentials.json rename to src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/credentials.json index 02baff7..3a0475e 100644 --- a/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/credentials.json +++ b/src/database/SsiAuthoritySchemaRegistry.Migrations/Seeder/Data/overwrite/credentials.json @@ -9,14 +9,14 @@ "type_id": 2, "name": "MembershipCredential" }, - { - "id": "255e01fc-65f6-43cd-8dfa-95e95fa95f6b", - "type_id": 4, - "name": "DismantlerCredential" - }, { "id": "10df6ecd-faa3-45ed-8da5-96261f6542dd", "type_id": 3, "name": "DataExchangeGovernanceCredential" + }, + { + "id": "255e01fc-65f6-43cd-8dfa-95e95fa95f6b", + "type_id": 4, + "name": "DismantlerCredential" } ] \ No newline at end of file diff --git a/src/database/SsiAuthoritySchemaRegistry.Migrations/SsiAuthoritySchemaRegistry.Migrations.csproj b/src/database/SsiAuthoritySchemaRegistry.Migrations/SsiAuthoritySchemaRegistry.Migrations.csproj index 05b1984..311edac 100644 --- a/src/database/SsiAuthoritySchemaRegistry.Migrations/SsiAuthoritySchemaRegistry.Migrations.csproj +++ b/src/database/SsiAuthoritySchemaRegistry.Migrations/SsiAuthoritySchemaRegistry.Migrations.csproj @@ -65,6 +65,9 @@ + + + diff --git a/src/database/SsiAuthoritySchemaRegistry.Migrations/appsettings.json b/src/database/SsiAuthoritySchemaRegistry.Migrations/appsettings.json index d664c39..9598782 100644 --- a/src/database/SsiAuthoritySchemaRegistry.Migrations/appsettings.json +++ b/src/database/SsiAuthoritySchemaRegistry.Migrations/appsettings.json @@ -29,7 +29,8 @@ }, "Seeding": { "DataPaths": [ - "Seeder/Data" + "Seeder/Data", + "Seeder/Data/overwrite" ], "TestDataEnvironments": [] }