Skip to content

Commit

Permalink
Fix adding and deleting keys by using named variables
Browse files Browse the repository at this point in the history
Initial positional parameters have already been parsed and stored in
named variables early, so use them instead of positional parameters

Some wrong conditions have been fixed, and this fixes
cedricziel#30.
  • Loading branch information
baobaab committed Feb 4, 2020
1 parent 8c72c48 commit 6bec6a3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions commands
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ EOF

add_shared_key() {
check_install
if [[ ! -n "$2" ]]; then
if [[ -n "$SHARED_KEY_TO_ADD" ]]; then
echo $SHARED_KEY_TO_ADD >> "$SHARED_HOSTKEYS_FILE"
echo "Added $SHARED_KEY_TO_ADD to the list of shared hostkeys"
else
Expand All @@ -141,7 +141,7 @@ add_shared_key() {

delete_shared_keys() {
check_install
if [[ ! -n "$2" ]]; then
if [[ -n "$HOSTNAME_TO_REMOVE" ]]; then
ssh-keygen -f "$SHARED_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE"
rm "$SHARED_HOSTKEYS_FOLDER/known_hosts.old"
echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup."
Expand All @@ -165,7 +165,7 @@ add_app_key() {
check_app
check_exists
check_install_app
if [[ ! -n "$3" ]]; then
if [[ -n "$SHARED_KEY_TO_ADD_APP" ]]; then
echo $SHARED_KEY_TO_ADD_APP >> "$APP_SPECIFIC_HOSTKEYS_FILE"
echo "Added $SHARED_KEY_TO_ADD_APP to the list of shared hostkeys"
else
Expand All @@ -189,7 +189,7 @@ delete_app_keys() {
check_app
check_exists
check_install_app
if [[ -n "$3" ]]; then
if [[ -n "$HOSTNAME_TO_REMOVE_APP" ]]; then
ssh-keygen -f "$APP_SPECIFIC_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE_APP"
rm "$APP_SPECIFIC_HOSTKEYS_FOLDER/known_hosts.old"
echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup."
Expand Down Expand Up @@ -227,11 +227,11 @@ case "$1" in
;;

hostkeys:shared:add)
add_shared_key "$@"
add_shared_key
;;

hostkeys:shared:delete)
delete_shared_keys "$@"
delete_shared_keys
;;

hostkeys:shared:autoadd)
Expand All @@ -243,11 +243,11 @@ case "$1" in
;;

hostkeys:app:add)
add_app_key "$@"
add_app_key
;;

hostkeys:app:delete)
delete_app_keys "$@"
delete_app_keys
;;

hostkeys:app:autoadd)
Expand Down

0 comments on commit 6bec6a3

Please # to comment.