26 lines
469 B
Bash
26 lines
469 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# Edit a single attribute of a sops json file
|
||
|
# Helps working with multiline strings in json
|
||
|
|
||
|
set -euo pipefail
|
||
|
|
||
|
SECRETS_FILE="$1"
|
||
|
KEY="$2"
|
||
|
|
||
|
if [[ -n $EDITOR ]]; then
|
||
|
EDITOR=vim
|
||
|
fi
|
||
|
|
||
|
TMP_FILE="$(mktemp)"
|
||
|
|
||
|
clerie-sops --decrypt --extract "[\"${KEY}\"]" "${SECRETS_FILE}" > "${TMP_FILE}"
|
||
|
|
||
|
vim "${TMP_FILE}"
|
||
|
|
||
|
JSON_QUOTED_SECRET="$(jq -Rs '.' "${TMP_FILE}")"
|
||
|
|
||
|
rm "${TMP_FILE}"
|
||
|
|
||
|
clerie-sops --set "[\"${KEY}\"] ${JSON_QUOTED_SECRET}" "${SECRETS_FILE}"
|