# Sign Pipeline Messages
# Sign every message with the edge node's identity and fan out to HTTP (signature in headers) and file (signature in body) using the signature processor.
#
# Source: https://docs.expanso.io/examples/signing-and-verifying
#
# Usage (runs locally, no account needed):
#   curl -sSLo pipeline.yaml https://docs.expanso.io/examples/signing-and-verifying.yaml
#   expanso-edge validate pipeline.yaml
#   expanso-edge run --local --data-dir ./.edge
#
# In a second terminal, deploy the pipeline to it as a job:
#   export EXPANSO_CLI_CONFIG_DIR="$PWD/.expanso-cli"
#   { printf 'name: signing-and-verifying\ntype: pipeline\nconfig:\n'
#     sed 's/^/  /' pipeline.yaml; } |
#     expanso-cli --endpoint http://localhost:9010 job deploy -

input:
  generate:
    interval: 1s
    mapping: |
      root.temp_c     = 21.5
      root.sensor_id  = 42
      root.marker     = "sig-example"
      root.destination = if random_int(min: 0, max: 1) == 0 { "http" } else { "file" }

pipeline:
  processors:
    - signature:
        target: both
        body_format: nested
        body_key: _signature
        on_signing_error: fail

output:
  switch:
    cases:
      - check: this.destination == "http"
        output:
          http_client:
            url: https://example.com/ingest
            verb: POST
            metadata:
              include_patterns:
                - "^expanso_"

      - check: this.destination == "file"
        output:
          file:
            path: /var/log/signed-events.jsonl
            codec: lines
