Skip to content

Commit

Permalink
moved regex to constant
Browse files Browse the repository at this point in the history
Signed-off-by: hiteshwani29 <hiteshwani29@gmail.com>
  • Loading branch information
hiteshwani29 committed Feb 27, 2023
1 parent fb2db0a commit b38f125
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ const (

var SessionDataKey contextKey
var SessionInternalKey contextKey

//Regex
const (
PROJECT_NAME_REGEX = `^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$`
)
5 changes: 3 additions & 2 deletions server/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/paralus/paralus/pkg/common"
"github.com/paralus/paralus/pkg/service"
systemrpc "github.com/paralus/paralus/proto/rpc/system"
v3 "github.com/paralus/paralus/proto/types/commonpb/v3"
Expand Down Expand Up @@ -34,8 +35,8 @@ func updateProjectStatus(req *systempbv3.Project, resp *systempbv3.Project, err
}

func (s *projectServer) CreateProject(ctx context.Context, req *systempbv3.Project) (*systempbv3.Project, error) {
regexProject := `^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$`
err, matched := MatchStringToRegx(req.Metadata.GetName(), regexProject)

err, matched := MatchStringToRegx(req.Metadata.GetName(), common.PROJECT_NAME_REGEX)
if err != nil || !matched {
return nil, fmt.Errorf("invalid project name. Valid project name must be like demo-proj-test3")
}
Expand Down

0 comments on commit b38f125

Please sign in to comment.