apiVersion: v1
kind: ConfigMap
metadata:
  name: wallet-config
data:
  _features.conf: |
    enabledFeatures = [
    ]
  db.conf: |
    dataSource {
        jdbcUrl = "jdbc:sqlite:/waltid-wallet-api/data/data.db"
        driverClassName = "org.sqlite.JDBC"
        username = ""
        password = ""
        transactionIsolation = "TRANSACTION_SERIALIZABLE"
        maximumPoolSize = 5
        autoCommit = false
        dataSource {
            journalMode = "WAL"
            fullColumnNames = false
        }
    }
    recreateDatabaseOnStart = false
  web.conf: |
    webHost = "0.0.0.0"
    webPort = 4545
  oidc.conf: |
    publicBaseUrl = "https://wallet-dev.demo.walt.id"
    providerName = keycloak
    oidcRealm = "https://keycloak.walt-test.cloud/realms/waltid-keycloak-ktor"
    oidcJwks = "${oidcRealm}/protocol/openid-connect/certs"
    authorizeUrl = "${oidcRealm}/protocol/openid-connect/auth"
    accessTokenUrl = "${oidcRealm}/protocol/openid-connect/token"
    logoutUrl = "${oidcRealm}/protocol/openid-connect/logout"
    clientId = "wallet_backend_prod"
    clientSecret = "__DEFAULT_KEYCLOAK_CLIENT_SECRET__"
    keycloakUserApi = "https://keycloak.walt-test.cloud/admin/realms/waltid-keycloak-ktor/users"
    jwksCache = {
        cacheSize = 10
        cacheExpirationHours = 24
        rateLimit: {
            bucketSize: 10
            refillRateMinutes: 1
        }
    }
  registration-defaults.conf: |
    defaultKeyConfig: {
      keyType: secp256r1
    }
    defaultIssuerConfig: {
      did = "did:web:walt.id",
      description = "walt.id issuer portal",
      uiEndpoint = "https://portal.demo.walt.id/credentials?ids=",
      configurationEndpoint = "https://issuer.demo.walt.id/.well-known/openid-credential-issuer",
      authorized = false,
    }
#  rejectionreason.conf: |
#    reasons = [
#        "Unknown sender",
#        "Not relevant to me",
#        "Unsure about accuracy",
#        "Need more details",
#    ]
#  logins.conf: |
#    enabledLoginMethods: [
#        "email",
#        "web3",
#        "oidc",
#        "passkeys"
#    ]
#  oci.conf: |
#    vaultId = "ocid1.vault.oc1.eu-frankfurt-1.entcvrlraabc4.abtheljrpyimqvzheblr6ce4bqt2snnz36i4etlgtg32n4du5dbrnpgagf6q"
#    compartmentId = "ocid1.compartment.oc1..aaaaaaaawirugoz35riiybcxsvf7bmelqsxo3sajaav5w3i2vqowcwqrllxa"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wallet-data-volume-claim
spec:
  storageClassName: azure-managed-standardssd-retain
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: wallet-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wallet-api
  template:
    metadata:
      labels:
        app: wallet-api
      annotations:
        deployment/id: "_DEFAULT_DEPLOYMENT_"
    spec:
      initContainers:
        - name: init-myservice
          image: busybox
          command: [ 'sh', '-c', 'chmod 777 /waltid-wallet-api/data/' ]
          volumeMounts:
            - mountPath: "/waltid-wallet-api/data/"
              name: wallet-data
      containers:
        - name: wallet-api
          image: waltid/wallet-api:__DEFAULT_IMAGE_TAG__
          volumeMounts:
            - name: wallet-config
              mountPath: /waltid-wallet-api/config/db.conf
              readOnly: true
              subPath: db.conf
            - name: wallet-config
              mountPath: /waltid-wallet-api/config/web.conf
              readOnly: true
              subPath: web.conf
            - name: wallet-config
              mountPath: /waltid-wallet-api/config/oidc.conf
              readOnly: true
              subPath: oidc.conf
            - name: wallet-config
              mountPath: /waltid-wallet-api/config/registration-defaults.conf
              readOnly: true
              subPath: registration-defaults.conf
            - name: wallet-auth-secret
              mountPath: /waltid-wallet-api/config/auth.conf
              readOnly: true
              subPath: auth.conf
            - mountPath: "/waltid-wallet-api/data/"
              name: wallet-data
          ports:
            - containerPort: 4545
              name: http-api
      volumes:
        - name: wallet-config
          configMap:
            name: wallet-config
        - name: wallet-auth-secret
          secret:
            secretName: wallet-auth-secret
        - name: wallet-data
          persistentVolumeClaim:
            claimName: wallet-data-volume-claim
---
kind: Service
apiVersion: v1
metadata:
  name: wallet-api
spec:
  ports:
    - name: http
      port: 80
      targetPort: http-api
      protocol: TCP
  selector:
    app: wallet-api
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: waltid-dev-wallet
spec:
  replicas: 1
  selector:
    matchLabels:
      app: waltid-dev-wallet
  template:
    metadata:
      labels:
        app: waltid-dev-wallet
      annotations:
        deployment/id: "_DEFAULT_DEPLOYMENT_"
    spec:
      containers:
        - name: waltid-dev-wallet
          image: waltid/waltid-dev-wallet:__DEFAULT_IMAGE_TAG__
          env:
            - name: NUXT_PUBLIC_ISSUER_CALLBACK_URL
              value: "https://wallet-dev.demo.walt.id"
            - name: NUXT_PUBLIC_DEMO_WALLET_URL
              value: "https://wallet.demo.walt.id"
          ports:
            - containerPort: 7104
              name: http-api
---
kind: Service
apiVersion: v1
metadata:
  name: waltid-dev-wallet
spec:
  ports:
    - name: http
      port: 80
      targetPort: http-api
      protocol: TCP
  selector:
    app: waltid-dev-wallet
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: waltid-demo-wallet
spec:
  replicas: 1
  selector:
    matchLabels:
      app: waltid-demo-wallet
  template:
    metadata:
      labels:
        app: waltid-demo-wallet
      annotations:
        deployment/id: "_DEFAULT_DEPLOYMENT_"
    spec:
      containers:
        - name: waltid-demo-wallet
          image: waltid/waltid-demo-wallet:__DEFAULT_IMAGE_TAG__
          env:
            - name: NUXT_PUBLIC_ISSUER_CALLBACK_URL
              value: "https://wallet.demo.walt.id"
            - name: NUXT_PUBLIC_DEV_WALLET_URL
              value: "https://wallet-dev.demo.walt.id"
            - name: NUXT_PUBLIC_CREDENTIALS_REPOSITORY_URL
              value: "https://credentials.walt.id"
          ports:
            - containerPort: 7101
              name: http-api
---
kind: Service
apiVersion: v1
metadata:
  name: waltid-demo-wallet
spec:
  ports:
    - name: http
      port: 80
      targetPort: http-api
      protocol: TCP
  selector:
    app: waltid-demo-wallet
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wallet-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
    - hosts:
        - wallet-dev.demo.walt.id
      secretName: wallet-dev-tls-secret
    - hosts:
        - wallet.demo.walt.id
      secretName: wallet-demo-tls-secret
  rules:
    - host: wallet-dev.demo.walt.id
      http:
        paths:
          - path: /wallet-api/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /swagger
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /api.json
            pathType: ImplementationSpecific
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /livez
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /features/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /debug/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /
            pathType: Prefix
            backend:
              service:
                name: waltid-dev-wallet
                port:
                  name: http
    - host: wallet.demo.walt.id
      http:
        paths:
          - path: /wallet-api/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /swagger
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /api.json
            pathType: ImplementationSpecific
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /livez
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /features/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /debug/
            pathType: Prefix
            backend:
              service:
                name: wallet-api
                port:
                  name: http
          - path: /
            pathType: Prefix
            backend:
              service:
                name: waltid-demo-wallet
                port:
                  name: http
