Skip to content

Commit

Permalink
fix(logs): additional logging
Browse files Browse the repository at this point in the history
Refs: CU-86949cvmb
  • Loading branch information
varrcan committed Apr 10, 2024
1 parent 492cf35 commit a564cfa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
3 changes: 3 additions & 0 deletions command/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"github.com/pterm/pterm"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
38 changes: 19 additions & 19 deletions utils/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,37 @@ 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,
})

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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion utils/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions utils/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/pterm/pterm"
"github.com/sirupsen/logrus"
)

// HomeDir user home directory
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down

0 comments on commit a564cfa

Please sign in to comment.