add entire function description on describe (#247)

This commit is contained in:
Asim Aslam
2021-10-26 17:28:42 +01:00
committed by GitHub
parent 7cbd26b388
commit 40112efb61
4 changed files with 104 additions and 51 deletions

View File

@@ -63,6 +63,15 @@
"name": "my-first-func" "name": "my-first-func"
}, },
"response": { "response": {
"function": {
"project": "a",
"name": "test4",
"entrypoint": "helloworld",
"repo": "github.com/m3o/nodejs-function-example",
"subfolder": "",
"runtime": "nodejs14",
"status": "ACTIVE"
},
"updateTime": "2021-10-08T10:17:34.914Z", "updateTime": "2021-10-08T10:17:34.914Z",
"status": "ACTIVE", "status": "ACTIVE",
"timeout": "60s" "timeout": "60s"

View File

@@ -327,11 +327,22 @@ func (e *Function) Describe(ctx context.Context, req *function.DescribeRequest,
if !ok { if !ok {
tenantId = "micro" tenantId = "micro"
} }
project := req.Project project := req.Project
if project == "" { if project == "" {
project = "default" project = "default"
} }
multitenantPrefix := strings.Replace(tenantId, "/", "-", -1) multitenantPrefix := strings.Replace(tenantId, "/", "-", -1)
id := fmt.Sprintf("%v-%v-%v", tenantId, project, req.Name)
readRsp, err := e.db.Read(ctx, &db.ReadRequest{
Table: "functions",
Id: id,
})
if err != nil {
return err
}
cmd := exec.Command("gcloud", "functions", "describe", "--region", "europe-west1", "--project", e.project, multitenantPrefix+"-"+req.Name) cmd := exec.Command("gcloud", "functions", "describe", "--region", "europe-west1", "--project", e.project, multitenantPrefix+"-"+req.Name)
outp, err := cmd.CombinedOutput() outp, err := cmd.CombinedOutput()
@@ -339,14 +350,29 @@ func (e *Function) Describe(ctx context.Context, req *function.DescribeRequest,
log.Error(fmt.Errorf(string(outp))) log.Error(fmt.Errorf(string(outp)))
return fmt.Errorf("function does not exist") return fmt.Errorf("function does not exist")
} }
log.Info(string(outp)) log.Info(string(outp))
m := map[string]interface{}{} m := map[string]interface{}{}
err = yaml.Unmarshal(outp, m) err = yaml.Unmarshal(outp, m)
if err != nil { if err != nil {
return err return err
} }
if len(readRsp.Records) > 0 {
m := readRsp.Records[0].AsMap()
bs, _ := json.Marshal(m)
f := &function.Func{}
err = json.Unmarshal(bs, f)
if err != nil {
return err
}
rsp.Function = f
}
// set describe info
rsp.Status = m["status"].(string) rsp.Status = m["status"].(string)
rsp.Timeout = m["timeout"].(string) rsp.Timeout = m["timeout"].(string)
rsp.UpdateTime = m["updateTime"].(string) rsp.UpdateTime = m["updateTime"].(string)
return nil return nil
} }

View File

@@ -154,7 +154,7 @@ type DeployRequest struct {
// go111, go113, go116 // go111, go113, go116
// python37, python38, python39 // python37, python38, python39
Runtime string `protobuf:"bytes,6,opt,name=runtime,proto3" json:"runtime,omitempty"` Runtime string `protobuf:"bytes,6,opt,name=runtime,proto3" json:"runtime,omitempty"`
// environment variables to pass in // environment variables to pass in at runtime
EnvVars map[string]string `protobuf:"bytes,7,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` EnvVars map[string]string `protobuf:"bytes,7,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
} }
@@ -645,9 +645,14 @@ type DescribeResponse struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
UpdateTime string `protobuf:"bytes,1,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // The function requested
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` Function *Func `protobuf:"bytes,1,opt,name=function,proto3" json:"function,omitempty"`
Timeout string `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` // The time at which the function was updated
UpdateTime string `protobuf:"bytes,2,opt,name=updateTime,proto3" json:"updateTime,omitempty"`
// The last known status of the function
Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
// The timeout for requests to the function
Timeout string `protobuf:"bytes,4,opt,name=timeout,proto3" json:"timeout,omitempty"`
} }
func (x *DescribeResponse) Reset() { func (x *DescribeResponse) Reset() {
@@ -682,6 +687,13 @@ func (*DescribeResponse) Descriptor() ([]byte, []int) {
return file_proto_function_proto_rawDescGZIP(), []int{10} return file_proto_function_proto_rawDescGZIP(), []int{10}
} }
func (x *DescribeResponse) GetFunction() *Func {
if x != nil {
return x.Function
}
return nil
}
func (x *DescribeResponse) GetUpdateTime() string { func (x *DescribeResponse) GetUpdateTime() string {
if x != nil { if x != nil {
return x.UpdateTime return x.UpdateTime
@@ -766,35 +778,38 @@ var file_proto_function_proto_rawDesc = []byte{
0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 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, 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, 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, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x90, 0x01, 0x0a, 0x10, 0x44, 0x65, 0x73,
0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a,
0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x0e, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x46, 0x75, 0x6e, 0x63, 0x52,
0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x75, 0x70, 0x64,
0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x75,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x32, 0xbf, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61,
0x02, 0x0a, 0x08, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x04, 0x43, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75,
0x61, 0x6c, 0x6c, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x04, 0x20, 0x01,
0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x28, 0x09, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x32, 0xbf, 0x02, 0x0a, 0x08,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c,
0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x12, 0x17, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c,
0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x12, 0x17, 0x2e, 0x66, 0x75,
0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71,
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e,
0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x12, 0x37, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74,
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x69, 0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x6e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52,
0x18, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x06, 0x44, 0x65, 0x6c,
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x08, 0x44, 0x65, 0x74, 0x65, 0x12, 0x17, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44,
0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x19, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x66,
0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x44, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x08, 0x44, 0x65, 0x73, 0x63,
0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x72, 0x69, 0x62, 0x65, 0x12, 0x19, 0x2e, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e,
0x42, 0x12, 0x5a, 0x10, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x66, 0x75, 0x6e, 0x63, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@@ -830,21 +845,22 @@ var file_proto_function_proto_depIdxs = []int32{
12, // 1: function.CallResponse.response:type_name -> google.protobuf.Struct 12, // 1: function.CallResponse.response:type_name -> google.protobuf.Struct
11, // 2: function.DeployRequest.env_vars:type_name -> function.DeployRequest.EnvVarsEntry 11, // 2: function.DeployRequest.env_vars:type_name -> function.DeployRequest.EnvVarsEntry
5, // 3: function.ListResponse.functions:type_name -> function.Func 5, // 3: function.ListResponse.functions:type_name -> function.Func
0, // 4: function.Function.Call:input_type -> function.CallRequest 5, // 4: function.DescribeResponse.function:type_name -> function.Func
2, // 5: function.Function.Deploy:input_type -> function.DeployRequest 0, // 5: function.Function.Call:input_type -> function.CallRequest
4, // 6: function.Function.List:input_type -> function.ListRequest 2, // 6: function.Function.Deploy:input_type -> function.DeployRequest
7, // 7: function.Function.Delete:input_type -> function.DeleteRequest 4, // 7: function.Function.List:input_type -> function.ListRequest
9, // 8: function.Function.Describe:input_type -> function.DescribeRequest 7, // 8: function.Function.Delete:input_type -> function.DeleteRequest
1, // 9: function.Function.Call:output_type -> function.CallResponse 9, // 9: function.Function.Describe:input_type -> function.DescribeRequest
3, // 10: function.Function.Deploy:output_type -> function.DeployResponse 1, // 10: function.Function.Call:output_type -> function.CallResponse
6, // 11: function.Function.List:output_type -> function.ListResponse 3, // 11: function.Function.Deploy:output_type -> function.DeployResponse
8, // 12: function.Function.Delete:output_type -> function.DeleteResponse 6, // 12: function.Function.List:output_type -> function.ListResponse
10, // 13: function.Function.Describe:output_type -> function.DescribeResponse 8, // 13: function.Function.Delete:output_type -> function.DeleteResponse
9, // [9:14] is the sub-list for method output_type 10, // 14: function.Function.Describe:output_type -> function.DescribeResponse
4, // [4:9] is the sub-list for method input_type 10, // [10:15] is the sub-list for method output_type
4, // [4:4] is the sub-list for extension type_name 5, // [5:10] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension extendee 5, // [5:5] is the sub-list for extension type_name
0, // [0:4] is the sub-list for field type_name 5, // [5:5] is the sub-list for extension extendee
0, // [0:5] is the sub-list for field type_name
} }
func init() { file_proto_function_proto_init() } func init() { file_proto_function_proto_init() }

View File

@@ -115,10 +115,12 @@ message DescribeRequest {
} }
message DescribeResponse { message DescribeResponse {
// The function requested
Func function = 1;
// The time at which the function was updated // The time at which the function was updated
string updateTime = 1; string updateTime = 2;
// The last known status of the function // The last known status of the function
string status = 2; string status = 3;
// The timeout for requests to the function // The timeout for requests to the function
string timeout = 3; string timeout = 4;
} }