#!/usr/bin/env bash
# Managed by pubrules {version}: `pubrules sync` rewrites this file, and
# `pubrules sync --check` fails when it differs. This repository's settings are
# in with-secrets.json, which is its own.
#
# Run one command with this repository's secrets in its environment:
#
#   ./with-secrets terraform plan
#   ./with-secrets scripts/some-setup.sh
#
# It runs `pubsec run` from this repository's pinned pubsec (./pubsec, which
# pubrules writes beside ./pubrules), in the directory it is called from. The secrets are read from a Bitwarden
# Secrets Manager project with the bws CLI, using a read-only machine account's
# access token: BWS_ACCESS_TOKEN if set, else the line BWS_ACCESS_TOKEN=... in
# the repository's .env, which git must ignore. They exist only in this
# command's process and what it starts: nothing is written to disk, and the
# calling shell never holds them. pubsec's README, "Services: ./with-secrets",
# explains with-secrets.json.
set -euo pipefail
exec "$(cd "$(dirname "$0")" && pwd)/pubsec" run --cwd "$PWD" -- "$@"
