introduced DownloadCommand and Shell types to improve type safety
This commit is contained in:
parent
6c6d396393
commit
4fbe5c7907
@ -56,7 +56,7 @@ func main() {
|
|||||||
Id: "myid",
|
Id: "myid",
|
||||||
SshKeys: []string{"a", "b"},
|
SshKeys: []string{"a", "b"},
|
||||||
ErrorMessages: []string{},
|
ErrorMessages: []string{},
|
||||||
RemoteShells: map[string]bool{templates2.POWERSHELL: true},
|
RemoteShells: map[templates2.Shell]bool{templates2.POWERSHELL: true},
|
||||||
LocalShells: nil,
|
LocalShells: nil,
|
||||||
}
|
}
|
||||||
shellUsage := func() templ.Component {
|
shellUsage := func() templ.Component {
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
const BASH = "*.sh"
|
type Shell string
|
||||||
const CMD = "cmd"
|
|
||||||
const POWERSHELL = "powershell"
|
|
||||||
|
|
||||||
const CURL = "curl"
|
const (
|
||||||
const WGET = "wget"
|
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",
|
CURL: "curl -o",
|
||||||
WGET: "wget -O",
|
WGET: "wget -O",
|
||||||
}
|
}
|
||||||
|
@ -206,9 +206,9 @@ templ Usage(access models.ConvergeAccess) {
|
|||||||
agent environment<sup><i class="bi bi-info-circle small"></i></sup></label>
|
agent environment<sup><i class="bi bi-info-circle small"></i></sup></label>
|
||||||
</td>
|
</td>
|
||||||
<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 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={CMD}> <label for="remote-shell-1">command prompt</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={POWERSHELL}> <label for="remote-shell-2">power shell</label>
|
<input id="remote-shell-2" name="remote-shell" type="radio" value={string(POWERSHELL)}> <label for="remote-shell-2">power shell</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -221,8 +221,8 @@ templ Usage(access models.ConvergeAccess) {
|
|||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input checked id="download-command-0" name="download-command" type="radio" value={CURL}> <label for="download-command-0">curl</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={WGET}> <label for="download-command-1">wget</label>
|
<input id="download-command-1" name="download-command" type="radio" value={string(WGET)}> <label for="download-command-1">wget</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -241,7 +241,7 @@ templ Usage(access models.ConvergeAccess) {
|
|||||||
<!--tr>
|
<!--tr>
|
||||||
<td class="minimal-width"><label for="local-shell">local environment</label></td>
|
<td class="minimal-width"><label for="local-shell">local environment</label></td>
|
||||||
<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-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>
|
<input id="local-shell-2" name="local-shell" type="radio" value={POWERSHELL}> <label for="local-shell-2">powershell</label>
|
||||||
</td>
|
</td>
|
||||||
|
@ -9,9 +9,9 @@ type UsageInputs struct {
|
|||||||
SshKeys []string
|
SshKeys []string
|
||||||
ErrorMessages []string
|
ErrorMessages []string
|
||||||
|
|
||||||
RemoteShells map[string]bool
|
RemoteShells map[Shell]bool
|
||||||
LocalShells map[string]bool
|
LocalShells map[Shell]bool
|
||||||
DownloadCommand string
|
DownloadCommand DownloadMethod
|
||||||
CertificateValidation bool
|
CertificateValidation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,21 +21,21 @@ func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, lo
|
|||||||
inputs := UsageInputs{
|
inputs := UsageInputs{
|
||||||
Id: id,
|
Id: id,
|
||||||
SshKeys: sshPublicKeys,
|
SshKeys: sshPublicKeys,
|
||||||
RemoteShells: make(map[string]bool),
|
RemoteShells: make(map[Shell]bool),
|
||||||
LocalShells: make(map[string]bool),
|
LocalShells: make(map[Shell]bool),
|
||||||
DownloadCommand: downloadCommand,
|
DownloadCommand: DownloadMethod(downloadCommand),
|
||||||
CertificateValidation: certificateValidation,
|
CertificateValidation: certificateValidation,
|
||||||
}
|
}
|
||||||
for _, remoteShell := range remoteShells {
|
for _, remoteShell := range remoteShells {
|
||||||
inputs.RemoteShells[remoteShell] = true
|
inputs.RemoteShells[Shell(remoteShell)] = true
|
||||||
}
|
}
|
||||||
for _, localShell := range localShells {
|
for _, localShell := range localShells {
|
||||||
inputs.LocalShells[localShell] = true
|
inputs.LocalShells[Shell(localShell)] = true
|
||||||
}
|
}
|
||||||
return inputs
|
return inputs
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSshKeys(shell string, keys []string) string {
|
func addSshKeys(shell Shell, keys []string) string {
|
||||||
|
|
||||||
quote := `"`
|
quote := `"`
|
||||||
if shell == CMD {
|
if shell == CMD {
|
||||||
|
Loading…
Reference in New Issue
Block a user