From a0ae2d7d974990b2c868fa08362b7df682b62834 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Wed, 4 Sep 2024 22:04:13 +0200 Subject: [PATCH] powershell instructions did not work when mukltiple ssh keys were configured. Also ignoring empty lines in the input. --- .idea/.gitignore | 8 -------- pkg/server/ui/usageinputs.go | 12 +++++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) delete mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/pkg/server/ui/usageinputs.go b/pkg/server/ui/usageinputs.go index 1508d07..c634c6d 100644 --- a/pkg/server/ui/usageinputs.go +++ b/pkg/server/ui/usageinputs.go @@ -2,6 +2,7 @@ package ui import ( "fmt" + "strings" ) type UsageInputs struct { @@ -38,12 +39,21 @@ func addSshKeys(shell Shell, keys []string) string { } res := "" for index, key := range keys { + key = strings.TrimSpace(key) + if key == "" { + continue + } operator := ">>" if index == 0 { operator = ">" } if shell == POWERSHELL { - res += fmt.Sprintf(`"%s" | Out-File -FilePath ".authorized_keys" -Encoding ASCII
`, key) + append := "" + if index > 0 { + append = "-Append " + } + res += fmt.Sprintf(`"%s" | Out-File %s-FilePath ".authorized_keys" -Encoding ASCII
`, + key, append) } else { res += fmt.Sprintf(" echo %s%s%s %s .authorized_keys
", quote, key, quote, operator)