Skip to content

Commit

Permalink
feat: add NQN validation
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 3, 2023
1 parent 4b57f4a commit e5a0cfe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/frontend/nvme_subsystem_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package frontend

import (
"fmt"
"regexp"

"go.einride.tech/aip/fieldbehavior"
"go.einride.tech/aip/resourceid"
Expand Down Expand Up @@ -43,7 +44,12 @@ func (s *Server) validateCreateNvmeSubsystemRequest(in *pb.CreateNvmeSubsystemRe
msg := fmt.Sprintf("ModelNumber value (%s) is too long, have to be between 1 and 40", in.NvmeSubsystem.Spec.ModelNumber)
return status.Errorf(codes.InvalidArgument, msg)
}
// TODO: check in.NvmeSubsystem.Spec.Nqn validity with regexp
// check if the NQN matches the pattern
regex := regexp.MustCompile(`^nqn\.[0-9]{4}-[0-9]{2}(\.[a-zA-Z0-9]+)+(:[a-zA-Z0-9-.]+)+$`)
if !regex.MatchString(in.NvmeSubsystem.Spec.Nqn) {
msg := fmt.Sprintf("NQN value (%s) does not match pattern", in.NvmeSubsystem.Spec.Nqn)
return status.Errorf(codes.InvalidArgument, msg)
}
return nil
}

Expand Down

0 comments on commit e5a0cfe

Please sign in to comment.