feat: 对接腾讯云查询函数详情方法
Signed-off-by: devad <cossjie@foxmail.com> Former-commit-id: 9cfe3e0a5f67030246cf121cd155c4ea1db36c03
This commit is contained in:
parent
1adcf288da
commit
61c5fc033d
|
@ -16,7 +16,7 @@
|
|||
|
||||
- [ ] CreateFunction 创建函数
|
||||
- [ ] DeleteFunction 删除函数
|
||||
- [ ] GetFunction 获取函数详细信息
|
||||
- [x] GetFunction 获取函数详细信息
|
||||
- [ ] Invoke 运行函数
|
||||
- [x] ListFunctions 获取函数列表
|
||||
- [ ] UpdateFunctionCode 更新函数代码
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||
tscf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
|
||||
|
||||
"PCM/adaptor/PCM-FC/PCM-SCF/internal/svc"
|
||||
"PCM/adaptor/PCM-FC/PCM-SCF/scf"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetFunctionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetFunctionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFunctionsLogic {
|
||||
return &GetFunctionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
func (l *GetFunctionsLogic) GetFunctions(in *scf.GetFunctionsReq) (*scf.GetFunctionsResp, error) {
|
||||
resp := &scf.GetFunctionsResp{}
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的k
|
||||
client, _ := tscf.NewClient(l.svcCtx.Credential, in.Region, l.svcCtx.Cpf)
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
request := tscf.NewGetFunctionRequest()
|
||||
|
||||
request.FunctionName = common.StringPtr(in.FunctionName)
|
||||
|
||||
// 返回的resp是一个GetFunctionResponse的实例,与请求对象对应
|
||||
response, err := client.GetFunction(request)
|
||||
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
fmt.Printf("An API error has returned: %s", err)
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tool.Convert(response.Response, &resp.Response)
|
||||
return resp, nil
|
||||
}
|
|
@ -7,7 +7,6 @@ import (
|
|||
"context"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tscf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -26,15 +25,11 @@ func NewListFunctionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Lis
|
|||
}
|
||||
}
|
||||
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
func (l *ListFunctionsLogic) ListFunctions(in *scf.ListFunctionsReq) (*scf.ListFunctionsResp, error) {
|
||||
resp := &scf.ListFunctionsResp{}
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
cpf := profile.NewClientProfile()
|
||||
//请求域名,表示用户的接入地域,默认就近接入
|
||||
cpf.HttpProfile.Endpoint = "scf.tencentcloudapi.com"
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
client, _ := tscf.NewClient(l.svcCtx.Credential, in.Region, cpf)
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的k
|
||||
client, _ := tscf.NewClient(l.svcCtx.Credential, in.Region, l.svcCtx.Cpf)
|
||||
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
request := tscf.NewListFunctionsRequest()
|
||||
|
|
|
@ -22,8 +22,14 @@ func NewScfServer(svcCtx *svc.ServiceContext) *ScfServer {
|
|||
}
|
||||
}
|
||||
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
func (s *ScfServer) ListFunctions(ctx context.Context, in *scf.ListFunctionsReq) (*scf.ListFunctionsResp, error) {
|
||||
l := logic.NewListFunctionsLogic(ctx, s.svcCtx)
|
||||
return l.ListFunctions(in)
|
||||
}
|
||||
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
func (s *ScfServer) GetFunctions(ctx context.Context, in *scf.GetFunctionsReq) (*scf.GetFunctionsResp, error) {
|
||||
l := logic.NewGetFunctionsLogic(ctx, s.svcCtx)
|
||||
return l.GetFunctions(in)
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ package svc
|
|||
import (
|
||||
"PCM/adaptor/PCM-FC/PCM-SCF/internal/config"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Credential *common.Credential
|
||||
Cpf *profile.ClientProfile
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
@ -17,8 +19,14 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
c.SecretConfig.SecretKey,
|
||||
)
|
||||
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
cpf := profile.NewClientProfile()
|
||||
//请求域名,表示用户的接入地域,默认就近接入
|
||||
cpf.HttpProfile.Endpoint = "scf.tencentcloudapi.com"
|
||||
|
||||
return &ServiceContext{
|
||||
Credential: credential,
|
||||
Config: c,
|
||||
Cpf: cpf,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,167 @@ syntax = "proto3";
|
|||
package scf;
|
||||
option go_package = "/scf";
|
||||
|
||||
message GetFunctionsReq {
|
||||
string functionName = 1;
|
||||
string qualifier = 2;
|
||||
string namespace = 3;
|
||||
string showCode = 4;
|
||||
string region = 5;
|
||||
}
|
||||
|
||||
message Triggers {
|
||||
string ModTime = 1;
|
||||
string Type = 2;
|
||||
string TriggerDesc = 3;
|
||||
string TriggerName = 4;
|
||||
string AddTime = 5;
|
||||
uint32 Enable = 6;
|
||||
string CustomArgument = 7;
|
||||
string AvailableStatus = 8;
|
||||
string ResourceId = 9;
|
||||
string BindStatus = 10;
|
||||
string TriggerAttribute = 11;
|
||||
string Qualifier = 12;
|
||||
string Description = 13;
|
||||
}
|
||||
|
||||
message Vpcconfig {
|
||||
string VpcId = 1;
|
||||
string SubnetId = 2;
|
||||
}
|
||||
|
||||
message Variables {
|
||||
string Key = 1;
|
||||
string Value = 2;
|
||||
}
|
||||
|
||||
message Environment {
|
||||
repeated Variables Variables = 1;
|
||||
}
|
||||
|
||||
message Tags {
|
||||
string Key = 1;
|
||||
string Value = 2;
|
||||
}
|
||||
|
||||
message Eipconfig {
|
||||
string EipFixed = 1;
|
||||
repeated string Eips = 2;
|
||||
}
|
||||
|
||||
message Accessinfo {
|
||||
string Host = 1;
|
||||
string Vip = 2;
|
||||
}
|
||||
|
||||
message Layers {
|
||||
repeated string CompatibleRuntimes = 1;
|
||||
string AddTime = 2;
|
||||
string Description = 3;
|
||||
string LicenseInfo = 4;
|
||||
uint32 LayerVersion = 5;
|
||||
string LayerName = 6;
|
||||
string Status = 7;
|
||||
string Stamp = 8;
|
||||
}
|
||||
|
||||
message Deadletterconfig {
|
||||
string Type = 1;
|
||||
string Name = 2;
|
||||
string FilterType = 3;
|
||||
}
|
||||
|
||||
message Eipconfig1 {
|
||||
string EipStatus = 1;
|
||||
repeated string EipAddress = 2;
|
||||
}
|
||||
|
||||
message Publicnetconfig {
|
||||
string PublicNetStatus = 1;
|
||||
Eipconfig1 EipConfig = 2;
|
||||
}
|
||||
|
||||
message Cfsinslist {
|
||||
string UserId = 1;
|
||||
string UserGroupId = 2;
|
||||
string CfsId = 3;
|
||||
string MountInsId = 4;
|
||||
string LocalMountDir = 5;
|
||||
string RemoteMountDir = 6;
|
||||
string IpAddress = 7;
|
||||
string MountVpcId = 8;
|
||||
string MountSubnetId = 9;
|
||||
}
|
||||
|
||||
message Cfsconfig {
|
||||
repeated Cfsinslist CfsInsList = 1;
|
||||
}
|
||||
|
||||
message Statusreasons {
|
||||
string ErrorCode = 1;
|
||||
string ErrorMessage = 2;
|
||||
}
|
||||
|
||||
message Wsparams {
|
||||
uint32 IdleTimeOut = 1;
|
||||
}
|
||||
|
||||
message Protocolparams {
|
||||
Wsparams WSParams = 1;
|
||||
}
|
||||
|
||||
message GetFunctionsResp {
|
||||
GetFunctionsResponse Response = 1;
|
||||
}
|
||||
|
||||
message GetFunctionsResponse {
|
||||
string ModTime = 1;
|
||||
string CodeInfo = 2;
|
||||
string Description = 3;
|
||||
repeated Triggers Triggers = 4;
|
||||
string Handler = 5;
|
||||
uint32 CodeSize = 6;
|
||||
uint32 Timeout = 7;
|
||||
string FunctionVersion = 8;
|
||||
uint32 MemorySize = 9;
|
||||
string Runtime = 10;
|
||||
string FunctionName = 11;
|
||||
Vpcconfig VpcConfig = 12;
|
||||
string UseGpu = 13;
|
||||
Environment Environment = 14;
|
||||
string CodeResult = 15;
|
||||
string CodeError = 16;
|
||||
uint32 ErrNo = 17;
|
||||
string Namespace = 18;
|
||||
string Role = 19;
|
||||
string InstallDependency = 20;
|
||||
string Status = 21;
|
||||
string StatusDesc = 22;
|
||||
string ClsLogsetId = 23;
|
||||
string ClsTopicId = 24;
|
||||
string FunctionId = 25;
|
||||
repeated Tags Tags = 26;
|
||||
Eipconfig EipConfig = 27;
|
||||
Accessinfo AccessInfo = 28;
|
||||
string Type = 29;
|
||||
string L5Enable = 30;
|
||||
repeated Layers Layers = 31;
|
||||
Deadletterconfig DeadLetterConfig = 32;
|
||||
string AddTime = 33;
|
||||
Publicnetconfig PublicNetConfig = 34;
|
||||
string OnsEnable = 35;
|
||||
Cfsconfig CfsConfig = 36;
|
||||
string AvailableStatus = 37;
|
||||
string Qualifier = 38;
|
||||
uint32 InitTimeout = 39;
|
||||
repeated Statusreasons StatusReasons = 40;
|
||||
string AsyncRunEnable = 41;
|
||||
string TraceEnable = 42;
|
||||
string ProtocolType = 43;
|
||||
Protocolparams ProtocolParams = 44;
|
||||
string RequestId = 45;
|
||||
}
|
||||
|
||||
message ListFunctionsReq {
|
||||
string order = 1;
|
||||
string orderby = 2;
|
||||
|
@ -22,7 +183,7 @@ message Filters {
|
|||
|
||||
|
||||
message ListFunctionsResp {
|
||||
Response response = 1;
|
||||
ListFunctionsResponse Response = 1;
|
||||
}
|
||||
|
||||
message Functions {
|
||||
|
@ -44,17 +205,20 @@ message Functions {
|
|||
string type = 16;
|
||||
}
|
||||
|
||||
message Response {
|
||||
message ListFunctionsResponse {
|
||||
repeated Functions functions = 1;
|
||||
string requestId = 2;
|
||||
int32 totalCount = 3;
|
||||
}
|
||||
|
||||
|
||||
// scf
|
||||
// scf 腾讯云函数
|
||||
service Scf {
|
||||
|
||||
//查询腾讯云云函数列表
|
||||
//ListFunctions 查询腾讯云云函数列表
|
||||
rpc ListFunctions(ListFunctionsReq) returns (ListFunctionsResp);
|
||||
|
||||
//GetFunctions 查询腾讯云云函数详情
|
||||
rpc GetFunctions(GetFunctionsReq) returns (GetFunctionsResp);
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc v3.21.12
|
||||
// - protoc v4.23.4
|
||||
// source: pb/pcm-scf.proto
|
||||
|
||||
package scf
|
||||
|
@ -20,14 +20,17 @@ const _ = grpc.SupportPackageIsVersion7
|
|||
|
||||
const (
|
||||
Scf_ListFunctions_FullMethodName = "/scf.Scf/ListFunctions"
|
||||
Scf_GetFunctions_FullMethodName = "/scf.Scf/GetFunctions"
|
||||
)
|
||||
|
||||
// ScfClient is the client API for Scf service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type ScfClient interface {
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
ListFunctions(ctx context.Context, in *ListFunctionsReq, opts ...grpc.CallOption) (*ListFunctionsResp, error)
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
GetFunctions(ctx context.Context, in *GetFunctionsReq, opts ...grpc.CallOption) (*GetFunctionsResp, error)
|
||||
}
|
||||
|
||||
type scfClient struct {
|
||||
|
@ -47,12 +50,23 @@ func (c *scfClient) ListFunctions(ctx context.Context, in *ListFunctionsReq, opt
|
|||
return out, nil
|
||||
}
|
||||
|
||||
func (c *scfClient) GetFunctions(ctx context.Context, in *GetFunctionsReq, opts ...grpc.CallOption) (*GetFunctionsResp, error) {
|
||||
out := new(GetFunctionsResp)
|
||||
err := c.cc.Invoke(ctx, Scf_GetFunctions_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ScfServer is the server API for Scf service.
|
||||
// All implementations must embed UnimplementedScfServer
|
||||
// for forward compatibility
|
||||
type ScfServer interface {
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
ListFunctions(context.Context, *ListFunctionsReq) (*ListFunctionsResp, error)
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
GetFunctions(context.Context, *GetFunctionsReq) (*GetFunctionsResp, error)
|
||||
mustEmbedUnimplementedScfServer()
|
||||
}
|
||||
|
||||
|
@ -63,6 +77,9 @@ type UnimplementedScfServer struct {
|
|||
func (UnimplementedScfServer) ListFunctions(context.Context, *ListFunctionsReq) (*ListFunctionsResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListFunctions not implemented")
|
||||
}
|
||||
func (UnimplementedScfServer) GetFunctions(context.Context, *GetFunctionsReq) (*GetFunctionsResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetFunctions not implemented")
|
||||
}
|
||||
func (UnimplementedScfServer) mustEmbedUnimplementedScfServer() {}
|
||||
|
||||
// UnsafeScfServer may be embedded to opt out of forward compatibility for this service.
|
||||
|
@ -94,6 +111,24 @@ func _Scf_ListFunctions_Handler(srv interface{}, ctx context.Context, dec func(i
|
|||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Scf_GetFunctions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetFunctionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ScfServer).GetFunctions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Scf_GetFunctions_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ScfServer).GetFunctions(ctx, req.(*GetFunctionsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Scf_ServiceDesc is the grpc.ServiceDesc for Scf service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
|
@ -105,6 +140,10 @@ var Scf_ServiceDesc = grpc.ServiceDesc{
|
|||
MethodName: "ListFunctions",
|
||||
Handler: _Scf_ListFunctions_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetFunctions",
|
||||
Handler: _Scf_GetFunctions_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "pb/pcm-scf.proto",
|
||||
|
|
|
@ -13,15 +13,36 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Filters = scf.Filters
|
||||
Functions = scf.Functions
|
||||
ListFunctionsReq = scf.ListFunctionsReq
|
||||
ListFunctionsResp = scf.ListFunctionsResp
|
||||
Response = scf.Response
|
||||
Accessinfo = scf.Accessinfo
|
||||
Cfsconfig = scf.Cfsconfig
|
||||
Cfsinslist = scf.Cfsinslist
|
||||
Deadletterconfig = scf.Deadletterconfig
|
||||
Eipconfig = scf.Eipconfig
|
||||
Eipconfig1 = scf.Eipconfig1
|
||||
Environment = scf.Environment
|
||||
Filters = scf.Filters
|
||||
Functions = scf.Functions
|
||||
GetFunctionsReq = scf.GetFunctionsReq
|
||||
GetFunctionsResp = scf.GetFunctionsResp
|
||||
GetFunctionsResponse = scf.GetFunctionsResponse
|
||||
Layers = scf.Layers
|
||||
ListFunctionsReq = scf.ListFunctionsReq
|
||||
ListFunctionsResp = scf.ListFunctionsResp
|
||||
ListFunctionsResponse = scf.ListFunctionsResponse
|
||||
Protocolparams = scf.Protocolparams
|
||||
Publicnetconfig = scf.Publicnetconfig
|
||||
Statusreasons = scf.Statusreasons
|
||||
Tags = scf.Tags
|
||||
Triggers = scf.Triggers
|
||||
Variables = scf.Variables
|
||||
Vpcconfig = scf.Vpcconfig
|
||||
Wsparams = scf.Wsparams
|
||||
|
||||
Scf interface {
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
ListFunctions(ctx context.Context, in *ListFunctionsReq, opts ...grpc.CallOption) (*ListFunctionsResp, error)
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
GetFunctions(ctx context.Context, in *GetFunctionsReq, opts ...grpc.CallOption) (*GetFunctionsResp, error)
|
||||
}
|
||||
|
||||
defaultScf struct {
|
||||
|
@ -35,8 +56,14 @@ func NewScf(cli zrpc.Client) Scf {
|
|||
}
|
||||
}
|
||||
|
||||
// 查询腾讯云云函数列表
|
||||
// ListFunctions 查询腾讯云云函数列表
|
||||
func (m *defaultScf) ListFunctions(ctx context.Context, in *ListFunctionsReq, opts ...grpc.CallOption) (*ListFunctionsResp, error) {
|
||||
client := scf.NewScfClient(m.cli.Conn())
|
||||
return client.ListFunctions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// GetFunctions 查询腾讯云云函数详情
|
||||
func (m *defaultScf) GetFunctions(ctx context.Context, in *GetFunctionsReq, opts ...grpc.CallOption) (*GetFunctionsResp, error) {
|
||||
client := scf.NewScfClient(m.cli.Conn())
|
||||
return client.GetFunctions(ctx, in, opts...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue