apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: azure-blob-upload
  labels:
    dagweave.io/catalog-item: azure-blob-upload
  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.2"
    dagweave.io/catalog-category: "Object storage"
spec:
  entrypoint: upload
  templates:
    - name: upload
      inputs:
        parameters:
          # Azure storage account name.
          - name: account
          # Target blob container within the account.
          - name: container
          # Destination blob name within the container.
          - name: blob
          # Local path of the file to upload.
          - name: source-path
          # Name of the Kubernetes Secret holding the storage account key, plus the
          # key within it. Defaults let a user leave them blank in the Inspector.
          - name: azure-secret-name
            default: azure-storage-credentials
          - name: azure-secret-key
            default: account-key
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # mcr.microsoft.com/azure-cli:2.91.0
        image: mcr.microsoft.com/azure-cli@sha256:933eb8dcb81aecb6f77e03c5b8660f0a1dfa9e1d16525763a27f86ff3b83a044
        command: [sh, -c]
        # The account key is passed as AZURE_STORAGE_KEY (read automatically by the
        # az CLI), never interpolated into the shell. Account/container/blob/source
        # are passed as env too and referenced double-quoted, so metacharacters are
        # safe.
        args:
          - |
            set -eu
            az storage blob upload \
              --account-name "${AZURE_STORAGE_ACCOUNT}" \
              --container-name "${BLOB_CONTAINER}" \
              --name "${BLOB_NAME}" \
              --file "${SOURCE_PATH}" \
              --overwrite
        env:
          - name: AZURE_STORAGE_ACCOUNT
            value: "{{inputs.parameters.account}}"
          - name: BLOB_CONTAINER
            value: "{{inputs.parameters.container}}"
          - name: BLOB_NAME
            value: "{{inputs.parameters.blob}}"
          - name: SOURCE_PATH
            value: "{{inputs.parameters.source-path}}"
          - name: AZURE_STORAGE_KEY
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.azure-secret-name}}"
                key: "{{inputs.parameters.azure-secret-key}}"
