apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: redis-command
  labels:
    dagweave.io/catalog-item: redis-command
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.0"
    dagweave.io/catalog-category: "Databases"
spec:
  entrypoint: run
  templates:
    - name: run
      inputs:
        parameters:
          # Redis server host.
          - name: host
          # Redis server port.
          - name: port
            default: "6379"
          # The Redis command to run (e.g. GET, SET, LPUSH).
          - name: command
          # Space-separated arguments for the command (e.g. "mykey myvalue").
          - name: args
            default: ""
          # Name of the Kubernetes Secret holding the AUTH password. Defaults let a
          # user leave them blank in the Inspector.
          - name: password-secret-name
            default: redis-password
          - name: password-secret-key
            default: password
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # redis:8-alpine (ships redis-cli)
        image: redis@sha256:21090af93f8324db2f0f0f4f38a7c60369d47d917e000c3423d89d2ae2883537
        command: [sh, -c]
        # Host, port, command and args are passed as env vars (below), never
        # interpolated from Argo into the shell, so they carry no injection risk.
        # redis-cli reads the AUTH password from REDISCLI_AUTH, so it never appears on
        # the command line. $COMMAND and $ARGS are intentionally left unquoted so the
        # args string is split into separate redis-cli arguments.
        args:
          - |
            set -eu
            redis-cli -h "$HOST" -p "$PORT" $COMMAND $ARGS
        env:
          - name: HOST
            value: "{{inputs.parameters.host}}"
          - name: PORT
            value: "{{inputs.parameters.port}}"
          - name: COMMAND
            value: "{{inputs.parameters.command}}"
          - name: ARGS
            value: "{{inputs.parameters.args}}"
          - name: REDISCLI_AUTH
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.password-secret-name}}"
                key: "{{inputs.parameters.password-secret-key}}"
