From c4d2592e41a77bdc1f7c0198938c7ea1387dffe6 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 16 May 2023 17:38:16 +0200 Subject: [PATCH] Do not show missing user error if there is no ssh-key provided fixes https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud/-/issues/41 --- lib/tiny-cloud/init | 7 ++++++- tests/tiny-cloud.test | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 51cb541..4759977 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -217,6 +217,11 @@ init__set_hostname() { } init__set_ssh_keys() { + local sshkeys="$(imds @ssh-keys)" + if [ -z "$sshkeys" ]; then + log -i -t "$phase" info "$ACTION: no ssh key found" + return + fi local user="$CLOUD_USER" local pwent="$(getent passwd "$user")" if [ -z "$pwent" ]; then @@ -235,7 +240,7 @@ init__set_ssh_keys() { touch "$keys_file" chmod 600 "$keys_file" $MOCK chown -R "$user:$group" "$ssh_dir" - imds @ssh-keys > "$keys_file" + echo "$sshkeys" > "$keys_file" } init__save_userdata() { diff --git a/tests/tiny-cloud.test b/tests/tiny-cloud.test index 01c9019..3f98423 100755 --- a/tests/tiny-cloud.test +++ b/tests/tiny-cloud.test @@ -54,6 +54,7 @@ no_userdata_main_body() { # we should not set empty hostname # we should not create .ssh dir for non-existing user CLOUD="$provider" atf_check \ + -e not-match:"failed" \ -e not-match:"unknown" \ -o not-match:"hostname.*-F" \ -o not-match:"chown.*/\.ssh" \