mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 08:14:08 +00:00
apcssh: minor log and logic clarity
This commit is contained in:
parent
f1dd079632
commit
841a459dca
4 changed files with 7 additions and 11 deletions
|
@ -13,10 +13,8 @@ import (
|
||||||
func (cli *Client) RestartWebUI() error {
|
func (cli *Client) RestartWebUI() error {
|
||||||
result, err := cli.cmd("reboot -Y")
|
result, err := cli.cmd("reboot -Y")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("apcssh: failed to restart web ui (%w)", err)
|
||||||
}
|
} else if !strings.EqualFold(result.code, "e000") {
|
||||||
|
|
||||||
if !strings.EqualFold(result.code, "e000") {
|
|
||||||
return fmt.Errorf("apcssh: failed to restart web ui (%s: %s)", result.code, result.codeText)
|
return fmt.Errorf("apcssh: failed to restart web ui (%s: %s)", result.code, result.codeText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (cli *Client) UploadSCP(destination string, fileContent []byte, filePermiss
|
||||||
// connect
|
// connect
|
||||||
sshClient, err := ssh.Dial("tcp", cli.hostname, cli.sshCfg)
|
sshClient, err := ssh.Dial("tcp", cli.hostname, cli.sshCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("apcssh: scp: failed to dial session (%w)", err)
|
return fmt.Errorf("apcssh: scp: failed to dial client (%w)", err)
|
||||||
}
|
}
|
||||||
defer sshClient.Close()
|
defer sshClient.Close()
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ func (cli *Client) InstallSSLCert(keyP15 []byte, certPem []byte, keyCertP15 []by
|
||||||
// run `ssl` command to check if it exists
|
// run `ssl` command to check if it exists
|
||||||
result, err := cli.cmd("ssl")
|
result, err := cli.cmd("ssl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("apcssh: ssl cert install: failed to send ssl cmd (%w)", err)
|
return fmt.Errorf("apcssh: ssl cert install: failed to test ssl cmd (%w)", err)
|
||||||
}
|
}
|
||||||
// E101 is the code for "Command Not Found"
|
// E101 is the code for "Command Not Found"
|
||||||
supportsSSLCmd := !strings.EqualFold(result.code, "e101")
|
supportsSSLCmd := !strings.EqualFold(result.code, "e101")
|
||||||
|
@ -45,16 +45,14 @@ func (cli *Client) installSSLCertModern(keyP15 []byte, certPem []byte) error {
|
||||||
result, err := cli.cmd("ssl key -i /ssl/nmc.key")
|
result, err := cli.cmd("ssl key -i /ssl/nmc.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("apcssh: ssl cert install: failed to send ssl key install cmd (%w)", err)
|
return fmt.Errorf("apcssh: ssl cert install: failed to send ssl key install cmd (%w)", err)
|
||||||
}
|
} else if !strings.EqualFold(result.code, "e000") {
|
||||||
if !strings.EqualFold(result.code, "e000") {
|
|
||||||
return fmt.Errorf("apcssh: ssl cert install: ssl key install cmd returned error code (%s: %s)", result.code, result.codeText)
|
return fmt.Errorf("apcssh: ssl cert install: ssl key install cmd returned error code (%s: %s)", result.code, result.codeText)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = cli.cmd("ssl cert -i /ssl/nmc.crt")
|
result, err = cli.cmd("ssl cert -i /ssl/nmc.crt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("apcssh: ssl cert install: failed to send ssl cert install cmd (%w)", err)
|
return fmt.Errorf("apcssh: ssl cert install: failed to send ssl cert install cmd (%w)", err)
|
||||||
}
|
} else if !strings.EqualFold(result.code, "e000") {
|
||||||
if !strings.EqualFold(result.code, "e000") {
|
|
||||||
return fmt.Errorf("apcssh: ssl cert install: ssl cert install cmd returned error code (%s: %s)", result.code, result.codeText)
|
return fmt.Errorf("apcssh: ssl cert install: ssl cert install cmd returned error code (%s: %s)", result.code, result.codeText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (app *app) cmdInstall(cmdCtx context.Context, args []string) error {
|
||||||
// install SSL Cert
|
// install SSL Cert
|
||||||
err = client.InstallSSLCert(keyP15, certPem, keyCertP15)
|
err = client.InstallSSLCert(keyP15, certPem, keyCertP15)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install: failed to send file to ups over scp (%w)", err)
|
return fmt.Errorf("install: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// installed
|
// installed
|
||||||
|
|
Loading…
Reference in a new issue