From 841a459dcad3dbc6bd9e207cbd02797a3fa290d3 Mon Sep 17 00:00:00 2001 From: "Greg T. Wallace" Date: Wed, 19 Jun 2024 19:56:16 -0400 Subject: [PATCH] apcssh: minor log and logic clarity --- pkg/apcssh/cmd_restartwebui.go | 6 ++---- pkg/apcssh/scp.go | 2 +- pkg/apcssh/ssl.go | 8 +++----- pkg/app/cmd_install.go | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/apcssh/cmd_restartwebui.go b/pkg/apcssh/cmd_restartwebui.go index bde8d3a..5196212 100644 --- a/pkg/apcssh/cmd_restartwebui.go +++ b/pkg/apcssh/cmd_restartwebui.go @@ -13,10 +13,8 @@ import ( func (cli *Client) RestartWebUI() error { result, err := cli.cmd("reboot -Y") if err != nil { - return err - } - - if !strings.EqualFold(result.code, "e000") { + return fmt.Errorf("apcssh: failed to restart web ui (%w)", err) + } else if !strings.EqualFold(result.code, "e000") { return fmt.Errorf("apcssh: failed to restart web ui (%s: %s)", result.code, result.codeText) } diff --git a/pkg/apcssh/scp.go b/pkg/apcssh/scp.go index 9db77c0..a37d154 100644 --- a/pkg/apcssh/scp.go +++ b/pkg/apcssh/scp.go @@ -19,7 +19,7 @@ func (cli *Client) UploadSCP(destination string, fileContent []byte, filePermiss // connect sshClient, err := ssh.Dial("tcp", cli.hostname, cli.sshCfg) 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() diff --git a/pkg/apcssh/ssl.go b/pkg/apcssh/ssl.go index 233ea38..2eb3bce 100644 --- a/pkg/apcssh/ssl.go +++ b/pkg/apcssh/ssl.go @@ -12,7 +12,7 @@ func (cli *Client) InstallSSLCert(keyP15 []byte, certPem []byte, keyCertP15 []by // run `ssl` command to check if it exists result, err := cli.cmd("ssl") 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" 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") if err != nil { return fmt.Errorf("apcssh: ssl cert install: failed to send ssl key install cmd (%w)", err) - } - if !strings.EqualFold(result.code, "e000") { + } else 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) } result, err = cli.cmd("ssl cert -i /ssl/nmc.crt") if err != nil { return fmt.Errorf("apcssh: ssl cert install: failed to send ssl cert install cmd (%w)", err) - } - if !strings.EqualFold(result.code, "e000") { + } else 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) } diff --git a/pkg/app/cmd_install.go b/pkg/app/cmd_install.go index b02d112..d3270a4 100644 --- a/pkg/app/cmd_install.go +++ b/pkg/app/cmd_install.go @@ -71,7 +71,7 @@ func (app *app) cmdInstall(cmdCtx context.Context, args []string) error { // install SSL Cert err = client.InstallSSLCert(keyP15, certPem, keyCertP15) if err != nil { - return fmt.Errorf("install: failed to send file to ups over scp (%w)", err) + return fmt.Errorf("install: %w", err) } // installed