Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(client/daemon): cleanup, and add noTLSConfig #2783

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading