-
Notifications
You must be signed in to change notification settings - Fork 5
feat (kafka): update newTLSConfig #499
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -322,21 +322,33 @@ func newTLSConfig(dir string) (*tls.Config, error) { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| tlsConfig := &tls.Config{} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| _, certFileErr := os.Stat(certFile) | ||||||||||||||||||||||||||||||||||
| _, keyFileErr := os.Stat(keyFile) | ||||||||||||||||||||||||||||||||||
| _, caFileErr := os.Stat(caFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if certFileErr != nil && keyFileErr != nil && caFileErr != nil { | ||||||||||||||||||||||||||||||||||
| return nil, errors.Join(certFileErr, keyFileErr, caFileErr) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+325
to
+331
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper error aggregation. The current implementation attempts to aggregate errors using - return nil, errors.Join(certFileErr, keyFileErr, caFileErr)
+ var multiErr *multierror.Error
+ multiErr = multierror.Append(multiErr, certFileErr, keyFileErr, caFileErr)
+ return nil, multiErr.ErrorOrNil()Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Load client cert | ||||||||||||||||||||||||||||||||||
| cert, err := tls.LoadX509KeyPair(certFile, keyFile) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||
| if certFileErr == nil && keyFileErr == nil { | ||||||||||||||||||||||||||||||||||
| cert, err := tls.LoadX509KeyPair(certFile, keyFile) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| tlsConfig.Certificates = []tls.Certificate{cert} | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| tlsConfig.Certificates = []tls.Certificate{cert} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Load CA cert | ||||||||||||||||||||||||||||||||||
| caCert, err := os.ReadFile(caFile) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||
| if caFileErr == nil { | ||||||||||||||||||||||||||||||||||
| caCert, err := os.ReadFile(caFile) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| caCertPool := x509.NewCertPool() | ||||||||||||||||||||||||||||||||||
| caCertPool.AppendCertsFromPEM(caCert) | ||||||||||||||||||||||||||||||||||
| tlsConfig.RootCAs = caCertPool | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| caCertPool := x509.NewCertPool() | ||||||||||||||||||||||||||||||||||
| caCertPool.AppendCertsFromPEM(caCert) | ||||||||||||||||||||||||||||||||||
| tlsConfig.RootCAs = caCertPool | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return tlsConfig, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine error handling to account for individual file errors.
Currently, the function returns an error if all files are missing. It might be more useful to handle cases where any of the files are missing individually, allowing for more specific error messages and handling.
Committable suggestion