Merge pull request #4261 from dokku/ssh-keys-commands

Add remove by fingerprint and json format output to ssh-keys plugin
This commit is contained in:
Jose Diaz-Gonzalez
2020-12-20 13:52:11 -05:00
committed by GitHub
8 changed files with 301 additions and 12 deletions

View File

@@ -8,10 +8,31 @@ cmd-ssh-keys-list() {
declare desc="List ssh key hashes"
declare cmd="ssh-keys:list"
[[ "$1" == "$cmd" ]] && shift 1
declare SSH_NAME="$1"
declare NAME="$1"
local FORMAT=text
if [[ "$NAME" == "--format" ]]; then
FORMAT="$2"
NAME="$3"
fi
if [[ "$FORMAT" != "text" ]] && [[ "$FORMAT" != "json" ]]; then
dokku_log_fail "Invalid output format specified, supported formats: json, text"
fi
if [[ "$FORMAT" == "text" ]]; then
FORMAT=""
fi
verify_ssh_key_file
sshcommand list dokku "$SSH_NAME"
if [[ "$FORMAT" == "json" ]]; then
if [[ -n "$NAME" ]]; then
sshcommand list dokku "" "$FORMAT" | jq -cM "[.[] | select(.name == \"$NAME\")]"
else
sshcommand list dokku "" "$FORMAT"
fi
else
sshcommand list dokku "$NAME"
fi
}
cmd-ssh-keys-list "$@"

View File

@@ -8,11 +8,20 @@ cmd-ssh-keys-remove() {
declare desc="Removes key from authorized_keys"
declare cmd="ssh-keys:remove"
[[ "$1" == "$cmd" ]] && shift 1
declare NAME="$1"
declare NAME="$1" FINGERPRINT="$2"
verify_ssh_key_file
[[ -z "$NAME" ]] && dokku_log_fail "A name is required to remove a key, ie: dokku ssh-keys:remove <name>"
sshcommand acl-remove dokku "$NAME" || dokku_log_fail "sshcommand returned an error $?"
if [[ "$NAME" == "--fingerprint" ]]; then
[[ -z "$FINGERPRINT" ]] && dokku_log_fail "A fingerprint is required to remove a key, ie: dokku ssh-keys:remove --fingerprint FINGERPRINT"
elif [[ -z "$NAME" ]]; then
dokku_log_fail "A name is required to remove a key, ie: dokku ssh-keys:remove <name>"
fi
if [[ "$NAME" == "--fingerprint" ]]; then
sshcommand acl-remove-by-fingerprint dokku "$FINGERPRINT" || dokku_log_fail "sshcommand returned an error $?"
else
sshcommand acl-remove dokku "$NAME" || dokku_log_fail "sshcommand returned an error $?"
fi
}
cmd-ssh-keys-remove "$@"