-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add validation for search input
- Loading branch information
1 parent
afda40f
commit 6ce22de
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package consumergroup | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
|
||
"github.com/redhat-developer/app-services-cli/pkg/common/commonerr" | ||
"github.com/redhat-developer/app-services-cli/pkg/localize" | ||
) | ||
|
||
const ( | ||
legalSearchChars = "^[a-zA-Z0-9-]+$" | ||
) | ||
|
||
// Validator is a type for validating Kafka consumer group configuration values | ||
type Validator struct { | ||
Localizer localize.Localizer | ||
} | ||
|
||
func (v *Validator) ValidateSearchInput(val interface{}) error { | ||
search, ok := val.(string) | ||
if !ok { | ||
return commonerr.NewCastError(val, "string") | ||
} | ||
|
||
matched, _ := regexp.Match(legalSearchChars, []byte(search)) | ||
|
||
if matched { | ||
return nil | ||
} | ||
|
||
return errors.New(v.Localizer.MustLocalize("kafka.consumerGroup.list.error.illegalSearchValue", localize.NewEntry("Search", search))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters