naming validation

This commit is contained in:
Asim Aslam
2021-12-01 15:37:54 +00:00
parent 0efaee0958
commit 52c42afd3a
3 changed files with 34 additions and 23 deletions

View File

@@ -102,6 +102,15 @@ func NewFunction(db db.DbService) *Function {
func (e *Function) Deploy(ctx context.Context, req *function.DeployRequest, rsp *function.DeployResponse) error {
log.Info("Received Function.Deploy request")
if len(req.Name) == 0 {
return errors.BadRequest("function.deploy", "Missing name")
}
if len(req.Repo) == 0 {
return errors.BadRequest("function.deploy", "Missing repo")
}
gitter := git.NewGitter(map[string]string{})
var err error
@@ -121,10 +130,12 @@ func (e *Function) Deploy(ctx context.Context, req *function.DeployRequest, rsp
if !ok {
tenantId = "micro"
}
multitenantPrefix := strings.Replace(tenantId, "/", "-", -1)
if req.Entrypoint == "" {
req.Entrypoint = req.Name
}
project := req.Project
if project == "" {
project = "default"

View File

@@ -133,12 +133,12 @@ type DeployRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// github url to repo
Repo string `protobuf:"bytes,1,opt,name=repo,proto3" json:"repo,omitempty"`
// optional subfolder path
Subfolder string `protobuf:"bytes,2,opt,name=subfolder,proto3" json:"subfolder,omitempty"`
// function name
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// github url to repo
Repo string `protobuf:"bytes,2,opt,name=repo,proto3" json:"repo,omitempty"`
// optional subfolder path
Subfolder string `protobuf:"bytes,3,opt,name=subfolder,proto3" json:"subfolder,omitempty"`
// entry point, ie. handler name in the source code
// if not provided, defaults to the name parameter
Entrypoint string `protobuf:"bytes,4,opt,name=entrypoint,proto3" json:"entrypoint,omitempty"`
@@ -190,6 +190,13 @@ func (*DeployRequest) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{2}
}
func (x *DeployRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *DeployRequest) GetRepo() string {
if x != nil {
return x.Repo
@@ -204,13 +211,6 @@ func (x *DeployRequest) GetSubfolder() string {
return ""
}
func (x *DeployRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *DeployRequest) GetEntrypoint() string {
if x != nil {
return x.Entrypoint
@@ -723,12 +723,12 @@ var file_proto_function_proto_rawDesc = []byte{
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52,
0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xa6, 0x02, 0x0a, 0x0d, 0x44, 0x65,
0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x72,
0x65, 0x70, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x12,
0x1c, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x09, 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18,
0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
0x12, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72,
0x65, 0x70, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65,
0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18,
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x70, 0x6f, 0x69, 0x6e,
0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x05, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x72,

View File

@@ -28,12 +28,12 @@ message CallResponse {
// Deploy a group of functions
message DeployRequest {
// github url to repo
string repo = 1;
// optional subfolder path
string subfolder = 2;
// function name
string name = 3;
string name = 1;
// github url to repo
string repo = 2;
// optional subfolder path
string subfolder = 3;
// entry point, ie. handler name in the source code
// if not provided, defaults to the name parameter
string entrypoint = 4;