Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rekey only specific identity #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pkgs/agenix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function show_help () {
echo '-h, --help show help'
# shellcheck disable=SC2016
echo '-e, --edit FILE edits FILE using $EDITOR'
echo '-r, --rekey re-encrypts all secrets with specified recipients'
echo '-r, --rekey [PUBLIC_KEY] re-encrypts all secrets with specified recipients'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this makes sense here.

It makes parsing harder e.g. --rekey -v is currently broken.

echo '-d, --decrypt FILE decrypts FILE to STDOUT'
echo '-i, --identity identity to use when decrypting'
echo '-v, --verbose verbose output'
Expand Down Expand Up @@ -46,6 +46,7 @@ function err() {
test $# -eq 0 && (show_help && exit 1)

REKEY=0
REKEY_PUBLIC_KEY=
DECRYPT_ONLY=0
DEFAULT_DECRYPT=(--decrypt)

Expand Down Expand Up @@ -77,6 +78,10 @@ while test $# -gt 0; do
;;
-r|--rekey)
shift
if test $# -gt 0; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Fix e.g. --rekey -v

REKEY_PUBLIC_KEY="$1"
shift
fi
REKEY=1
;;
-d|--decrypt)
Expand Down Expand Up @@ -189,7 +194,22 @@ function edit {
}

function rekey {
FILES=$( (@nixInstantiate@ --json --eval -E "(let rules = import $RULES; in builtins.attrNames rules)" | @jqBin@ -r .[]) || exit 1)
if test ! -z "$REKEY_PUBLIC_KEY"; then
FILTER_EXPRESSION="builtins.elem \"$REKEY_PUBLIC_KEY\" rules.\${file}.publicKeys";
else
FILTER_EXPRESSION="true";
fi

RULES_EXPRESSION=$(cat <<EOF
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using a here document make sense here? I tried fitting it all in the single line but that isn't pretty.

let
rules = import $RULES;
filter = file: $FILTER_EXPRESSION;
in
builtins.filter filter (builtins.attrNames rules)
EOF
)

FILES=$( (@nixInstantiate@ --json --eval -E "$RULES_EXPRESSION" | @jqBin@ -r .[]) || exit 1)

for FILE in $FILES
do
Expand Down
Loading