diff --git a/backend/app/plugins/mongodb.py b/backend/app/plugins/mongodb.py index cc85ea7..c4ebcf3 100644 --- a/backend/app/plugins/mongodb.py +++ b/backend/app/plugins/mongodb.py @@ -9,7 +9,12 @@ class MongoClientError(Exception): class MongoClient: def __init__(self): - self.client = pymongo.MongoClient(settings.MONGO_DB) + self.client = pymongo.MongoClient( + f'{settings.MONGO_HOST}:{settings.MONGO_PORT}', + username=settings.MONGO_USER, + password=settings.MONGO_PASSWORD, + authSource=settings.MONGO_DB, + ) self.db = self.client["orgbook-publisher"] def provision(self): diff --git a/backend/config.py b/backend/config.py index e88fcae..3177964 100644 --- a/backend/config.py +++ b/backend/config.py @@ -36,12 +36,10 @@ class Settings(BaseSettings): JWT_SECRET: str = TRACTION_API_KEY JWT_ALGORITHM: str = "HS256" - MONGO_HOST: str = os.getenv("MONGO_HOST") MONGO_PORT: str = os.getenv("MONGO_PORT") MONGO_USER: str = os.getenv("MONGO_USER") MONGO_PASSWORD: str = os.getenv("MONGO_PASSWORD") - MONGO_DB: str = f'mongodb://{MONGO_USER}:{MONGO_PASSWORD}@{MONGO_HOST}:{MONGO_PORT}/' - + MONGO_DB: str = os.getenv("MONGO_DB") settings = Settings() diff --git a/charts/orgbook-publisher/Chart.yaml b/charts/orgbook-publisher/Chart.yaml index c4ef1d3..c6165ce 100644 --- a/charts/orgbook-publisher/Chart.yaml +++ b/charts/orgbook-publisher/Chart.yaml @@ -3,7 +3,7 @@ name: orgbook-publisher description: An api server to register and manage credentials. type: application version: 0.0.2 -appVersion: "0.0.1" +appVersion: "0.0.2" dependencies: - name: mongodb diff --git a/charts/orgbook-publisher/templates/backend/deployment.yaml b/charts/orgbook-publisher/templates/backend/deployment.yaml index 9cc0a9d..de97fcb 100644 --- a/charts/orgbook-publisher/templates/backend/deployment.yaml +++ b/charts/orgbook-publisher/templates/backend/deployment.yaml @@ -31,40 +31,44 @@ spec: # PUBLISHER INFO - name: DOMAIN value: {{ .Values.backend.host }} + - name: ORGBOOK_URL + value: {{ .Values.backend.environment.ORGBOOK_URL }} - name: PUBLISHER_MULTIKEY - value: {{ .Values.backend.publisher_multikey }} + value: {{ .Values.backend.environment.PUBLISHER_MULTIKEY }} - name: ISSUER_REGISTRY_URL - value: {{ .Values.backend.issuer_registry_url }} + value: {{ .Values.backend.environment.ISSUER_REGISTRY_URL }} # TRACTION - name: TRACTION_API_URL - value: {{ .Values.backend.traction_api_url }} + value: {{ .Values.backend.environment.TRACTION_API_URL }} - name: TRACTION_API_KEY valueFrom: secretKeyRef: - name: {{ .Values.backend.fullname }} + name: {{ include "backend.fullname" . }} key: traction_api_key - name: TRACTION_TENANT_ID valueFrom: secretKeyRef: - name: {{ .Values.backend.fullname }} + name: {{ include "backend.fullname" . }} key: traction_tenant_id # DID WEB SERVER - name: DID_WEB_SERVER_URL - value: {{ .Values.backend.did_web_server_url }} + value: {{ .Values.backend.environment.DID_WEB_SERVER_URL }} # MONGODB - name: MONGO_HOST - value: "{{ .Release.Name }}-mongodb" + value: "{{ .Release.Name }}-mongodb-headless.{{ .Release.Namespace }}.svc.cluster.local" - name: MONGO_PORT value: {{ .Values.mongodb.service.ports.mongodb | quote }} - name: MONGO_USER - value: {{ .Values.mongodb.auth.username }} + value: {{ first .Values.mongodb.auth.usernames }} + - name: MONGO_DB + value: {{ first .Values.mongodb.auth.databases }} - name: MONGO_PASSWORD valueFrom: secretKeyRef: - name: {{ .Values.mongodb.nameOverride }} + name: {{ include "backend.databaseSecretName" . }} key: mongodb-passwords ports: - name: api diff --git a/charts/orgbook-publisher/values.yaml b/charts/orgbook-publisher/values.yaml index f1fc77d..fad95eb 100644 --- a/charts/orgbook-publisher/values.yaml +++ b/charts/orgbook-publisher/values.yaml @@ -19,7 +19,7 @@ networkPolicy: backend: image: repository: ghcr.io/bcgov/orgbook-publisher-service - tag: v0.0.1 + tag: v0.0.2 pullPolicy: IfNotPresent pullSecrets: [] @@ -56,14 +56,14 @@ mongodb: ## @param mongodb.auth.existingSecret Existing secret with MongoDB(®) credentials (keys: `mongodb-passwords`, `mongodb-root-password`, `mongodb-metrics-password`, `mongodb-replica-set-key`) ## NOTE: When it's set the previous parameters are ignored. ## - existingSecret: '{{ include "global.fullname" . }}' + existingSecret: 'include "backend.databaseSecretName" .' ## MongoDB(®) custom users and databases ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mongodb#creating-a-user-and-database-on-first-run ## @param mongodb.auth.usernames List of custom users to be created during the initialization ## @param mongodb.auth.databases List of custom databases to be created during the initialization ## - username: "orgbook-publisher" - database: "orgbook-publisher" + usernames: ["orgbook-publisher"] + databases: ["orgbook-publisher"] ## @param mongodb.commonLabels [array] Add labels to all the deployed resources (sub-charts are not considered). Evaluated as a template ## commonLabels: