introduced DownloadCommand and Shell types to improve type safety

This commit is contained in:
Erik Brakkee 2024-08-17 10:12:09 +02:00
parent 6c6d396393
commit 4fbe5c7907
4 changed files with 30 additions and 22 deletions

View File

@ -56,7 +56,7 @@ func main() {
Id: "myid",
SshKeys: []string{"a", "b"},
ErrorMessages: []string{},
RemoteShells: map[string]bool{templates2.POWERSHELL: true},
RemoteShells: map[templates2.Shell]bool{templates2.POWERSHELL: true},
LocalShells: nil,
}
shellUsage := func() templ.Component {

View File

@ -1,13 +1,21 @@
package templates
const BASH = "*.sh"
const CMD = "cmd"
const POWERSHELL = "powershell"
type Shell string
const CURL = "curl"
const WGET = "wget"
const (
BASH Shell = "bash"
CMD Shell = "cmd"
POWERSHELL Shell = "powershell"
)
var DOWNLOAD_COMMAND = map[string]string{
type DownloadMethod string
const (
CURL DownloadMethod = "curl"
WGET DownloadMethod = "wget"
)
var DOWNLOAD_COMMAND = map[DownloadMethod]string{
CURL: "curl -o",
WGET: "wget -O",
}

View File

@ -206,9 +206,9 @@ templ Usage(access models.ConvergeAccess) {
agent environment<sup><i class="bi bi-info-circle small"></i></sup></label>
</td>
<td>
<input checked id="remote-shell-0" name="remote-shell" type="radio" value={BASH}> <label for="remote-shell-0">bash, sh, zsh, ...</label>
<input id="remote-shell-1" name="remote-shell" type="radio" value={CMD}> <label for="remote-shell-1">command prompt</label>
<input id="remote-shell-2" name="remote-shell" type="radio" value={POWERSHELL}> <label for="remote-shell-2">power shell</label>
<input checked id="remote-shell-0" name="remote-shell" type="radio" value={string(BASH)}> <label for="remote-shell-0">bash, sh, zsh, ...</label>
<input id="remote-shell-1" name="remote-shell" type="radio" value={string(CMD)}> <label for="remote-shell-1">command prompt</label>
<input id="remote-shell-2" name="remote-shell" type="radio" value={string(POWERSHELL)}> <label for="remote-shell-2">power shell</label>
</td>
</tr>
<tr>
@ -221,8 +221,8 @@ templ Usage(access models.ConvergeAccess) {
</label>
</td>
<td>
<input checked id="download-command-0" name="download-command" type="radio" value={CURL}> <label for="download-command-0">curl</label>
<input id="download-command-1" name="download-command" type="radio" value={WGET}> <label for="download-command-1">wget</label>
<input checked id="download-command-0" name="download-command" type="radio" value={string(CURL)}> <label for="download-command-0">curl</label>
<input id="download-command-1" name="download-command" type="radio" value={string(WGET)}> <label for="download-command-1">wget</label>
</td>
</tr>
<tr>
@ -241,7 +241,7 @@ templ Usage(access models.ConvergeAccess) {
<!--tr>
<td class="minimal-width"><label for="local-shell">local environment</label></td>
<td>
<input id="checked local-shell-0" name="local-shell" type="radio" value={BASH}> <label for="local-shell-0">*.sh</label>
<input id="checked local-shell-0" name="local-shell" type="radio" value={BASH}> <label for="local-shell-0">*sh</label>
<input id="local-shell-1" name="local-shell" type="radio" value={CMD}> <label for="local-shell-1">command prompt</label>
<input id="local-shell-2" name="local-shell" type="radio" value={POWERSHELL}> <label for="local-shell-2">powershell</label>
</td>

View File

@ -9,9 +9,9 @@ type UsageInputs struct {
SshKeys []string
ErrorMessages []string
RemoteShells map[string]bool
LocalShells map[string]bool
DownloadCommand string
RemoteShells map[Shell]bool
LocalShells map[Shell]bool
DownloadCommand DownloadMethod
CertificateValidation bool
}
@ -21,21 +21,21 @@ func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, lo
inputs := UsageInputs{
Id: id,
SshKeys: sshPublicKeys,
RemoteShells: make(map[string]bool),
LocalShells: make(map[string]bool),
DownloadCommand: downloadCommand,
RemoteShells: make(map[Shell]bool),
LocalShells: make(map[Shell]bool),
DownloadCommand: DownloadMethod(downloadCommand),
CertificateValidation: certificateValidation,
}
for _, remoteShell := range remoteShells {
inputs.RemoteShells[remoteShell] = true
inputs.RemoteShells[Shell(remoteShell)] = true
}
for _, localShell := range localShells {
inputs.LocalShells[localShell] = true
inputs.LocalShells[Shell(localShell)] = true
}
return inputs
}
func addSshKeys(shell string, keys []string) string {
func addSshKeys(shell Shell, keys []string) string {
quote := `"`
if shell == CMD {