Skip to content
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

add validation rule for contents name #31

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/operator/server/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
package v1

import (
"errors"
"fmt"
"reflect"
"regexp"

sinkV1 "github.com/naver/lobster/pkg/operator/api/v1"
)

var invalidNameCharacter = regexp.MustCompile(`[<>:"/\\|?*]`)

type SinkContents interface {
GetNamespace() string
GetName() string
Expand Down Expand Up @@ -83,6 +87,10 @@ func ValidateContent(content interface{}) error {
return fmt.Errorf("duplicated name is not allowed '%s'", name)
}

if err := hasValidName(name); err != nil {
return err
}

existence[name] = true
}

Expand Down Expand Up @@ -124,3 +132,11 @@ func SearchContentToDelete(content interface{}, targetName string) int {

return -1
}

func hasValidName(name string) error {
if invalidNameCharacter.MatchString(name) {
return errors.New("invalid characters(<>:\"/\\) are included in name")
}

return nil
}
Loading