File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed
Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ Invalid Kafka instance name. Valid names must satisfy the following conditions:
1111[kafka .validation .name .error .lengthError ]
1212one = ' Kafka instance name must be between 1 and 32 characters'
1313
14+ [kafka .validation .error .invalidSearchValue ]
15+ description = ' Error message when invalid search input is provided'
16+ one = '''
17+ Illegal search value "{{.Search}}", search input must satisfy the following conditions:
18+
19+ - must be of 1 or more characters
20+ - must only consist of alphanumeric characters, '-', '_' and '%'
21+ '''
1422
1523[kafka .common .error .notFoundErrorById ]
1624one = ' Kafka instance with ID "{{.ID}}" not found'
Original file line number Diff line number Diff line change 99 kasclient "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/kas/client"
1010 flagutil "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmdutil/flags"
1111 "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/iostreams"
12+ "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/kafka"
1213
1314 "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/dump"
1415
@@ -101,6 +102,11 @@ func runList(opts *options) error {
101102 a = a .Size (strconv .Itoa (opts .limit ))
102103
103104 if opts .search != "" {
105+
106+ if err = kafka .ValidateSearchInput (opts .search ); err != nil {
107+ return err
108+ }
109+
104110 logger .Debug (localizer .MustLocalize (& localizer.Config {
105111 MessageID : "kafka.list.log.debug.filteringKafkaList" ,
106112 TemplateData : map [string ]interface {}{
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import (
1111)
1212
1313var (
14- validNameRegexp = regexp .MustCompile (`^[a-z]([-a-z0-9]*[a-z0-9])?$` )
14+ validNameRegexp = regexp .MustCompile (`^[a-z]([-a-z0-9]*[a-z0-9])?$` )
15+ validSearchRegexp = regexp .MustCompile (`^([a-zA-Z0-9-_%]*[a-zA-Z0-9-_%])?$` )
1516)
1617
1718// ValidateName validates the proposed name of a Kafka instance
@@ -69,3 +70,30 @@ func TransformKafkaRequest(kafka *kasclient.KafkaRequest) *kasclient.KafkaReques
6970
7071 return kafka
7172}
73+
74+ func ValidateSearchInput (val interface {}) error {
75+ search , ok := val .(string )
76+
77+ if ! ok {
78+ return errors .New (localizer .MustLocalize (& localizer.Config {
79+ MessageID : "common.error.castError" ,
80+ TemplateData : map [string ]interface {}{
81+ "Value" : val ,
82+ "Type" : "string" ,
83+ },
84+ }))
85+ }
86+
87+ matched := validSearchRegexp .MatchString (search )
88+
89+ if matched {
90+ return nil
91+ }
92+
93+ return errors .New (localizer .MustLocalize (& localizer.Config {
94+ MessageID : "kafka.validation.error.invalidSearchValue" ,
95+ TemplateData : map [string ]interface {}{
96+ "Search" : search ,
97+ },
98+ }))
99+ }
You can’t perform that action at this time.
0 commit comments