From b38f125ded27e38d5e148803ca39d7f573efc3d9 Mon Sep 17 00:00:00 2001 From: hiteshwani29 Date: Mon, 27 Feb 2023 17:50:18 +0530 Subject: [PATCH] moved regex to constant Signed-off-by: hiteshwani29 --- pkg/common/constants.go | 5 +++++ server/project.go | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 2d55d9ef..cdfdaf74 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -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])?$` +) diff --git a/server/project.go b/server/project.go index cdc2b6df..ce2d96b6 100644 --- a/server/project.go +++ b/server/project.go @@ -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" @@ -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") }