Fix SonarQube string literal duplication issues#1499
Fix SonarQube string literal duplication issues#1499PabloHiro wants to merge 1 commit intoansible:develfrom
Conversation
caf6208 to
a16f156
Compare
Extract repeated string literals into named constants to improve code maintainability and reduce duplication across multiple files: - pkg/certificates/cli.go - pkg/netceptor/external_backend.go - pkg/netceptor/netceptor.go - pkg/workceptor/command.go - pkg/workceptor/controlsvc.go - pkg/workceptor/kubernetes.go - pkg/workceptor/remote_work.go Assisted-by: Claude <noreply@anthropic.com>
a16f156 to
aba4339
Compare
|
arrestle
left a comment
There was a problem hiding this comment.
Hi Pablo,
I noticed we can improve our error handling in this PR, I'm ok with flagging it in a new Jira if it these changes cause code coverage issues, however., so I'm marking it as Approved in the hopes you'll either enhance the message, or log a jira to handle it later, since it's a fairly minor change.
Again, thanks for being our SonarQube liason!
| func (s *Netceptor) AddWorkCommand(command string, secure bool) error { | ||
| if command == "" { | ||
| return fmt.Errorf("must provide a name") | ||
| return errors.New(errMustProvideName) |
There was a problem hiding this comment.
Hmmm. I dislike that all these error messages are identical. Can we take this opportunity to mention which name is missing?
| return errors.New(errMustProvideName) | |
| return errors.fmt(errMustProvideName,"Work Command") |
| func (s *Netceptor) SetServerTLSConfig(name string, config *tls.Config) error { | ||
| if name == "" { | ||
| return fmt.Errorf("must provide a name") | ||
| return errors.New(errMustProvideName) |
There was a problem hiding this comment.
| return errors.New(errMustProvideName) | |
| return errors.fmt(errMustProvideName,"Server TLS Config") |
| // defaultMaxConnectionIdleTime is the maximum time a connection can go without data before we consider it failed. | ||
| const defaultMaxConnectionIdleTime = 2*defaultRouteUpdateTime + 1*time.Second | ||
|
|
||
| const errMustProvideName = "must provide a name" |
There was a problem hiding this comment.
| const errMustProvideName = "must provide a name" | |
| const errMustProvideName = "must provide a %s name" |
|
|
||
| const errMsgStatusFileUpdate = "Error updating status file %s: %s" | ||
| const ( | ||
| errMsgStatusFileUpdate = "Error updating status file %s: %s" |
There was a problem hiding this comment.
Because I see this error message has parameters.


AAP-60060
Summary
This PR addresses SonarQube string literal duplication issues by extracting repeated string literals into named constants.
Changes
Files Modified
pkg/certificates/cli.gopkg/netceptor/external_backend.gopkg/netceptor/netceptor.gopkg/workceptor/command.gopkg/workceptor/controlsvc.gopkg/workceptor/kubernetes.gopkg/workceptor/remote_work.goTest Plan