converge/pkg/server/templates/usageinputs.go
Erik Brakkee b41317c598 Lots of work on making easier interactive documentation, especially to make working with SSH public keys really easy.
Next step is to do more validation in the UI.
Specifically:
* validate authorized keys
* detection of accidental use of a private key

Then, password based access can be disabled.
2024-09-08 11:16:49 +02:00

46 lines
965 B
Go

package templates
import (
"fmt"
)
type UsageInputs struct {
Id string
SshKeys []string
RemoteShells map[string]bool
LocalShells map[string]bool
}
func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, localShells []string) UsageInputs {
inputs := UsageInputs{
Id: id,
SshKeys: sshPublicKeys,
RemoteShells: make(map[string]bool),
LocalShells: make(map[string]bool),
}
for _, remoteShell := range remoteShells {
inputs.RemoteShells[remoteShell] = true
}
for _, localShell := range localShells {
inputs.LocalShells[localShell] = true
}
return inputs
}
func addSshKeys(shell string, keys []string) string {
quote := `"`
if shell == CMD {
quote = ""
}
res := ""
for index, key := range keys {
operator := ">>"
if index == 0 {
operator = ">"
}
res += fmt.Sprintf(" echo %s%s%s %s .authorized_keys\n", quote, key, quote,
operator)
}
return res + " "
}