Merge pull request #2465 from polettix/2446-add-ssh-keys
Patch GH #2446 "Adding a file with two ssh-key..."
This commit is contained in:
@@ -5,7 +5,11 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
verify_ssh_key_file() {
|
||||
declare desc="Test that public key is valid"
|
||||
[[ -s ${DOKKU_ROOT}/.ssh/authorized_keys ]] || dokku_log_fail "No public keys found."
|
||||
ssh-keygen -l -f "${DOKKU_ROOT}/.ssh/authorized_keys" &> /dev/null || dokku_log_fail "${DOKKU_ROOT}/.ssh/authorized_keys failed ssh-keygen check."
|
||||
local key line=0
|
||||
while read key ; do
|
||||
line=$((line + 1))
|
||||
ssh-keygen -l -f /dev/stdin <<< "$key" &> /dev/null || dokku_log_fail "${DOKKU_ROOT}/.ssh/authorized_keys line $line failed ssh-keygen check."
|
||||
done <"${DOKKU_ROOT}/.ssh/authorized_keys"
|
||||
}
|
||||
|
||||
verify_ssh_key_exists() {
|
||||
|
||||
@@ -14,10 +14,14 @@ add_keys() {
|
||||
key_contents="$key_from_pipe"
|
||||
elif [[ -n "$key_file" ]]; then
|
||||
key_contents="$(cat "$key_file")"
|
||||
ssh-keygen -lf /dev/stdin <<< "$key_contents" &> /dev/null || dokku_log_fail "Key from file is not a valid ssh public key"
|
||||
fi
|
||||
[[ -n "$name" && -n "$key_contents" ]] || dokku_log_fail "Two arguments are required if not piping, ie: dokku ssh-keys:add <NAME> <KEY_FILE>"
|
||||
local count="$(wc -l <<< "$key_contents")"
|
||||
[ "$count" -eq 1 ] || dokku_log_fail 'Too many keys provided, set one per invocation of dokku ssh-keys:add <NAME> <KEY_FILE>'
|
||||
verify_ssh_key_exists
|
||||
echo "$key_contents" | sshcommand acl-add dokku "$name" || dokku_log_fail "sshcommand returned an error: $?"
|
||||
verify_ssh_key_file
|
||||
}
|
||||
|
||||
add_keys "$@"
|
||||
|
||||
Reference in New Issue
Block a user