fix: feat: disinto secrets add — accept piped stdin for non-interactive imports (#776) #786
1 changed files with 32 additions and 11 deletions
29
bin/disinto
29
bin/disinto
|
|
@ -1180,25 +1180,42 @@ disinto_secrets() {
|
||||||
|
|
||||||
case "$subcmd" in
|
case "$subcmd" in
|
||||||
add)
|
add)
|
||||||
local name="${2:-}"
|
# Parse flags
|
||||||
|
local force=false
|
||||||
|
shift # consume 'add'
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
-f|--force) force=true; shift ;;
|
||||||
|
-*) echo "Unknown flag: $1" >&2; exit 1 ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
local name="${1:-}"
|
||||||
if [ -z "$name" ]; then
|
if [ -z "$name" ]; then
|
||||||
echo "Usage: disinto secrets add <NAME>" >&2
|
echo "Usage: disinto secrets add [-f|--force] <NAME>" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
_secrets_ensure_age_key
|
_secrets_ensure_age_key
|
||||||
mkdir -p "$secrets_dir"
|
mkdir -p "$secrets_dir"
|
||||||
|
|
||||||
printf 'Enter value for %s: ' "$name" >&2
|
|
||||||
local value
|
local value
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
# Interactive TTY — prompt with hidden input (original behavior)
|
||||||
|
printf 'Enter value for %s: ' "$name" >&2
|
||||||
IFS= read -rs value
|
IFS= read -rs value
|
||||||
echo >&2
|
echo >&2
|
||||||
|
else
|
||||||
|
# Piped/redirected stdin — read raw bytes verbatim
|
||||||
|
IFS= read -r -d '' value || true
|
||||||
|
fi
|
||||||
if [ -z "$value" ]; then
|
if [ -z "$value" ]; then
|
||||||
echo "Error: empty value" >&2
|
echo "Error: empty value" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local enc_path="${secrets_dir}/${name}.enc"
|
local enc_path="${secrets_dir}/${name}.enc"
|
||||||
if [ -f "$enc_path" ]; then
|
if [ -f "$enc_path" ] && [ "$force" = false ]; then
|
||||||
|
if [ -t 0 ]; then
|
||||||
printf 'Secret %s already exists. Overwrite? [y/N] ' "$name" >&2
|
printf 'Secret %s already exists. Overwrite? [y/N] ' "$name" >&2
|
||||||
local confirm
|
local confirm
|
||||||
read -r confirm
|
read -r confirm
|
||||||
|
|
@ -1206,6 +1223,10 @@ disinto_secrets() {
|
||||||
echo "Aborted." >&2
|
echo "Aborted." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: secret ${name} already exists (use -f to overwrite)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if ! printf '%s' "$value" | age -r "$AGE_PUBLIC_KEY" -o "$enc_path"; then
|
if ! printf '%s' "$value" | age -r "$AGE_PUBLIC_KEY" -o "$enc_path"; then
|
||||||
echo "Error: encryption failed" >&2
|
echo "Error: encryption failed" >&2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue