Skip to content

Commit

Permalink
chore(client/daemon): cleanup, and add noTLSConfig instead nil for be…
Browse files Browse the repository at this point in the history
…tter readable
  • Loading branch information
sashamelentyev committed Oct 9, 2023
1 parent 2b4e378 commit 321f0ba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions client/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) {
tmpOpt := config.NewDaemonConfig()
err := tmpOpt.Load(viper.ConfigFileUsed())
if err != nil {
return nil, fmt.Errorf("read config error: %s", err)
return nil, fmt.Errorf("read config error: %w", err)
}

err = source.InitSourceClients(tmpOpt.Download.ResourceClients)
Expand Down Expand Up @@ -400,15 +400,17 @@ func loadLegacyGPRCTLSCredentials(opt config.SecurityOption, certifyClient *cert
return loadGPRCTLSCredentialsWithOptions(opt.TLSConfig, security, options...)
}

var noTLSConfig *tls.Config = nil

func loadGlobalGPRCTLSCredentials(certifyClient *certify.Certify, security config.GlobalSecurityOption) (credentials.TransportCredentials, error) {
return loadGPRCTLSCredentialsWithOptions(nil, security, func(c *tls.Config) {
return loadGPRCTLSCredentialsWithOptions(noTLSConfig, security, func(c *tls.Config) {
c.GetCertificate = config.GetCertificate(certifyClient)
c.GetClientCertificate = certifyClient.GetClientCertificate
})
}

func loadManagerGPRCTLSCredentials(security config.GlobalSecurityOption) (credentials.TransportCredentials, error) {
return loadGPRCTLSCredentialsWithOptions(nil, security, func(c *tls.Config) {
return loadGPRCTLSCredentialsWithOptions(noTLSConfig, security, func(c *tls.Config) {
c.ClientAuth = tls.NoClientCert
})
}
Expand All @@ -418,11 +420,11 @@ func loadGPRCTLSCredentialsWithOptions(baseConfig *tls.Config, security config.G
certPool := x509.NewCertPool()

if security.CACert == "" {
return nil, fmt.Errorf("empty glocal CA's certificate")
return nil, errors.New("empty global CA's certificate")
}

if !certPool.AppendCertsFromPEM([]byte(security.CACert)) {
return nil, fmt.Errorf("failed to add global CA's certificate")
return nil, errors.New("failed to add global CA's certificate")
}

var tlsConfig *tls.Config
Expand Down

0 comments on commit 321f0ba

Please sign in to comment.