-
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?
Conversation
WalkthroughThe recent changes in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- kafka/kafka.go (1 hunks)
Additional comments not posted (2)
kafka/kafka.go (2)
334-339: Proper conditional loading of client certificates.The conditional loading of the client certificates based on the file existence checks is implemented correctly. This ensures that the system does not attempt to load files that do not exist, which is a good practice for robust error handling.
343-350: Correct implementation of CA certificate loading.The loading of the CA certificate is also conditional and correctly checks if the CA file exists before attempting to read it. This is a crucial check that prevents runtime errors from attempting to read a non-existing file.
| if certFileErr != nil && keyFileErr != nil && caFileErr != nil { | ||
| return nil, errors.Join(certFileErr, keyFileErr, caFileErr) | ||
| } |
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.
- if certFileErr != nil && keyFileErr != nil && caFileErr != nil {
+ if certFileErr != nil || keyFileErr != nil || caFileErr != nil {
+ var errMsgs []string
+ if certFileErr != nil { errMsgs = append(errMsgs, "certificate file missing") }
+ if keyFileErr != nil { errMsgs = append(errMsgs, "key file missing") }
+ if caFileErr != nil { errMsgs = append(errMsgs, "CA file missing") }
+ return nil, fmt.Errorf("file error(s): %s", strings.Join(errMsgs, ", "))Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if certFileErr != nil && keyFileErr != nil && caFileErr != nil { | |
| return nil, errors.Join(certFileErr, keyFileErr, caFileErr) | |
| } | |
| if certFileErr != nil || keyFileErr != nil || caFileErr != nil { | |
| var errMsgs []string | |
| if certFileErr != nil { errMsgs = append(errMsgs, "certificate file missing") } | |
| if keyFileErr != nil { errMsgs = append(errMsgs, "key file missing") } | |
| if caFileErr != nil { errMsgs = append(errMsgs, "CA file missing") } | |
| return nil, fmt.Errorf("file error(s): %s", strings.Join(errMsgs, ", ")) | |
| } |
| _, 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) | ||
| } |
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.
Ensure proper error aggregation.
The current implementation attempts to aggregate errors using errors.Join, which is not a standard function in Go's errors package. Consider using a custom error aggregation approach or a package like github.com/hashicorp/go-multierror for error handling.
- return nil, errors.Join(certFileErr, keyFileErr, caFileErr)
+ var multiErr *multierror.Error
+ multiErr = multierror.Append(multiErr, certFileErr, keyFileErr, caFileErr)
+ return nil, multiErr.ErrorOrNil()Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| _, 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) | |
| } | |
| _, certFileErr := os.Stat(certFile) | |
| _, keyFileErr := os.Stat(keyFile) | |
| _, caFileErr := os.Stat(caFile) | |
| if certFileErr != nil && keyFileErr != nil && caFileErr != nil { | |
| var multiErr *multierror.Error | |
| multiErr = multierror.Append(multiErr, certFileErr, keyFileErr, caFileErr) | |
| return nil, multiErr.ErrorOrNil() | |
| } |
ri-nat
left a comment
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.
🤟
d04d9b1 to
9c32558
Compare
Summary by CodeRabbit