From a564cfa6887b1c0718a52e57c577e41ef09b5724 Mon Sep 17 00:00:00 2001 From: Sergey Voloshin Date: Wed, 10 Apr 2024 21:33:06 +0300 Subject: [PATCH] fix(logs): additional logging Refs: CU-86949cvmb --- command/cert.go | 3 +++ command/deploy.go | 3 +++ utils/client/client.go | 38 +++++++++++++++++++------------------- utils/docker/client.go | 2 +- utils/path.go | 7 +++++++ 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/command/cert.go b/command/cert.go index 5a9ad1a..52b4ac7 100644 --- a/command/cert.go +++ b/command/cert.go @@ -2,6 +2,7 @@ package command import ( "github.com/pterm/pterm" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -23,6 +24,8 @@ func certCommand() *cobra.Command { func storeCertConfig(status bool) { viper.Set("ca", status) + + logrus.Info("Updating the configuration file") err := viper.WriteConfig() if err != nil { pterm.FgRed.Println(err) diff --git a/command/deploy.go b/command/deploy.go index 0da6eb8..fa1eece 100644 --- a/command/deploy.go +++ b/command/deploy.go @@ -162,6 +162,7 @@ func startDump(ctx context.Context, c *client.Client) { func detectFw() (string, error) { ls := strings.Join([]string{"cd", sshClient.Config.Catalog, "&&", "ls"}, " ") + logrus.Infof("Run command: %s", ls) out, err := sshClient.Run(ls) if err != nil { return "", err @@ -183,5 +184,7 @@ func detectFw() (string, error) { return "laravel", nil } + logrus.Errorf("Output of ls: %s", string(out)) + return "", errors.New("failed determine the Framework, please specify accesses manually https://clck.ru/uAGwX") } diff --git a/utils/client/client.go b/utils/client/client.go index 4a1fc78..6e9bc9e 100644 --- a/utils/client/client.go +++ b/utils/client/client.go @@ -36,18 +36,18 @@ type Config struct { Callback ssh.HostKeyCallback } -// DefaultTimeout is the timeout of ssh client connection. -var DefaultTimeout = 20 * time.Second +// defaultTimeout is the timeout of ssh client connection. +var defaultTimeout = 20 * time.Second // NewClient returns new client and error if any func NewClient(config *Config) (c *Client, err error) { - c, err = NewConn(&Config{ + c, err = newConn(&Config{ User: config.User, Addr: config.Addr, Port: config.Port, Catalog: config.Catalog, FwType: config.FwType, - Timeout: DefaultTimeout, + Timeout: defaultTimeout, Auth: getAuth(config), Callback: verifyHost, }) @@ -55,18 +55,18 @@ func NewClient(config *Config) (c *Client, err error) { return } -// NewConn returns new client and error if any. -func NewConn(config *Config) (c *Client, err error) { +// newConn returns new client and error if any. +func newConn(config *Config) (c *Client, err error) { c = &Client{ Config: config, } - c.Client, err = Dial("tcp", config) + c.Client, err = dial("tcp", config) return } -// Dial starts a client connection to SSH server based on config. -func Dial(proto string, c *Config) (*ssh.Client, error) { +// dial starts a client connection to SSH server based on config. +func dial(proto string, c *Config) (*ssh.Client, error) { return ssh.Dial(proto, net.JoinHostPort(c.Addr, fmt.Sprint(c.Port)), &ssh.ClientConfig{ User: c.User, Auth: c.Auth, @@ -100,15 +100,15 @@ func getAuth(config *Config) Auth { auth := Password(askPass("Enter SSH Password: ")) return auth - } else { - home, _ := utils.HomeDir() - auth, err := Key(filepath.Join(home, ".ssh", config.Key), getPassphrase(config.UseKeyPassphrase)) - if err != nil { - pterm.FgRed.Println(err) - return nil - } - return auth } + + home, _ := utils.HomeDir() + auth, err := Key(filepath.Join(home, ".ssh", config.Key), getPassphrase(config.UseKeyPassphrase)) + if err != nil { + pterm.FgRed.Println(err) + return nil + } + return auth } func getPassphrase(ask bool) string { @@ -138,11 +138,11 @@ func verifyHost(host string, remote net.Addr, key ssh.PublicKey) error { } // handshake because public key already exists - if hostFound && err == nil { + if hostFound { return nil } - if askIsHostTrusted(host, key) == false { + if !askIsHostTrusted(host, key) { pterm.FgRed.Println("Connection aborted") return nil } diff --git a/utils/docker/client.go b/utils/docker/client.go index 612a992..1886f47 100644 --- a/utils/docker/client.go +++ b/utils/docker/client.go @@ -45,7 +45,7 @@ func newDockerCli() (*command.DockerCli, error) { } options := flags.NewClientOptions() - options.LogLevel = "fatal" + // options.LogLevel = "fatal" err = dockerCLI.Initialize(options) if err != nil { diff --git a/utils/path.go b/utils/path.go index 035a653..8e1b2b6 100644 --- a/utils/path.go +++ b/utils/path.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/pterm/pterm" + "github.com/sirupsen/logrus" ) // HomeDir user home directory @@ -55,20 +56,25 @@ func CertDir() string { // CertutilPath determine the path to the certutil func CertutilPath() (string, error) { + logrus.Info("Determine the path to the certutil") + switch runtime.GOOS { case "darwin": switch { case BinaryExists("certutil"): certutilPath, _ := exec.LookPath("certutil") + logrus.Infof("Found certutil: %s", certutilPath) return certutilPath, nil case BinaryExists("/usr/local/opt/nss/bin/certutil"): certutilPath := "/usr/local/opt/nss/bin/certutil" + logrus.Infof("Found certutil: %s", certutilPath) return certutilPath, nil default: out, err := exec.Command("brew", "--prefix", "nss").Output() if err == nil { certutilPath := filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil") if pathExists(certutilPath) { + logrus.Infof("Found certutil: %s", certutilPath) return certutilPath, nil } } @@ -77,6 +83,7 @@ func CertutilPath() (string, error) { case "linux": if BinaryExists("certutil") { certutilPath, _ := exec.LookPath("certutil") + logrus.Infof("Found certutil: %s", certutilPath) return certutilPath, nil } }