diff --git a/clients/go/function/function.go b/clients/go/function/function.go index d0c12f5..6528524 100755 --- a/clients/go/function/function.go +++ b/clients/go/function/function.go @@ -34,6 +34,12 @@ func (t *FunctionService) Deploy(request *DeployRequest) (*DeployResponse, error return rsp, t.client.Call("function", "Deploy", request, rsp) } +// +func (t *FunctionService) Describe(request *DescribeRequest) (*DescribeResponse, error) { + rsp := &DescribeResponse{} + return rsp, t.client.Call("function", "Describe", request, rsp) +} + // List all the deployed functions func (t *FunctionService) List(request *ListRequest) (*ListResponse, error) { rsp := &ListResponse{} @@ -89,10 +95,24 @@ type DeployRequest struct { type DeployResponse struct { } +type DescribeRequest struct { + // The name of the function + Name string `json:"name"` + // Optional project name + Project string `json:"project"` +} + +type DescribeResponse struct { + Status string `json:"status"` + Timeout string `json:"timeout"` + UpdateTime string `json:"updateTime"` +} + type Func struct { // name of handler in source code Entrypoint string `json:"entrypoint"` // function name + // limitation: must be unique across projects Name string `json:"name"` // project of function, optional // defaults to literal "default" diff --git a/clients/ts/function/index.ts b/clients/ts/function/index.ts index b1cab09..23eee49 100755 --- a/clients/ts/function/index.ts +++ b/clients/ts/function/index.ts @@ -30,6 +30,14 @@ export class FunctionService { request ) as Promise; } + // + describe(request: DescribeRequest): Promise { + return this.client.call( + "function", + "Describe", + request + ) as Promise; + } // List all the deployed functions list(request: ListRequest): Promise { return this.client.call( @@ -87,10 +95,24 @@ export interface DeployRequest { export interface DeployResponse {} +export interface DescribeRequest { + // The name of the function + name?: string; + // Optional project name + project?: string; +} + +export interface DescribeResponse { + status?: string; + timeout?: string; + updateTime?: string; +} + export interface Func { // name of handler in source code entrypoint?: string; // function name + // limitation: must be unique across projects name?: string; // project of function, optional // defaults to literal "default" diff --git a/examples/db/update/go/updateARecord.go b/examples/db/update/go/updateARecord.go index d1cad90..4c7b7e9 100755 --- a/examples/db/update/go/updateARecord.go +++ b/examples/db/update/go/updateARecord.go @@ -11,8 +11,8 @@ func UpdateArecord() { dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) rsp, err := dbService.Update(&db.UpdateRequest{ Record: map[string]interface{}{ - "id": "1", "age": 43, + "id": "1", }, Table: "users", }) diff --git a/examples/function/describe/curl/describeFunctionStatus.sh b/examples/function/describe/curl/describeFunctionStatus.sh new file mode 100755 index 0000000..cb52197 --- /dev/null +++ b/examples/function/describe/curl/describeFunctionStatus.sh @@ -0,0 +1,7 @@ +curl "https://api.m3o.com/v1/function/Describe" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "name": "my-first-func", + "project": "tests" +}' \ No newline at end of file diff --git a/examples/function/describe/go/describeFunctionStatus.go b/examples/function/describe/go/describeFunctionStatus.go new file mode 100755 index 0000000..e60cc83 --- /dev/null +++ b/examples/function/describe/go/describeFunctionStatus.go @@ -0,0 +1,17 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/function" + "os" +) + +// +func DescribeFunctionStatus() { + functionService := function.NewFunctionService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := functionService.Describe(&function.DescribeRequest{ + Name: "my-first-func", + Project: "tests", + }) + fmt.Println(rsp, err) +} diff --git a/examples/function/describe/node/describeFunctionStatus.js b/examples/function/describe/node/describeFunctionStatus.js new file mode 100755 index 0000000..0d31396 --- /dev/null +++ b/examples/function/describe/node/describeFunctionStatus.js @@ -0,0 +1,13 @@ +import * as fx from "m3o/function"; + +// +async function DescribeFunctionStatus() { + let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN); + let rsp = await functionService.describe({ + name: "my-first-func", + project: "tests", + }); + console.log(rsp); +} + +await DescribeFunctionStatus(); diff --git a/function/examples.json b/function/examples.json index c398ed0..b061582 100644 --- a/function/examples.json +++ b/function/examples.json @@ -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" + } + } ] } diff --git a/function/handler/function.go b/function/handler/function.go index 0486dac..7559245 100644 --- a/function/handler/function.go +++ b/function/handler/function.go @@ -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 +} diff --git a/function/proto/function.pb.go b/function/proto/function.pb.go index 20243ac..160b2cf 100644 --- a/function/proto/function.pb.go +++ b/function/proto/function.pb.go @@ -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, }, diff --git a/function/proto/function.pb.micro.go b/function/proto/function.pb.micro.go index 53d2453..96ff878 100644 --- a/function/proto/function.pb.micro.go +++ b/function/proto/function.pb.micro.go @@ -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) +} diff --git a/function/proto/function.proto b/function/proto/function.proto index b23af02..8e6c453 100644 --- a/function/proto/function.proto +++ b/function/proto/function.proto @@ -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; +} \ No newline at end of file diff --git a/go.mod b/go.mod index 3806671..ed6b550 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,7 @@ require ( google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4 // indirect google.golang.org/protobuf v1.27.1 googlemaps.github.io/maps v1.3.1 + gopkg.in/yaml.v2 v2.3.0 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect gorm.io/datatypes v1.0.1 gorm.io/driver/postgres v1.0.8