From 34671bfd42402134aa98ce3207dfe9cebdb649d7 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Thu, 22 Aug 2024 23:54:45 +0200 Subject: [PATCH] feat: Handle errors on password retrieval from 1Password in secrets.sh --- bin/actions/secrets.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/actions/secrets.sh b/bin/actions/secrets.sh index 65dcaf0..80a08b3 100755 --- a/bin/actions/secrets.sh +++ b/bin/actions/secrets.sh @@ -9,6 +9,13 @@ printfe "%s\n" "cyan" "Fetching password from 1Password..." echo -en '\r' output=$(op item get "SSH Config Secrets" --fields password) + +# Check if the password was found +if [[ -z "$output" ]]; then + printfe "%s\n" "red" "Password not found in 1Password, add a login item with the name 'SSH Config Secrets' and give it a password." + exit 1 +fi + command=$(echo "$output" | grep -oP "(?<=use ').*(?=')") password=$(eval $command | grep -oP "(?<= password: ).*" | tr -d '\n') @@ -38,4 +45,4 @@ elif [[ "$2" == "encrypt" ]]; then else printfe "%s\n" "red" "Invalid argument. Use 'decrypt' or 'encrypt'" exit 1 -fi \ No newline at end of file +fi