Skip to content

Commit

Permalink
CLI: tls config validation - make it a warning
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Aug 20, 2024
1 parent 461a64b commit 88902b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 2 additions & 6 deletions cmd/cli/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func Init(args []string) (err error) {
UA: ua,
}
if cos.IsHTTPS(clusterURL) {
if err = cfg.ValidateTLS(); err != nil {
return err
}
cfg.WarnTLS("aistore at " + clusterURL)
clientTLS = cmn.NewClientTLS(cargs, sargs)
apiBP.Client = clientTLS
} else {
Expand All @@ -74,9 +72,7 @@ func Init(args []string) (err error) {
}
if cos.IsHTTPS(authnURL) {
if clientTLS == nil {
if err = cfg.ValidateTLS(); err != nil {
return err
}
cfg.WarnTLS("AuthN at " + authnURL)
clientTLS = cmn.NewClientTLS(cargs, sargs)
}
authParams.Client = clientTLS
Expand Down
10 changes: 6 additions & 4 deletions cmd/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,18 @@ func (c *Config) validate() (err error) {
return nil
}

func (c *Config) ValidateTLS() (err error) {
err = cos.Stat(c.Cluster.Certificate)
func (c *Config) WarnTLS(server string) {
err := cos.Stat(c.Cluster.Certificate)
if err == nil {
err = cos.Stat(c.Cluster.CertKey)
}
if err == nil {
return nil
return
}
path := filepath.Join(ConfigDir, fname.CliConfig)
return fmt.Errorf("CLI config at %s: invalid public/private key pair (%q,%q): %v",

fmt.Fprintln(os.Stderr, "Warning: CLI may have a problem communicating with "+server+" - CLI config at")
fmt.Fprintf(os.Stderr, "%s contains invalid public/private key pair (%q,%q), err: %v\n\n",
path, c.Cluster.Certificate, c.Cluster.CertKey, err)
}

Expand Down

0 comments on commit 88902b5

Please sign in to comment.