function: Describe + Delete endpoints (#230)

This commit is contained in:
Janos Dobronszki
2021-10-14 10:29:18 +01:00
committed by GitHub
parent a67ecc0e36
commit e6e0b1a84d
12 changed files with 406 additions and 63 deletions

View File

@@ -54,5 +54,19 @@
},
"response": {}
}
],
"describe": [
{
"title": "Describe function status",
"request": {
"project": "tests",
"name": "my-first-func"
},
"response": {
"updateTime": "2021-10-08T10:17:34.914Z",
"status": "ACTIVE",
"timeout": "60s"
}
}
]
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/micro/micro/v3/service/config"
log "github.com/micro/micro/v3/service/logger"
"gopkg.in/yaml.v2"
"github.com/micro/micro/v3/service/runtime/source/git"
@@ -224,7 +225,31 @@ func (e *Function) Call(ctx context.Context, req *function.CallRequest, rsp *fun
func (e *Function) Delete(ctx context.Context, req *function.DeleteRequest, rsp *function.DeleteResponse) error {
log.Info("Received Function.Delete request")
return fmt.Errorf("not implemented yet")
tenantId, ok := tenant.FromContext(ctx)
if !ok {
tenantId = "micro"
}
multitenantPrefix := strings.Replace(tenantId, "/", "-", -1)
project := req.Project
if project == "" {
project = "default"
}
cmd := exec.Command("gcloud", "functions", "delete", "--project", e.project, "--region", "europe-west1", multitenantPrefix+"-"+req.Name)
outp, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Errorf(string(outp)))
return err
}
id := fmt.Sprintf("%v-%v-%v", tenantId, project, req.Name)
_, err = e.db.Delete(ctx, &db.DeleteRequest{
Table: "functions",
Id: id,
})
return err
}
func (e *Function) List(ctx context.Context, req *function.ListRequest, rsp *function.ListResponse) error {
@@ -280,3 +305,32 @@ func (e *Function) List(ctx context.Context, req *function.ListRequest, rsp *fun
}
return nil
}
func (e *Function) Describe(ctx context.Context, req *function.DescribeRequest, rsp *function.DescribeResponse) error {
tenantId, ok := tenant.FromContext(ctx)
if !ok {
tenantId = "micro"
}
project := req.Project
if project == "" {
project = "default"
}
multitenantPrefix := strings.Replace(tenantId, "/", "-", -1)
cmd := exec.Command("gcloud", "functions", "describe", "--region", "europe-west1", "--project", e.project, multitenantPrefix+"-"+req.Name)
outp, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Errorf(string(outp)))
return fmt.Errorf("function does not exist")
}
log.Info(string(outp))
m := map[string]interface{}{}
err = yaml.Unmarshal(outp, m)
if err != nil {
return err
}
rsp.Status = m["status"].(string)
rsp.Timeout = m["timeout"].(string)
rsp.UpdateTime = m["updateTime"].(string)
return nil
}

View File

@@ -327,6 +327,7 @@ type Func struct {
// used to namespace functions
Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"`
// function name
// limitation: must be unique across projects
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
// name of handler in source code
Entrypoint string `protobuf:"bytes,3,opt,name=entrypoint,proto3" json:"entrypoint,omitempty"`
@@ -343,7 +344,7 @@ type Func struct {
// go111, go113, go116
// python37, python38, python39
Runtime string `protobuf:"bytes,6,opt,name=runtime,proto3" json:"runtime,omitempty"`
// eg. ACTIVE etc
// eg. ACTIVE, DEPLOY_IN_PROGRESS, OFFLINE etc
Status string `protobuf:"bytes,7,opt,name=status,proto3" json:"status,omitempty"`
}
@@ -482,10 +483,10 @@ type DeleteRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Optional project name
Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"`
// The name of the function
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// Optional project name
Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"`
}
func (x *DeleteRequest) Reset() {
@@ -520,16 +521,16 @@ func (*DeleteRequest) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{7}
}
func (x *DeleteRequest) GetProject() string {
func (x *DeleteRequest) GetName() string {
if x != nil {
return x.Project
return x.Name
}
return ""
}
func (x *DeleteRequest) GetName() string {
func (x *DeleteRequest) GetProject() string {
if x != nil {
return x.Name
return x.Project
}
return ""
}
@@ -572,6 +573,126 @@ func (*DeleteResponse) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{8}
}
type DescribeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// The name of the function
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// Optional project name
Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"`
}
func (x *DescribeRequest) Reset() {
*x = DescribeRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_function_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DescribeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DescribeRequest) ProtoMessage() {}
func (x *DescribeRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_function_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DescribeRequest.ProtoReflect.Descriptor instead.
func (*DescribeRequest) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{9}
}
func (x *DescribeRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *DescribeRequest) GetProject() string {
if x != nil {
return x.Project
}
return ""
}
type DescribeResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UpdateTime string `protobuf:"bytes,1,opt,name=updateTime,proto3" json:"updateTime,omitempty"`
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"`
Timeout string `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"`
}
func (x *DescribeResponse) Reset() {
*x = DescribeResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_function_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DescribeResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DescribeResponse) ProtoMessage() {}
func (x *DescribeResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_function_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DescribeResponse.ProtoReflect.Descriptor instead.
func (*DescribeResponse) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{10}
}
func (x *DescribeResponse) GetUpdateTime() string {
if x != nil {
return x.UpdateTime
}
return ""
}
func (x *DescribeResponse) GetStatus() string {
if x != nil {
return x.Status
}
return ""
}
func (x *DescribeResponse) GetTimeout() string {
if x != nil {
return x.Timeout
}
return ""
}
var File_proto_function_proto protoreflect.FileDescriptor
var file_proto_function_proto_rawDesc = []byte{
@@ -619,29 +740,43 @@ var file_proto_function_proto_rawDesc = []byte{
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e,
0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x46, 0x75, 0x6e, 0x63, 0x52, 0x09,
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x3d, 0x0a, 0x0d, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72,
0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f,
0x6a, 0x65, 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xfa, 0x01, 0x0a, 0x08, 0x46,
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12,
0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44,
0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
0x37, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16,
0x65, 0x74, 0x65, 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, 0x18,
0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3f, 0x0a, 0x0f, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 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, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x64, 0x0a, 0x10, 0x44,
0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x1e, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12,
0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f,
0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75,
0x74, 0x32, 0xbf, 0x02, 0x0a, 0x08, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37,
0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x70, 0x6c, 0x6f,
0x79, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70,
0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75, 0x6e,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15,
0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75,
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x12, 0x5a, 0x10, 0x2e, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x3b, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
0x3d, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e, 0x63,
0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43,
0x0a, 0x08, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x19, 0x2e, 0x66, 0x75, 0x6e,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x42, 0x12, 0x5a, 0x10, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x66,
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -656,36 +791,40 @@ func file_proto_function_proto_rawDescGZIP() []byte {
return file_proto_function_proto_rawDescData
}
var file_proto_function_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_proto_function_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_proto_function_proto_goTypes = []interface{}{
(*CallRequest)(nil), // 0: function.CallRequest
(*CallResponse)(nil), // 1: function.CallResponse
(*DeployRequest)(nil), // 2: function.DeployRequest
(*DeployResponse)(nil), // 3: function.DeployResponse
(*ListRequest)(nil), // 4: function.ListRequest
(*Func)(nil), // 5: function.Func
(*ListResponse)(nil), // 6: function.ListResponse
(*DeleteRequest)(nil), // 7: function.DeleteRequest
(*DeleteResponse)(nil), // 8: function.DeleteResponse
(*_struct.Struct)(nil), // 9: google.protobuf.Struct
(*CallRequest)(nil), // 0: function.CallRequest
(*CallResponse)(nil), // 1: function.CallResponse
(*DeployRequest)(nil), // 2: function.DeployRequest
(*DeployResponse)(nil), // 3: function.DeployResponse
(*ListRequest)(nil), // 4: function.ListRequest
(*Func)(nil), // 5: function.Func
(*ListResponse)(nil), // 6: function.ListResponse
(*DeleteRequest)(nil), // 7: function.DeleteRequest
(*DeleteResponse)(nil), // 8: function.DeleteResponse
(*DescribeRequest)(nil), // 9: function.DescribeRequest
(*DescribeResponse)(nil), // 10: function.DescribeResponse
(*_struct.Struct)(nil), // 11: google.protobuf.Struct
}
var file_proto_function_proto_depIdxs = []int32{
9, // 0: function.CallRequest.request:type_name -> google.protobuf.Struct
9, // 1: function.CallResponse.response:type_name -> google.protobuf.Struct
5, // 2: function.ListResponse.functions:type_name -> function.Func
0, // 3: function.Function.Call:input_type -> function.CallRequest
2, // 4: function.Function.Deploy:input_type -> function.DeployRequest
4, // 5: function.Function.List:input_type -> function.ListRequest
7, // 6: function.Function.Delete:input_type -> function.DeleteRequest
1, // 7: function.Function.Call:output_type -> function.CallResponse
3, // 8: function.Function.Deploy:output_type -> function.DeployResponse
6, // 9: function.Function.List:output_type -> function.ListResponse
8, // 10: function.Function.Delete:output_type -> function.DeleteResponse
7, // [7:11] is the sub-list for method output_type
3, // [3:7] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
11, // 0: function.CallRequest.request:type_name -> google.protobuf.Struct
11, // 1: function.CallResponse.response:type_name -> google.protobuf.Struct
5, // 2: function.ListResponse.functions:type_name -> function.Func
0, // 3: function.Function.Call:input_type -> function.CallRequest
2, // 4: function.Function.Deploy:input_type -> function.DeployRequest
4, // 5: function.Function.List:input_type -> function.ListRequest
7, // 6: function.Function.Delete:input_type -> function.DeleteRequest
9, // 7: function.Function.Describe:input_type -> function.DescribeRequest
1, // 8: function.Function.Call:output_type -> function.CallResponse
3, // 9: function.Function.Deploy:output_type -> function.DeployResponse
6, // 10: function.Function.List:output_type -> function.ListResponse
8, // 11: function.Function.Delete:output_type -> function.DeleteResponse
10, // 12: function.Function.Describe:output_type -> function.DescribeResponse
8, // [8:13] is the sub-list for method output_type
3, // [3:8] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
}
func init() { file_proto_function_proto_init() }
@@ -802,6 +941,30 @@ func file_proto_function_proto_init() {
return nil
}
}
file_proto_function_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DescribeRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_function_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DescribeResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -809,7 +972,7 @@ func file_proto_function_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_function_proto_rawDesc,
NumEnums: 0,
NumMessages: 9,
NumMessages: 11,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -47,6 +47,7 @@ type FunctionService interface {
Deploy(ctx context.Context, in *DeployRequest, opts ...client.CallOption) (*DeployResponse, error)
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
Describe(ctx context.Context, in *DescribeRequest, opts ...client.CallOption) (*DescribeResponse, error)
}
type functionService struct {
@@ -101,6 +102,16 @@ func (c *functionService) Delete(ctx context.Context, in *DeleteRequest, opts ..
return out, nil
}
func (c *functionService) Describe(ctx context.Context, in *DescribeRequest, opts ...client.CallOption) (*DescribeResponse, error) {
req := c.c.NewRequest(c.name, "Function.Describe", in)
out := new(DescribeResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Function service
type FunctionHandler interface {
@@ -108,6 +119,7 @@ type FunctionHandler interface {
Deploy(context.Context, *DeployRequest, *DeployResponse) error
List(context.Context, *ListRequest, *ListResponse) error
Delete(context.Context, *DeleteRequest, *DeleteResponse) error
Describe(context.Context, *DescribeRequest, *DescribeResponse) error
}
func RegisterFunctionHandler(s server.Server, hdlr FunctionHandler, opts ...server.HandlerOption) error {
@@ -116,6 +128,7 @@ func RegisterFunctionHandler(s server.Server, hdlr FunctionHandler, opts ...serv
Deploy(ctx context.Context, in *DeployRequest, out *DeployResponse) error
List(ctx context.Context, in *ListRequest, out *ListResponse) error
Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
Describe(ctx context.Context, in *DescribeRequest, out *DescribeResponse) error
}
type Function struct {
function
@@ -143,3 +156,7 @@ func (h *functionHandler) List(ctx context.Context, in *ListRequest, out *ListRe
func (h *functionHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
return h.FunctionHandler.Delete(ctx, in, out)
}
func (h *functionHandler) Describe(ctx context.Context, in *DescribeRequest, out *DescribeResponse) error {
return h.FunctionHandler.Describe(ctx, in, out)
}

View File

@@ -10,6 +10,7 @@ service Function {
rpc Deploy(DeployRequest) returns (DeployResponse) {}
rpc List(ListRequest) returns (ListResponse) {}
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
rpc Describe(DescribeRequest) returns (DescribeResponse) {}
}
// Call a function by name
@@ -65,6 +66,7 @@ message Func {
// used to namespace functions
string project = 1;
// function name
// limitation: must be unique across projects
string name = 2;
// name of handler in source code
string entrypoint = 3;
@@ -92,12 +94,25 @@ message ListResponse {
// Delete a function by name
message DeleteRequest {
// Optional project name
string project = 1;
// The name of the function
string name = 2;
string name = 1;
// Optional project name
string project = 2;
}
message DeleteResponse {
}
message DescribeRequest {
// The name of the function
string name = 1;
// Optional project name
string project = 2;
}
message DescribeResponse {
string updateTime = 1;
string status = 2;
string timeout = 3;
}