# 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:
#   curl -o config.yaml https://docs.expanso.io/examples/signing-and-verifying.yaml
#   expanso-edge run -f config.yaml

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
