@@ -3,6 +3,8 @@ package server
33import (
44 "context"
55 "fmt"
6+ "math"
7+ "strings"
68 "time"
79
810 sdcpb "github.com/iptecharch/sdc-protos/sdcpb"
@@ -52,7 +54,11 @@ func (s *Server) GetDataStore(ctx context.Context, req *sdcpb.GetDataStoreReques
5254func (s * Server ) CreateDataStore (ctx context.Context , req * sdcpb.CreateDataStoreRequest ) (* sdcpb.CreateDataStoreResponse , error ) {
5355 log .Debugf ("Received CreateDataStoreRequest: %v" , req )
5456 name := req .GetName ()
55- if name == "" {
57+ lName := len (name )
58+ if lName == 0 {
59+ return nil , status .Error (codes .InvalidArgument , "missing datastore name attribute" )
60+ }
61+ if lName > math .MaxUint16 {
5662 return nil , status .Error (codes .InvalidArgument , "missing datastore name attribute" )
5763 }
5864 switch {
@@ -66,6 +72,17 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore
6672 }
6773 switch req .GetDatastore ().GetType () {
6874 case sdcpb .Type_CANDIDATE :
75+ owner := req .GetDatastore ().GetOwner ()
76+ lOwner := len (owner )
77+ if lOwner == 0 {
78+ return nil , status .Error (codes .InvalidArgument , "missing owner name attribute" )
79+ }
80+ if lOwner > math .MaxUint16 {
81+ return nil , status .Errorf (codes .InvalidArgument , "owner name too long(%d>%d)" , lOwner , math .MaxUint16 )
82+ }
83+ if strings .HasPrefix (owner , "__" ) {
84+ return nil , status .Error (codes .InvalidArgument , "owner name cannot start with `__`" )
85+ }
6986 err := ds .CreateCandidate (ctx , req .GetDatastore ())
7087 if err != nil {
7188 return nil , status .Errorf (codes .Internal , "%v" , err )
@@ -310,13 +327,5 @@ func (s *Server) datastoreToRsp(ctx context.Context, ds *datastore.Datastore) (*
310327 Vendor : ds .Config ().Schema .Vendor ,
311328 Version : ds .Config ().Schema .Version ,
312329 }
313- // for _, cand := range cands {
314- // rsp.Datastore = append(rsp.Datastore,
315- // &sdcpb.DataStore{
316- // Type: *sdcpb.Type_CANDIDATE.Enum(),
317- // Name: cand,
318- // },
319- // )
320- // }
321330 return rsp , nil
322331}
0 commit comments