---
apiVersion: v1
data:
  generate-secrets.sh: |
    set -e

    generate_secret() {
        openssl rand -hex 16 | tr 'a-f' 'A-F' | head -c 32
    }

    GITEA_CLIENT_SECRET=$(generate_secret)
    GITEA_ADMIN_PASSWORD=$(generate_secret)

    cat > /tmp/final-secret-store.yaml << EOF
    apiVersion: external-secrets.io/v1beta1
    kind: ClusterSecretStore
    metadata:
      name: k8srealm-secret-store
    spec:
      provider:
        fake:
          data:
          - key: gitea-client-secret
            value: ${GITEA_CLIENT_SECRET}
          - key: gitea-admin-password
            value: ${GITEA_ADMIN_PASSWORD}
          - key: gitea-admin-username
            value: silogen-admin
    EOF

    kubectl apply -f /tmp/final-secret-store.yaml

    echo "ClusterSecretStore created successfully!"
    echo "Generated secrets with alphanumeric values only"
kind: ConfigMap
metadata:
  name: k8srealm-secret-generator-script
  namespace: default
