Skip to content

Commit 22ad702

Browse files
committed
config: Fix pattern matching for tags
We have different rules for configuring tag names than app names. This change pulls in the regular expression used by our backend to validate tag names. This will allow users to configure a device to follow a tag like `foo.bar` which was already possible, but fioctl would not allow. Signed-off-by: Andy Doan <andy@foundries.io>
1 parent 9f78dba commit 22ad702

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

subcommands/common_config.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ const (
2525
FIO_TOML_ONCHANGED = "/usr/share/fioconfig/handlers/aktualizr-toml-update"
2626
)
2727

28+
var (
29+
// Validate the inputs: Must be alphanumeric, a dash, underscore, or comma
30+
reAppPattern = regexp.MustCompile(`^[a-zA-Z0-9-_,]+$`)
31+
32+
// Validate the inputs: Must be alphanumeric, a underscore, dash, or dot
33+
reTagPattern = regexp.MustCompile(`^[a-zA-Z0-9_\-\.\+]+$`)
34+
)
35+
2836
type SetConfigOptions struct {
2937
Reason string
3038
FileArgs []string
@@ -320,14 +328,11 @@ func loadSotaConfig(dcl *client.DeviceConfigList) (sota *toml.Tree, err error) {
320328
}
321329

322330
func validateUpdateArgs(opts *SetUpdatesConfigOptions) error {
323-
// Validate the inputs: Must be alphanumeric, a dash, underscore, or comma
324-
pattern := `^[a-zA-Z0-9-_,]+$`
325-
re := regexp.MustCompile(pattern)
326-
if len(opts.UpdateApps) > 0 && !re.MatchString(opts.UpdateApps) {
327-
return fmt.Errorf("Invalid value for apps: %s\nMust be %s", opts.UpdateApps, pattern)
331+
if len(opts.UpdateApps) > 0 && !reAppPattern.MatchString(opts.UpdateApps) {
332+
return fmt.Errorf("Invalid value for apps: %s\nMust be %s", opts.UpdateApps, reAppPattern.String())
328333
}
329-
if len(opts.UpdateTag) > 0 && !re.MatchString(opts.UpdateTag) {
330-
return fmt.Errorf("Invalid value for tag: %s\nMust be %s", opts.UpdateTag, pattern)
334+
if len(opts.UpdateTag) > 0 && !reTagPattern.MatchString(opts.UpdateTag) {
335+
return fmt.Errorf("Invalid value for tag: %s\nMust be %s", opts.UpdateTag, reTagPattern.String())
331336
}
332337
return nil
333338
}

0 commit comments

Comments
 (0)