From edb12c3b1fa91686a9ab9f7ab80e35b3bcd927fe Mon Sep 17 00:00:00 2001 From: algotao Date: Sat, 9 Aug 2025 15:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AD=96=E7=95=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E7=BB=91=E5=AE=9A=E3=80=81=E8=A7=A3=E7=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd.pb.go | 1024 +++++++++++++++++++++++++++---- cmd.proto | 94 ++- cmd/saastool/bind.go | 46 ++ cmd/saastool/bind_delete.go | 105 ++++ cmd/saastool/bind_setaccount.go | 107 ++++ cmd/saastool/bind_setad.go | 110 ++++ cmd/saastool/help.go | 4 +- cmd/saastool/main.go | 4 + cmd/saastool/params.go | 32 + cmd/saastool/read.go | 2 +- cmd/saastool/target.go | 40 ++ cmd/saastool/target_list.go | 88 +++ cmd/saastool/task_create.go | 2 +- cmd/saastool/task_delete.go | 2 +- cmd/saastool/task_download.go | 4 +- cmd/saastool/task_info.go | 2 +- cmd/saastool/task_list.go | 2 +- cmd/saastool/task_run.go | 2 +- cmd/saastool/task_upload.go | 2 +- cmd/saastool/write.go | 2 +- pkg/saashttp/cfg.go | 110 ++++ pkg/saashttp/httpcli.go | 15 + 22 files changed, 1674 insertions(+), 125 deletions(-) create mode 100644 cmd/saastool/bind.go create mode 100644 cmd/saastool/bind_delete.go create mode 100644 cmd/saastool/bind_setaccount.go create mode 100644 cmd/saastool/bind_setad.go create mode 100644 cmd/saastool/target.go create mode 100644 cmd/saastool/target_list.go diff --git a/cmd.pb.go b/cmd.pb.go index 4005a94..95321ca 100644 --- a/cmd.pb.go +++ b/cmd.pb.go @@ -21,6 +21,112 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// BindType 绑定类型 +type BindType int32 + +const ( + BindType_UnknownBindType BindType = 0 + BindType_AdgroupId BindType = 1 //广告 + BindType_AccountId BindType = 3 //广告主 +) + +// Enum value maps for BindType. +var ( + BindType_name = map[int32]string{ + 0: "UnknownBindType", + 1: "AdgroupId", + 3: "AccountId", + } + BindType_value = map[string]int32{ + "UnknownBindType": 0, + "AdgroupId": 1, + "AccountId": 3, + } +) + +func (x BindType) Enum() *BindType { + p := new(BindType) + *p = x + return p +} + +func (x BindType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (BindType) Descriptor() protoreflect.EnumDescriptor { + return file_cmd_proto_enumTypes[0].Descriptor() +} + +func (BindType) Type() protoreflect.EnumType { + return &file_cmd_proto_enumTypes[0] +} + +func (x BindType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use BindType.Descriptor instead. +func (BindType) EnumDescriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{0} +} + +// BindSourceType 绑定操作来源 +type BindSourceType int32 + +const ( + BindSourceType_DefaultBindSourceType BindSourceType = 0 //广告主或未填写 + BindSourceType_ThirdPartyApi BindSourceType = 1 //第三方API + BindSourceType_ADQ BindSourceType = 2 //ADQ平台 + BindSourceType_MP BindSourceType = 3 //MP平台 + BindSourceType_MktApi BindSourceType = 4 //MarketingAPI +) + +// Enum value maps for BindSourceType. +var ( + BindSourceType_name = map[int32]string{ + 0: "DefaultBindSourceType", + 1: "ThirdPartyApi", + 2: "ADQ", + 3: "MP", + 4: "MktApi", + } + BindSourceType_value = map[string]int32{ + "DefaultBindSourceType": 0, + "ThirdPartyApi": 1, + "ADQ": 2, + "MP": 3, + "MktApi": 4, + } +) + +func (x BindSourceType) Enum() *BindSourceType { + p := new(BindSourceType) + *p = x + return p +} + +func (x BindSourceType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (BindSourceType) Descriptor() protoreflect.EnumDescriptor { + return file_cmd_proto_enumTypes[1].Descriptor() +} + +func (BindSourceType) Type() protoreflect.EnumType { + return &file_cmd_proto_enumTypes[1] +} + +func (x BindSourceType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use BindSourceType.Descriptor instead. +func (BindSourceType) EnumDescriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{1} +} + // ErrorCode 返回码 type ErrorCode int32 @@ -50,6 +156,7 @@ const ( ErrorCode_TASK_FINISHED ErrorCode = 133 // 任务已完成 ErrorCode_DATA_ERROR ErrorCode = 201 // 数据错误 ErrorCode_CMD_ERROR ErrorCode = 202 // 命令行执行错误 + ErrorCode_API_ERROR ErrorCode = 301 // 调用内部API错误 ) // Enum value maps for ErrorCode. @@ -80,6 +187,7 @@ var ( 133: "TASK_FINISHED", 201: "DATA_ERROR", 202: "CMD_ERROR", + 301: "API_ERROR", } ErrorCode_value = map[string]int32{ "SUCC": 0, @@ -107,6 +215,7 @@ var ( "TASK_FINISHED": 133, "DATA_ERROR": 201, "CMD_ERROR": 202, + "API_ERROR": 301, } ) @@ -121,11 +230,11 @@ func (x ErrorCode) String() string { } func (ErrorCode) Descriptor() protoreflect.EnumDescriptor { - return file_cmd_proto_enumTypes[0].Descriptor() + return file_cmd_proto_enumTypes[2].Descriptor() } func (ErrorCode) Type() protoreflect.EnumType { - return &file_cmd_proto_enumTypes[0] + return &file_cmd_proto_enumTypes[2] } func (x ErrorCode) Number() protoreflect.EnumNumber { @@ -134,7 +243,7 @@ func (x ErrorCode) Number() protoreflect.EnumNumber { // Deprecated: Use ErrorCode.Descriptor instead. func (ErrorCode) EnumDescriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{0} + return file_cmd_proto_rawDescGZIP(), []int{2} } type CmdErrorCode int32 @@ -164,11 +273,11 @@ func (x CmdErrorCode) String() string { } func (CmdErrorCode) Descriptor() protoreflect.EnumDescriptor { - return file_cmd_proto_enumTypes[1].Descriptor() + return file_cmd_proto_enumTypes[3].Descriptor() } func (CmdErrorCode) Type() protoreflect.EnumType { - return &file_cmd_proto_enumTypes[1] + return &file_cmd_proto_enumTypes[3] } func (x CmdErrorCode) Number() protoreflect.EnumNumber { @@ -177,7 +286,7 @@ func (x CmdErrorCode) Number() protoreflect.EnumNumber { // Deprecated: Use CmdErrorCode.Descriptor instead. func (CmdErrorCode) EnumDescriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{1} + return file_cmd_proto_rawDescGZIP(), []int{3} } type TaskStatus int32 @@ -225,11 +334,11 @@ func (x TaskStatus) String() string { } func (TaskStatus) Descriptor() protoreflect.EnumDescriptor { - return file_cmd_proto_enumTypes[2].Descriptor() + return file_cmd_proto_enumTypes[4].Descriptor() } func (TaskStatus) Type() protoreflect.EnumType { - return &file_cmd_proto_enumTypes[2] + return &file_cmd_proto_enumTypes[4] } func (x TaskStatus) Number() protoreflect.EnumNumber { @@ -238,7 +347,7 @@ func (x TaskStatus) Number() protoreflect.EnumNumber { // Deprecated: Use TaskStatus.Descriptor instead. func (TaskStatus) EnumDescriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{2} + return file_cmd_proto_rawDescGZIP(), []int{4} } // SaasReq 命令请求 @@ -254,6 +363,9 @@ type SaasReq struct { // *SaasReq_TaskRun // *SaasReq_TaskDelete // *SaasReq_TaskInfo + // *SaasReq_TargetList + // *SaasReq_BindSet + // *SaasReq_BindDelete // *SaasReq_Debug Cmd isSaasReq_Cmd `protobuf_oneof:"cmd"` unknownFields protoimpl.UnknownFields @@ -369,6 +481,33 @@ func (x *SaasReq) GetTaskInfo() *TaskInfo { return nil } +func (x *SaasReq) GetTargetList() *TargetList { + if x != nil { + if x, ok := x.Cmd.(*SaasReq_TargetList); ok { + return x.TargetList + } + } + return nil +} + +func (x *SaasReq) GetBindSet() *BindSet { + if x != nil { + if x, ok := x.Cmd.(*SaasReq_BindSet); ok { + return x.BindSet + } + } + return nil +} + +func (x *SaasReq) GetBindDelete() *BindDelete { + if x != nil { + if x, ok := x.Cmd.(*SaasReq_BindDelete); ok { + return x.BindDelete + } + } + return nil +} + func (x *SaasReq) GetDebug() *Debug { if x != nil { if x, ok := x.Cmd.(*SaasReq_Debug); ok { @@ -414,8 +553,20 @@ type SaasReq_TaskInfo struct { TaskInfo *TaskInfo `protobuf:"bytes,24,opt,name=task_info,json=taskInfo,proto3,oneof"` // 任务详情 } +type SaasReq_TargetList struct { + TargetList *TargetList `protobuf:"bytes,50,opt,name=target_list,json=targetList,proto3,oneof"` // 列出策略及绑定 +} + +type SaasReq_BindSet struct { + BindSet *BindSet `protobuf:"bytes,61,opt,name=bind_set,json=bindSet,proto3,oneof"` // 设置绑定 +} + +type SaasReq_BindDelete struct { + BindDelete *BindDelete `protobuf:"bytes,62,opt,name=bind_delete,json=bindDelete,proto3,oneof"` // 解除绑定 +} + type SaasReq_Debug struct { - Debug *Debug `protobuf:"bytes,30,opt,name=debug,proto3,oneof"` // 试运行lua脚本 + Debug *Debug `protobuf:"bytes,90,opt,name=debug,proto3,oneof"` // 试运行lua脚本 } func (*SaasReq_Read) isSaasReq_Cmd() {} @@ -434,6 +585,12 @@ func (*SaasReq_TaskDelete) isSaasReq_Cmd() {} func (*SaasReq_TaskInfo) isSaasReq_Cmd() {} +func (*SaasReq_TargetList) isSaasReq_Cmd() {} + +func (*SaasReq_BindSet) isSaasReq_Cmd() {} + +func (*SaasReq_BindDelete) isSaasReq_Cmd() {} + func (*SaasReq_Debug) isSaasReq_Cmd() {} // Read 批量读取命令 @@ -1298,6 +1455,7 @@ func (x *TaskInfo) GetTaskSha256() string { return "" } +// FileInfo 任务文件信息 type FileInfo struct { state protoimpl.MessageState `protogen:"open.v1"` FileName string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"` // 文件名 @@ -1358,6 +1516,7 @@ func (x *FileInfo) GetFileBlocks() []*FileBlock { return nil } +// FileBlock 文件块信息 type FileBlock struct { state protoimpl.MessageState `protogen:"open.v1"` BlockSha256 string `protobuf:"bytes,1,opt,name=block_sha256,json=blockSha256,proto3" json:"block_sha256,omitempty"` // 块的sha256 @@ -1418,6 +1577,150 @@ func (x *FileBlock) GetUploaded() bool { return false } +// TargetList 列出策略 +type TargetList struct { + state protoimpl.MessageState `protogen:"open.v1"` + Targets []string `protobuf:"bytes,1,rep,name=targets,proto3" json:"targets,omitempty"` // 指定要列出的绑定的策略列表,如不指定则返回全部 + ListBind bool `protobuf:"varint,2,opt,name=list_bind,json=listBind,proto3" json:"list_bind,omitempty"` // 是否同时列出绑定信息 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TargetList) Reset() { + *x = TargetList{} + mi := &file_cmd_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TargetList) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TargetList) ProtoMessage() {} + +func (x *TargetList) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[17] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TargetList.ProtoReflect.Descriptor instead. +func (*TargetList) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{17} +} + +func (x *TargetList) GetTargets() []string { + if x != nil { + return x.Targets + } + return nil +} + +func (x *TargetList) GetListBind() bool { + if x != nil { + return x.ListBind + } + return false +} + +// BindSet 设置绑定 +type BindSet struct { + state protoimpl.MessageState `protogen:"open.v1"` + Binds []*Bind `protobuf:"bytes,2,rep,name=binds,proto3" json:"binds,omitempty"` // 设置绑定内容 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BindSet) Reset() { + *x = BindSet{} + mi := &file_cmd_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BindSet) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BindSet) ProtoMessage() {} + +func (x *BindSet) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[18] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BindSet.ProtoReflect.Descriptor instead. +func (*BindSet) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{18} +} + +func (x *BindSet) GetBinds() []*Bind { + if x != nil { + return x.Binds + } + return nil +} + +// BindDelete 删除绑定 +type BindDelete struct { + state protoimpl.MessageState `protogen:"open.v1"` + Binds []*Bind `protobuf:"bytes,2,rep,name=binds,proto3" json:"binds,omitempty"` // 解除绑定内容 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BindDelete) Reset() { + *x = BindDelete{} + mi := &file_cmd_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BindDelete) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BindDelete) ProtoMessage() {} + +func (x *BindDelete) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[19] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BindDelete.ProtoReflect.Descriptor instead. +func (*BindDelete) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{19} +} + +func (x *BindDelete) GetBinds() []*Bind { + if x != nil { + return x.Binds + } + return nil +} + +// Debug 调试 type Debug struct { state protoimpl.MessageState `protogen:"open.v1"` LuaScript string `protobuf:"bytes,1,opt,name=lua_script,json=luaScript,proto3" json:"lua_script,omitempty"` // 要调试的lua脚本 @@ -1433,7 +1736,7 @@ type Debug struct { func (x *Debug) Reset() { *x = Debug{} - mi := &file_cmd_proto_msgTypes[17] + mi := &file_cmd_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1445,7 +1748,7 @@ func (x *Debug) String() string { func (*Debug) ProtoMessage() {} func (x *Debug) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[17] + mi := &file_cmd_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1458,7 +1761,7 @@ func (x *Debug) ProtoReflect() protoreflect.Message { // Deprecated: Use Debug.ProtoReflect.Descriptor instead. func (*Debug) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{17} + return file_cmd_proto_rawDescGZIP(), []int{20} } func (x *Debug) GetLuaScript() string { @@ -1524,6 +1827,9 @@ type SaasRes struct { // *SaasRes_TaskRunRes // *SaasRes_TaskDeleteRes // *SaasRes_TaskInfoRes + // *SaasRes_TargetListRes + // *SaasRes_BindSetRes + // *SaasRes_BindDeleteRes Res isSaasRes_Res `protobuf_oneof:"res"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -1531,7 +1837,7 @@ type SaasRes struct { func (x *SaasRes) Reset() { *x = SaasRes{} - mi := &file_cmd_proto_msgTypes[18] + mi := &file_cmd_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1543,7 +1849,7 @@ func (x *SaasRes) String() string { func (*SaasRes) ProtoMessage() {} func (x *SaasRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[18] + mi := &file_cmd_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1556,7 +1862,7 @@ func (x *SaasRes) ProtoReflect() protoreflect.Message { // Deprecated: Use SaasRes.ProtoReflect.Descriptor instead. func (*SaasRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{18} + return file_cmd_proto_rawDescGZIP(), []int{21} } func (x *SaasRes) GetCode() ErrorCode { @@ -1643,6 +1949,33 @@ func (x *SaasRes) GetTaskInfoRes() *Task { return nil } +func (x *SaasRes) GetTargetListRes() *TargetListRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_TargetListRes); ok { + return x.TargetListRes + } + } + return nil +} + +func (x *SaasRes) GetBindSetRes() *BindSetRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_BindSetRes); ok { + return x.BindSetRes + } + } + return nil +} + +func (x *SaasRes) GetBindDeleteRes() *BindDeleteRes { + if x != nil { + if x, ok := x.Res.(*SaasRes_BindDeleteRes); ok { + return x.BindDeleteRes + } + } + return nil +} + type isSaasRes_Res interface { isSaasRes_Res() } @@ -1675,6 +2008,18 @@ type SaasRes_TaskInfoRes struct { TaskInfoRes *Task `protobuf:"bytes,24,opt,name=task_info_res,json=taskInfoRes,proto3,oneof"` // 任务详情返回状态 } +type SaasRes_TargetListRes struct { + TargetListRes *TargetListRes `protobuf:"bytes,50,opt,name=target_list_res,json=targetListRes,proto3,oneof"` // 列出策略及绑定返回状态 +} + +type SaasRes_BindSetRes struct { + BindSetRes *BindSetRes `protobuf:"bytes,61,opt,name=bind_set_res,json=bindSetRes,proto3,oneof"` // 设置绑定返回状态 +} + +type SaasRes_BindDeleteRes struct { + BindDeleteRes *BindDeleteRes `protobuf:"bytes,62,opt,name=bind_delete_res,json=bindDeleteRes,proto3,oneof"` // 删除绑定返回状态 +} + func (*SaasRes_ReadRes) isSaasRes_Res() {} func (*SaasRes_WriteRes) isSaasRes_Res() {} @@ -1689,6 +2034,13 @@ func (*SaasRes_TaskDeleteRes) isSaasRes_Res() {} func (*SaasRes_TaskInfoRes) isSaasRes_Res() {} +func (*SaasRes_TargetListRes) isSaasRes_Res() {} + +func (*SaasRes_BindSetRes) isSaasRes_Res() {} + +func (*SaasRes_BindDeleteRes) isSaasRes_Res() {} + +// ReadRes 读记录返回 type ReadRes struct { state protoimpl.MessageState `protogen:"open.v1"` SuccCmdCount uint32 `protobuf:"varint,1,opt,name=succ_cmd_count,json=succCmdCount,proto3" json:"succ_cmd_count,omitempty"` // 成功的命令数量 @@ -1700,7 +2052,7 @@ type ReadRes struct { func (x *ReadRes) Reset() { *x = ReadRes{} - mi := &file_cmd_proto_msgTypes[19] + mi := &file_cmd_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1712,7 +2064,7 @@ func (x *ReadRes) String() string { func (*ReadRes) ProtoMessage() {} func (x *ReadRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[19] + mi := &file_cmd_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1725,7 +2077,7 @@ func (x *ReadRes) ProtoReflect() protoreflect.Message { // Deprecated: Use ReadRes.ProtoReflect.Descriptor instead. func (*ReadRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{19} + return file_cmd_proto_rawDescGZIP(), []int{22} } func (x *ReadRes) GetSuccCmdCount() uint32 { @@ -1749,6 +2101,7 @@ func (x *ReadRes) GetCmdRes() []*ValueItem { return nil } +// WriteRes 写记录返回 type WriteRes struct { state protoimpl.MessageState `protogen:"open.v1"` // uint32 succ_cmd_count = 1; // 成功的命令数量 @@ -1760,7 +2113,7 @@ type WriteRes struct { func (x *WriteRes) Reset() { *x = WriteRes{} - mi := &file_cmd_proto_msgTypes[20] + mi := &file_cmd_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1772,7 +2125,7 @@ func (x *WriteRes) String() string { func (*WriteRes) ProtoMessage() {} func (x *WriteRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[20] + mi := &file_cmd_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1785,7 +2138,7 @@ func (x *WriteRes) ProtoReflect() protoreflect.Message { // Deprecated: Use WriteRes.ProtoReflect.Descriptor instead. func (*WriteRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{20} + return file_cmd_proto_rawDescGZIP(), []int{23} } func (x *WriteRes) GetFailedUserid() []string { @@ -1810,7 +2163,7 @@ type ValueItem struct { func (x *ValueItem) Reset() { *x = ValueItem{} - mi := &file_cmd_proto_msgTypes[21] + mi := &file_cmd_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1822,7 +2175,7 @@ func (x *ValueItem) String() string { func (*ValueItem) ProtoMessage() {} func (x *ValueItem) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[21] + mi := &file_cmd_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1835,7 +2188,7 @@ func (x *ValueItem) ProtoReflect() protoreflect.Message { // Deprecated: Use ValueItem.ProtoReflect.Descriptor instead. func (*ValueItem) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{21} + return file_cmd_proto_rawDescGZIP(), []int{24} } func (x *ValueItem) GetCmdIndex() uint32 { @@ -1880,6 +2233,7 @@ func (x *ValueItem) GetLastModifyTime() uint32 { return 0 } +// TaskListRes 任务列表返回 type TaskListRes struct { state protoimpl.MessageState `protogen:"open.v1"` Tasks []*Task `protobuf:"bytes,1,rep,name=tasks,proto3" json:"tasks,omitempty"` // 任务列表 @@ -1889,7 +2243,7 @@ type TaskListRes struct { func (x *TaskListRes) Reset() { *x = TaskListRes{} - mi := &file_cmd_proto_msgTypes[22] + mi := &file_cmd_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1901,7 +2255,7 @@ func (x *TaskListRes) String() string { func (*TaskListRes) ProtoMessage() {} func (x *TaskListRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[22] + mi := &file_cmd_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1914,7 +2268,7 @@ func (x *TaskListRes) ProtoReflect() protoreflect.Message { // Deprecated: Use TaskListRes.ProtoReflect.Descriptor instead. func (*TaskListRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{22} + return file_cmd_proto_rawDescGZIP(), []int{25} } func (x *TaskListRes) GetTasks() []*Task { @@ -1924,6 +2278,356 @@ func (x *TaskListRes) GetTasks() []*Task { return nil } +// TargetListRes 策略列表返回 +type TargetListRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + TargetList map[string]*Binds `protobuf:"bytes,1,rep,name=target_list,json=targetList,proto3" json:"target_list,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // 绑定列表 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TargetListRes) Reset() { + *x = TargetListRes{} + mi := &file_cmd_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TargetListRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TargetListRes) ProtoMessage() {} + +func (x *TargetListRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[26] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TargetListRes.ProtoReflect.Descriptor instead. +func (*TargetListRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{26} +} + +func (x *TargetListRes) GetTargetList() map[string]*Binds { + if x != nil { + return x.TargetList + } + return nil +} + +type Binds struct { + state protoimpl.MessageState `protogen:"open.v1"` + Binds []*Bind `protobuf:"bytes,1,rep,name=binds,proto3" json:"binds,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Binds) Reset() { + *x = Binds{} + mi := &file_cmd_proto_msgTypes[27] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Binds) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Binds) ProtoMessage() {} + +func (x *Binds) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[27] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Binds.ProtoReflect.Descriptor instead. +func (*Binds) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{27} +} + +func (x *Binds) GetBinds() []*Bind { + if x != nil { + return x.Binds + } + return nil +} + +// Bind 绑定信息 +type Bind struct { + state protoimpl.MessageState `protogen:"open.v1"` + BindId int64 `protobuf:"varint,1,opt,name=bind_id,json=bindId,proto3" json:"bind_id,omitempty"` //绑定的ID + BindType BindType `protobuf:"varint,2,opt,name=bind_type,json=bindType,proto3,enum=saasapi.BindType" json:"bind_type,omitempty"` //绑定类型 + TargetId string `protobuf:"bytes,3,opt,name=target_id,json=targetId,proto3" json:"target_id,omitempty"` //策略ID + AccountId int64 `protobuf:"varint,4,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"` //广告主ID + BindSource BindSourceType `protobuf:"varint,5,opt,name=bind_source,json=bindSource,proto3,enum=saasapi.BindSourceType" json:"bind_source,omitempty"` //绑定操作来源 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Bind) Reset() { + *x = Bind{} + mi := &file_cmd_proto_msgTypes[28] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Bind) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Bind) ProtoMessage() {} + +func (x *Bind) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[28] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Bind.ProtoReflect.Descriptor instead. +func (*Bind) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{28} +} + +func (x *Bind) GetBindId() int64 { + if x != nil { + return x.BindId + } + return 0 +} + +func (x *Bind) GetBindType() BindType { + if x != nil { + return x.BindType + } + return BindType_UnknownBindType +} + +func (x *Bind) GetTargetId() string { + if x != nil { + return x.TargetId + } + return "" +} + +func (x *Bind) GetAccountId() int64 { + if x != nil { + return x.AccountId + } + return 0 +} + +func (x *Bind) GetBindSource() BindSourceType { + if x != nil { + return x.BindSource + } + return BindSourceType_DefaultBindSourceType +} + +// BindSetRes 设置绑定返回 +type BindSetRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + SuccessNum int32 `protobuf:"varint,1,opt,name=success_num,json=successNum,proto3" json:"success_num,omitempty"` //成功数 + ErrorNum int32 `protobuf:"varint,2,opt,name=error_num,json=errorNum,proto3" json:"error_num,omitempty"` //错误数 + Errors []*BindError `protobuf:"bytes,3,rep,name=errors,proto3" json:"errors,omitempty"` //绑定错误的记录 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BindSetRes) Reset() { + *x = BindSetRes{} + mi := &file_cmd_proto_msgTypes[29] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BindSetRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BindSetRes) ProtoMessage() {} + +func (x *BindSetRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[29] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BindSetRes.ProtoReflect.Descriptor instead. +func (*BindSetRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{29} +} + +func (x *BindSetRes) GetSuccessNum() int32 { + if x != nil { + return x.SuccessNum + } + return 0 +} + +func (x *BindSetRes) GetErrorNum() int32 { + if x != nil { + return x.ErrorNum + } + return 0 +} + +func (x *BindSetRes) GetErrors() []*BindError { + if x != nil { + return x.Errors + } + return nil +} + +// BindDeleteRes 删除绑定返回 +type BindDeleteRes struct { + state protoimpl.MessageState `protogen:"open.v1"` + SuccessNum int32 `protobuf:"varint,1,opt,name=success_num,json=successNum,proto3" json:"success_num,omitempty"` //成功数 + ErrorNum int32 `protobuf:"varint,2,opt,name=error_num,json=errorNum,proto3" json:"error_num,omitempty"` //错误数 + Errors []*BindError `protobuf:"bytes,3,rep,name=errors,proto3" json:"errors,omitempty"` //绑定错误的记录 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BindDeleteRes) Reset() { + *x = BindDeleteRes{} + mi := &file_cmd_proto_msgTypes[30] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BindDeleteRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BindDeleteRes) ProtoMessage() {} + +func (x *BindDeleteRes) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[30] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BindDeleteRes.ProtoReflect.Descriptor instead. +func (*BindDeleteRes) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{30} +} + +func (x *BindDeleteRes) GetSuccessNum() int32 { + if x != nil { + return x.SuccessNum + } + return 0 +} + +func (x *BindDeleteRes) GetErrorNum() int32 { + if x != nil { + return x.ErrorNum + } + return 0 +} + +func (x *BindDeleteRes) GetErrors() []*BindError { + if x != nil { + return x.Errors + } + return nil +} + +// BindError 绑定错误信息 +type BindError struct { + state protoimpl.MessageState `protogen:"open.v1"` + BindId int64 `protobuf:"varint,1,opt,name=bind_id,json=bindId,proto3" json:"bind_id,omitempty"` //错误绑定的绑定ID + BindType int32 `protobuf:"varint,2,opt,name=bind_type,json=bindType,proto3" json:"bind_type,omitempty"` //绑定类型 + Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"` //错误绑定原因 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BindError) Reset() { + *x = BindError{} + mi := &file_cmd_proto_msgTypes[31] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BindError) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BindError) ProtoMessage() {} + +func (x *BindError) ProtoReflect() protoreflect.Message { + mi := &file_cmd_proto_msgTypes[31] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BindError.ProtoReflect.Descriptor instead. +func (*BindError) Descriptor() ([]byte, []int) { + return file_cmd_proto_rawDescGZIP(), []int{31} +} + +func (x *BindError) GetBindId() int64 { + if x != nil { + return x.BindId + } + return 0 +} + +func (x *BindError) GetBindType() int32 { + if x != nil { + return x.BindType + } + return 0 +} + +func (x *BindError) GetReason() string { + if x != nil { + return x.Reason + } + return "" +} + +// DebugRes 调试返回 type DebugRes struct { state protoimpl.MessageState `protogen:"open.v1"` PrintOutput string `protobuf:"bytes,1,opt,name=PrintOutput,proto3" json:"PrintOutput,omitempty"` // print输出 @@ -1935,7 +2639,7 @@ type DebugRes struct { func (x *DebugRes) Reset() { *x = DebugRes{} - mi := &file_cmd_proto_msgTypes[23] + mi := &file_cmd_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1947,7 +2651,7 @@ func (x *DebugRes) String() string { func (*DebugRes) ProtoMessage() {} func (x *DebugRes) ProtoReflect() protoreflect.Message { - mi := &file_cmd_proto_msgTypes[23] + mi := &file_cmd_proto_msgTypes[32] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1960,7 +2664,7 @@ func (x *DebugRes) ProtoReflect() protoreflect.Message { // Deprecated: Use DebugRes.ProtoReflect.Descriptor instead. func (*DebugRes) Descriptor() ([]byte, []int) { - return file_cmd_proto_rawDescGZIP(), []int{23} + return file_cmd_proto_rawDescGZIP(), []int{32} } func (x *DebugRes) GetPrintOutput() string { @@ -1988,7 +2692,7 @@ var File_cmd_proto protoreflect.FileDescriptor const file_cmd_proto_rawDesc = "" + "\n" + - "\tcmd.proto\x12\asaasapi\"\xbd\x03\n" + + "\tcmd.proto\x12\asaasapi\"\xdc\x04\n" + "\aSaasReq\x12#\n" + "\x04read\x18\n" + " \x01(\v2\r.saasapi.ReadH\x00R\x04read\x12&\n" + @@ -2000,8 +2704,13 @@ const file_cmd_proto_rawDesc = "" + "\btask_run\x18\x16 \x01(\v2\x10.saasapi.TaskRunH\x00R\ataskRun\x126\n" + "\vtask_delete\x18\x17 \x01(\v2\x13.saasapi.TaskDeleteH\x00R\n" + "taskDelete\x120\n" + - "\ttask_info\x18\x18 \x01(\v2\x11.saasapi.TaskInfoH\x00R\btaskInfo\x12&\n" + - "\x05debug\x18\x1e \x01(\v2\x0e.saasapi.DebugH\x00R\x05debugB\x05\n" + + "\ttask_info\x18\x18 \x01(\v2\x11.saasapi.TaskInfoH\x00R\btaskInfo\x126\n" + + "\vtarget_list\x182 \x01(\v2\x13.saasapi.TargetListH\x00R\n" + + "targetList\x12-\n" + + "\bbind_set\x18= \x01(\v2\x10.saasapi.BindSetH\x00R\abindSet\x126\n" + + "\vbind_delete\x18> \x01(\v2\x13.saasapi.BindDeleteH\x00R\n" + + "bindDelete\x12&\n" + + "\x05debug\x18Z \x01(\v2\x0e.saasapi.DebugH\x00R\x05debugB\x05\n" + "\x03cmd\"q\n" + "\x04Read\x12!\n" + "\fdataspace_id\x18\x01 \x01(\tR\vdataspaceId\x12\x14\n" + @@ -2081,7 +2790,16 @@ const file_cmd_proto_rawDesc = "" + "\tFileBlock\x12!\n" + "\fblock_sha256\x18\x01 \x01(\tR\vblockSha256\x12!\n" + "\fblock_length\x18\x02 \x01(\x04R\vblockLength\x12\x1a\n" + - "\buploaded\x18\x03 \x01(\bR\buploaded\"\xa2\x02\n" + + "\buploaded\x18\x03 \x01(\bR\buploaded\"C\n" + + "\n" + + "TargetList\x12\x18\n" + + "\atargets\x18\x01 \x03(\tR\atargets\x12\x1b\n" + + "\tlist_bind\x18\x02 \x01(\bR\blistBind\".\n" + + "\aBindSet\x12#\n" + + "\x05binds\x18\x02 \x03(\v2\r.saasapi.BindR\x05binds\"1\n" + + "\n" + + "BindDelete\x12#\n" + + "\x05binds\x18\x02 \x03(\v2\r.saasapi.BindR\x05binds\"\xa2\x02\n" + "\x05Debug\x12\x1d\n" + "\n" + "lua_script\x18\x01 \x01(\tR\tluaScript\x12&\n" + @@ -2091,7 +2809,7 @@ const file_cmd_proto_rawDesc = "" + "\x05appid\x18\x04 \x01(\tR\x05appid\x12#\n" + "\rserver_openid\x18\x05 \x01(\tR\fserverOpenid\x128\n" + "\x0elocal_did_data\x18\x06 \x01(\v2\x12.saasapi.WriteItemR\flocalDidData\x12>\n" + - "\x11local_openid_data\x18\a \x01(\v2\x12.saasapi.WriteItemR\x0flocalOpenidData\"\xc7\x03\n" + + "\x11local_openid_data\x18\a \x01(\v2\x12.saasapi.WriteItemR\x0flocalOpenidData\"\x84\x05\n" + "\aSaasRes\x12&\n" + "\x04code\x18\x01 \x01(\x0e2\x12.saasapi.ErrorCodeR\x04code\x12\x16\n" + "\x06status\x18\x02 \x01(\tR\x06status\x12-\n" + @@ -2103,7 +2821,11 @@ const file_cmd_proto_rawDesc = "" + "\ftask_run_res\x18\x16 \x01(\v2\r.saasapi.TaskH\x00R\n" + "taskRunRes\x127\n" + "\x0ftask_delete_res\x18\x17 \x01(\v2\r.saasapi.TaskH\x00R\rtaskDeleteRes\x123\n" + - "\rtask_info_res\x18\x18 \x01(\v2\r.saasapi.TaskH\x00R\vtaskInfoResB\x05\n" + + "\rtask_info_res\x18\x18 \x01(\v2\r.saasapi.TaskH\x00R\vtaskInfoRes\x12@\n" + + "\x0ftarget_list_res\x182 \x01(\v2\x16.saasapi.TargetListResH\x00R\rtargetListRes\x127\n" + + "\fbind_set_res\x18= \x01(\v2\x13.saasapi.BindSetResH\x00R\n" + + "bindSetRes\x12@\n" + + "\x0fbind_delete_res\x18> \x01(\v2\x16.saasapi.BindDeleteResH\x00R\rbindDeleteResB\x05\n" + "\x03res\"\x82\x01\n" + "\aReadRes\x12$\n" + "\x0esucc_cmd_count\x18\x01 \x01(\rR\fsuccCmdCount\x12$\n" + @@ -2119,11 +2841,53 @@ const file_cmd_proto_rawDesc = "" + "\x11flags_with_expire\x18\x05 \x03(\v2\x17.saasapi.FlagWithExpireR\x0fflagsWithExpire\x12(\n" + "\x10last_modify_time\x18\x06 \x01(\rR\x0elastModifyTime\"2\n" + "\vTaskListRes\x12#\n" + - "\x05tasks\x18\x01 \x03(\v2\r.saasapi.TaskR\x05tasks\"h\n" + + "\x05tasks\x18\x01 \x03(\v2\r.saasapi.TaskR\x05tasks\"\xa7\x01\n" + + "\rTargetListRes\x12G\n" + + "\vtarget_list\x18\x01 \x03(\v2&.saasapi.TargetListRes.TargetListEntryR\n" + + "targetList\x1aM\n" + + "\x0fTargetListEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12$\n" + + "\x05value\x18\x02 \x01(\v2\x0e.saasapi.BindsR\x05value:\x028\x01\",\n" + + "\x05Binds\x12#\n" + + "\x05binds\x18\x01 \x03(\v2\r.saasapi.BindR\x05binds\"\xc5\x01\n" + + "\x04Bind\x12\x17\n" + + "\abind_id\x18\x01 \x01(\x03R\x06bindId\x12.\n" + + "\tbind_type\x18\x02 \x01(\x0e2\x11.saasapi.BindTypeR\bbindType\x12\x1b\n" + + "\ttarget_id\x18\x03 \x01(\tR\btargetId\x12\x1d\n" + + "\n" + + "account_id\x18\x04 \x01(\x03R\taccountId\x128\n" + + "\vbind_source\x18\x05 \x01(\x0e2\x17.saasapi.BindSourceTypeR\n" + + "bindSource\"v\n" + + "\n" + + "BindSetRes\x12\x1f\n" + + "\vsuccess_num\x18\x01 \x01(\x05R\n" + + "successNum\x12\x1b\n" + + "\terror_num\x18\x02 \x01(\x05R\berrorNum\x12*\n" + + "\x06errors\x18\x03 \x03(\v2\x12.saasapi.BindErrorR\x06errors\"y\n" + + "\rBindDeleteRes\x12\x1f\n" + + "\vsuccess_num\x18\x01 \x01(\x05R\n" + + "successNum\x12\x1b\n" + + "\terror_num\x18\x02 \x01(\x05R\berrorNum\x12*\n" + + "\x06errors\x18\x03 \x03(\v2\x12.saasapi.BindErrorR\x06errors\"Y\n" + + "\tBindError\x12\x17\n" + + "\abind_id\x18\x01 \x01(\x03R\x06bindId\x12\x1b\n" + + "\tbind_type\x18\x02 \x01(\x05R\bbindType\x12\x16\n" + + "\x06reason\x18\x03 \x01(\tR\x06reason\"h\n" + "\bDebugRes\x12 \n" + "\vPrintOutput\x18\x01 \x01(\tR\vPrintOutput\x12\x14\n" + "\x05Error\x18\x02 \x01(\tR\x05Error\x12$\n" + - "\rTargetsOutput\x18\x03 \x01(\tR\rTargetsOutput*\xea\x03\n" + + "\rTargetsOutput\x18\x03 \x01(\tR\rTargetsOutput*=\n" + + "\bBindType\x12\x13\n" + + "\x0fUnknownBindType\x10\x00\x12\r\n" + + "\tAdgroupId\x10\x01\x12\r\n" + + "\tAccountId\x10\x03*[\n" + + "\x0eBindSourceType\x12\x19\n" + + "\x15DefaultBindSourceType\x10\x00\x12\x11\n" + + "\rThirdPartyApi\x10\x01\x12\a\n" + + "\x03ADQ\x10\x02\x12\x06\n" + + "\x02MP\x10\x03\x12\n" + + "\n" + + "\x06MktApi\x10\x04*\xfa\x03\n" + "\tErrorCode\x12\b\n" + "\x04SUCC\x10\x00\x12\x13\n" + "\x0fINVALID_ACCOUNT\x10e\x12\x15\n" + @@ -2151,7 +2915,8 @@ const file_cmd_proto_rawDesc = "" + "\rTASK_FINISHED\x10\x85\x01\x12\x0f\n" + "\n" + "DATA_ERROR\x10\xc9\x01\x12\x0e\n" + - "\tCMD_ERROR\x10\xca\x01*\x16\n" + + "\tCMD_ERROR\x10\xca\x01\x12\x0e\n" + + "\tAPI_ERROR\x10\xad\x02*\x16\n" + "\fCmdErrorCode\x12\x06\n" + "\x02OK\x10\x00*^\n" + "\n" + @@ -2177,79 +2942,106 @@ func file_cmd_proto_rawDescGZIP() []byte { return file_cmd_proto_rawDescData } -var file_cmd_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_cmd_proto_msgTypes = make([]protoimpl.MessageInfo, 24) +var file_cmd_proto_enumTypes = make([]protoimpl.EnumInfo, 5) +var file_cmd_proto_msgTypes = make([]protoimpl.MessageInfo, 34) var file_cmd_proto_goTypes = []any{ - (ErrorCode)(0), // 0: saasapi.ErrorCode - (CmdErrorCode)(0), // 1: saasapi.CmdErrorCode - (TaskStatus)(0), // 2: saasapi.TaskStatus - (*SaasReq)(nil), // 3: saasapi.SaasReq - (*Read)(nil), // 4: saasapi.Read - (*ReadItem)(nil), // 5: saasapi.ReadItem - (*Write)(nil), // 6: saasapi.Write - (*WriteItem)(nil), // 7: saasapi.WriteItem - (*Bytes)(nil), // 8: saasapi.Bytes - (*Uint32S)(nil), // 9: saasapi.Uint32s - (*FlagsWithExpire)(nil), // 10: saasapi.FlagsWithExpire - (*FlagWithExpire)(nil), // 11: saasapi.FlagWithExpire - (*ColumnWrite)(nil), // 12: saasapi.ColumnWrite - (*Task)(nil), // 13: saasapi.Task - (*TaskList)(nil), // 14: saasapi.TaskList - (*TaskRun)(nil), // 15: saasapi.TaskRun - (*TaskDelete)(nil), // 16: saasapi.TaskDelete - (*TaskInfo)(nil), // 17: saasapi.TaskInfo - (*FileInfo)(nil), // 18: saasapi.FileInfo - (*FileBlock)(nil), // 19: saasapi.FileBlock - (*Debug)(nil), // 20: saasapi.Debug - (*SaasRes)(nil), // 21: saasapi.SaasRes - (*ReadRes)(nil), // 22: saasapi.ReadRes - (*WriteRes)(nil), // 23: saasapi.WriteRes - (*ValueItem)(nil), // 24: saasapi.ValueItem - (*TaskListRes)(nil), // 25: saasapi.TaskListRes - (*DebugRes)(nil), // 26: saasapi.DebugRes + (BindType)(0), // 0: saasapi.BindType + (BindSourceType)(0), // 1: saasapi.BindSourceType + (ErrorCode)(0), // 2: saasapi.ErrorCode + (CmdErrorCode)(0), // 3: saasapi.CmdErrorCode + (TaskStatus)(0), // 4: saasapi.TaskStatus + (*SaasReq)(nil), // 5: saasapi.SaasReq + (*Read)(nil), // 6: saasapi.Read + (*ReadItem)(nil), // 7: saasapi.ReadItem + (*Write)(nil), // 8: saasapi.Write + (*WriteItem)(nil), // 9: saasapi.WriteItem + (*Bytes)(nil), // 10: saasapi.Bytes + (*Uint32S)(nil), // 11: saasapi.Uint32s + (*FlagsWithExpire)(nil), // 12: saasapi.FlagsWithExpire + (*FlagWithExpire)(nil), // 13: saasapi.FlagWithExpire + (*ColumnWrite)(nil), // 14: saasapi.ColumnWrite + (*Task)(nil), // 15: saasapi.Task + (*TaskList)(nil), // 16: saasapi.TaskList + (*TaskRun)(nil), // 17: saasapi.TaskRun + (*TaskDelete)(nil), // 18: saasapi.TaskDelete + (*TaskInfo)(nil), // 19: saasapi.TaskInfo + (*FileInfo)(nil), // 20: saasapi.FileInfo + (*FileBlock)(nil), // 21: saasapi.FileBlock + (*TargetList)(nil), // 22: saasapi.TargetList + (*BindSet)(nil), // 23: saasapi.BindSet + (*BindDelete)(nil), // 24: saasapi.BindDelete + (*Debug)(nil), // 25: saasapi.Debug + (*SaasRes)(nil), // 26: saasapi.SaasRes + (*ReadRes)(nil), // 27: saasapi.ReadRes + (*WriteRes)(nil), // 28: saasapi.WriteRes + (*ValueItem)(nil), // 29: saasapi.ValueItem + (*TaskListRes)(nil), // 30: saasapi.TaskListRes + (*TargetListRes)(nil), // 31: saasapi.TargetListRes + (*Binds)(nil), // 32: saasapi.Binds + (*Bind)(nil), // 33: saasapi.Bind + (*BindSetRes)(nil), // 34: saasapi.BindSetRes + (*BindDeleteRes)(nil), // 35: saasapi.BindDeleteRes + (*BindError)(nil), // 36: saasapi.BindError + (*DebugRes)(nil), // 37: saasapi.DebugRes + nil, // 38: saasapi.TargetListRes.TargetListEntry } var file_cmd_proto_depIdxs = []int32{ - 4, // 0: saasapi.SaasReq.read:type_name -> saasapi.Read - 6, // 1: saasapi.SaasReq.write:type_name -> saasapi.Write - 12, // 2: saasapi.SaasReq.column_write:type_name -> saasapi.ColumnWrite - 13, // 3: saasapi.SaasReq.task_create:type_name -> saasapi.Task - 14, // 4: saasapi.SaasReq.task_list:type_name -> saasapi.TaskList - 15, // 5: saasapi.SaasReq.task_run:type_name -> saasapi.TaskRun - 16, // 6: saasapi.SaasReq.task_delete:type_name -> saasapi.TaskDelete - 17, // 7: saasapi.SaasReq.task_info:type_name -> saasapi.TaskInfo - 20, // 8: saasapi.SaasReq.debug:type_name -> saasapi.Debug - 5, // 9: saasapi.Read.read_items:type_name -> saasapi.ReadItem - 7, // 10: saasapi.Write.write_items:type_name -> saasapi.WriteItem - 8, // 11: saasapi.WriteItem.write_bytes:type_name -> saasapi.Bytes - 9, // 12: saasapi.WriteItem.write_uint32s:type_name -> saasapi.Uint32s - 10, // 13: saasapi.WriteItem.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire - 11, // 14: saasapi.FlagsWithExpire.flags_with_expire:type_name -> saasapi.FlagWithExpire - 8, // 15: saasapi.ColumnWrite.write_bytes:type_name -> saasapi.Bytes - 9, // 16: saasapi.ColumnWrite.write_uint32s:type_name -> saasapi.Uint32s - 10, // 17: saasapi.ColumnWrite.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire - 18, // 18: saasapi.Task.task_file_infos:type_name -> saasapi.FileInfo - 2, // 19: saasapi.Task.status:type_name -> saasapi.TaskStatus - 2, // 20: saasapi.TaskList.status_filter:type_name -> saasapi.TaskStatus - 19, // 21: saasapi.FileInfo.file_blocks:type_name -> saasapi.FileBlock - 7, // 22: saasapi.Debug.local_did_data:type_name -> saasapi.WriteItem - 7, // 23: saasapi.Debug.local_openid_data:type_name -> saasapi.WriteItem - 0, // 24: saasapi.SaasRes.code:type_name -> saasapi.ErrorCode - 22, // 25: saasapi.SaasRes.read_res:type_name -> saasapi.ReadRes - 23, // 26: saasapi.SaasRes.write_res:type_name -> saasapi.WriteRes - 13, // 27: saasapi.SaasRes.task_create_res:type_name -> saasapi.Task - 25, // 28: saasapi.SaasRes.task_list_res:type_name -> saasapi.TaskListRes - 13, // 29: saasapi.SaasRes.task_run_res:type_name -> saasapi.Task - 13, // 30: saasapi.SaasRes.task_delete_res:type_name -> saasapi.Task - 13, // 31: saasapi.SaasRes.task_info_res:type_name -> saasapi.Task - 24, // 32: saasapi.ReadRes.cmd_res:type_name -> saasapi.ValueItem - 1, // 33: saasapi.ValueItem.cmd_code:type_name -> saasapi.CmdErrorCode - 11, // 34: saasapi.ValueItem.flags_with_expire:type_name -> saasapi.FlagWithExpire - 13, // 35: saasapi.TaskListRes.tasks:type_name -> saasapi.Task - 36, // [36:36] is the sub-list for method output_type - 36, // [36:36] is the sub-list for method input_type - 36, // [36:36] is the sub-list for extension type_name - 36, // [36:36] is the sub-list for extension extendee - 0, // [0:36] is the sub-list for field type_name + 6, // 0: saasapi.SaasReq.read:type_name -> saasapi.Read + 8, // 1: saasapi.SaasReq.write:type_name -> saasapi.Write + 14, // 2: saasapi.SaasReq.column_write:type_name -> saasapi.ColumnWrite + 15, // 3: saasapi.SaasReq.task_create:type_name -> saasapi.Task + 16, // 4: saasapi.SaasReq.task_list:type_name -> saasapi.TaskList + 17, // 5: saasapi.SaasReq.task_run:type_name -> saasapi.TaskRun + 18, // 6: saasapi.SaasReq.task_delete:type_name -> saasapi.TaskDelete + 19, // 7: saasapi.SaasReq.task_info:type_name -> saasapi.TaskInfo + 22, // 8: saasapi.SaasReq.target_list:type_name -> saasapi.TargetList + 23, // 9: saasapi.SaasReq.bind_set:type_name -> saasapi.BindSet + 24, // 10: saasapi.SaasReq.bind_delete:type_name -> saasapi.BindDelete + 25, // 11: saasapi.SaasReq.debug:type_name -> saasapi.Debug + 7, // 12: saasapi.Read.read_items:type_name -> saasapi.ReadItem + 9, // 13: saasapi.Write.write_items:type_name -> saasapi.WriteItem + 10, // 14: saasapi.WriteItem.write_bytes:type_name -> saasapi.Bytes + 11, // 15: saasapi.WriteItem.write_uint32s:type_name -> saasapi.Uint32s + 12, // 16: saasapi.WriteItem.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire + 13, // 17: saasapi.FlagsWithExpire.flags_with_expire:type_name -> saasapi.FlagWithExpire + 10, // 18: saasapi.ColumnWrite.write_bytes:type_name -> saasapi.Bytes + 11, // 19: saasapi.ColumnWrite.write_uint32s:type_name -> saasapi.Uint32s + 12, // 20: saasapi.ColumnWrite.write_flags_with_expire:type_name -> saasapi.FlagsWithExpire + 20, // 21: saasapi.Task.task_file_infos:type_name -> saasapi.FileInfo + 4, // 22: saasapi.Task.status:type_name -> saasapi.TaskStatus + 4, // 23: saasapi.TaskList.status_filter:type_name -> saasapi.TaskStatus + 21, // 24: saasapi.FileInfo.file_blocks:type_name -> saasapi.FileBlock + 33, // 25: saasapi.BindSet.binds:type_name -> saasapi.Bind + 33, // 26: saasapi.BindDelete.binds:type_name -> saasapi.Bind + 9, // 27: saasapi.Debug.local_did_data:type_name -> saasapi.WriteItem + 9, // 28: saasapi.Debug.local_openid_data:type_name -> saasapi.WriteItem + 2, // 29: saasapi.SaasRes.code:type_name -> saasapi.ErrorCode + 27, // 30: saasapi.SaasRes.read_res:type_name -> saasapi.ReadRes + 28, // 31: saasapi.SaasRes.write_res:type_name -> saasapi.WriteRes + 15, // 32: saasapi.SaasRes.task_create_res:type_name -> saasapi.Task + 30, // 33: saasapi.SaasRes.task_list_res:type_name -> saasapi.TaskListRes + 15, // 34: saasapi.SaasRes.task_run_res:type_name -> saasapi.Task + 15, // 35: saasapi.SaasRes.task_delete_res:type_name -> saasapi.Task + 15, // 36: saasapi.SaasRes.task_info_res:type_name -> saasapi.Task + 31, // 37: saasapi.SaasRes.target_list_res:type_name -> saasapi.TargetListRes + 34, // 38: saasapi.SaasRes.bind_set_res:type_name -> saasapi.BindSetRes + 35, // 39: saasapi.SaasRes.bind_delete_res:type_name -> saasapi.BindDeleteRes + 29, // 40: saasapi.ReadRes.cmd_res:type_name -> saasapi.ValueItem + 3, // 41: saasapi.ValueItem.cmd_code:type_name -> saasapi.CmdErrorCode + 13, // 42: saasapi.ValueItem.flags_with_expire:type_name -> saasapi.FlagWithExpire + 15, // 43: saasapi.TaskListRes.tasks:type_name -> saasapi.Task + 38, // 44: saasapi.TargetListRes.target_list:type_name -> saasapi.TargetListRes.TargetListEntry + 33, // 45: saasapi.Binds.binds:type_name -> saasapi.Bind + 0, // 46: saasapi.Bind.bind_type:type_name -> saasapi.BindType + 1, // 47: saasapi.Bind.bind_source:type_name -> saasapi.BindSourceType + 36, // 48: saasapi.BindSetRes.errors:type_name -> saasapi.BindError + 36, // 49: saasapi.BindDeleteRes.errors:type_name -> saasapi.BindError + 32, // 50: saasapi.TargetListRes.TargetListEntry.value:type_name -> saasapi.Binds + 51, // [51:51] is the sub-list for method output_type + 51, // [51:51] is the sub-list for method input_type + 51, // [51:51] is the sub-list for extension type_name + 51, // [51:51] is the sub-list for extension extendee + 0, // [0:51] is the sub-list for field type_name } func init() { file_cmd_proto_init() } @@ -2266,9 +3058,12 @@ func file_cmd_proto_init() { (*SaasReq_TaskRun)(nil), (*SaasReq_TaskDelete)(nil), (*SaasReq_TaskInfo)(nil), + (*SaasReq_TargetList)(nil), + (*SaasReq_BindSet)(nil), + (*SaasReq_BindDelete)(nil), (*SaasReq_Debug)(nil), } - file_cmd_proto_msgTypes[18].OneofWrappers = []any{ + file_cmd_proto_msgTypes[21].OneofWrappers = []any{ (*SaasRes_ReadRes)(nil), (*SaasRes_WriteRes)(nil), (*SaasRes_TaskCreateRes)(nil), @@ -2276,14 +3071,17 @@ func file_cmd_proto_init() { (*SaasRes_TaskRunRes)(nil), (*SaasRes_TaskDeleteRes)(nil), (*SaasRes_TaskInfoRes)(nil), + (*SaasRes_TargetListRes)(nil), + (*SaasRes_BindSetRes)(nil), + (*SaasRes_BindDeleteRes)(nil), } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_cmd_proto_rawDesc), len(file_cmd_proto_rawDesc)), - NumEnums: 3, - NumMessages: 24, + NumEnums: 5, + NumMessages: 34, NumExtensions: 0, NumServices: 0, }, diff --git a/cmd.proto b/cmd.proto index 9f40bda..9570806 100644 --- a/cmd.proto +++ b/cmd.proto @@ -17,7 +17,12 @@ message SaasReq { TaskDelete task_delete = 23; // 删除任务 TaskInfo task_info = 24; // 任务详情 - Debug debug = 30; // 试运行lua脚本 + TargetList target_list = 50; // 列出策略及绑定 + + BindSet bind_set = 61; // 设置绑定 + BindDelete bind_delete = 62; // 解除绑定 + + Debug debug = 90; // 试运行lua脚本 } } @@ -123,18 +128,37 @@ message TaskInfo { string task_sha256 = 1; // 任务sha256 } +// FileInfo 任务文件信息 message FileInfo { string file_name = 1; // 文件名 uint64 file_size = 2; // 文件大小 repeated FileBlock file_blocks = 3; // 文件块列表 } +// FileBlock 文件块信息 message FileBlock { string block_sha256 = 1; // 块的sha256 uint64 block_length = 2; // 块的字节长度 bool uploaded = 3; // 是否已上传(在TaskCreate/TaskInfo请求返回) } +// TargetList 列出策略 +message TargetList { + repeated string targets = 1; // 指定要列出的绑定的策略列表,如不指定则返回全部 + bool list_bind = 2; // 是否同时列出绑定信息 +} + +// BindSet 设置绑定 +message BindSet { + repeated Bind binds = 2; // 设置绑定内容 +} + +// BindDelete 删除绑定 +message BindDelete { + repeated Bind binds = 2; // 解除绑定内容 +} + +// Debug 调试 message Debug { string lua_script = 1; // 要调试的lua脚本 bool use_server_data = 2; // 是否使用服务端用户数据 @@ -158,15 +182,22 @@ message SaasRes { Task task_run_res = 22; // 运行任务返回状态 Task task_delete_res = 23; // 删除任务返回状态 Task task_info_res = 24; // 任务详情返回状态 + + TargetListRes target_list_res = 50; // 列出策略及绑定返回状态 + + BindSetRes bind_set_res = 61; // 设置绑定返回状态 + BindDeleteRes bind_delete_res = 62; // 删除绑定返回状态 } } +// ReadRes 读记录返回 message ReadRes { uint32 succ_cmd_count = 1; // 成功的命令数量 uint32 fail_cmd_count = 2; // 失败的命令数量 repeated ValueItem cmd_res = 3; // 返回的命令 } +// WriteRes 写记录返回 message WriteRes { //uint32 succ_cmd_count = 1; // 成功的命令数量 //uint32 fail_cmd_count = 2; // 失败的命令数量 @@ -183,10 +214,69 @@ message ValueItem { uint32 last_modify_time = 6; // 最后修改时间 } +// TaskListRes 任务列表返回 message TaskListRes { repeated Task tasks = 1; // 任务列表 } +// TargetListRes 策略列表返回 +message TargetListRes { + map target_list = 1; // 绑定列表 +} + +message Binds { + repeated Bind binds = 1; +} + +// Bind 绑定信息 +message Bind { + int64 bind_id = 1; //绑定的ID + BindType bind_type = 2; //绑定类型 + string target_id = 3; //策略ID + int64 account_id = 4; //广告主ID + BindSourceType bind_source = 5; //绑定操作来源 +} + + +// BindType 绑定类型 +enum BindType { + UnknownBindType = 0; + AdgroupId = 1; //广告 + AccountId = 3; //广告主 +} + +// BindSourceType 绑定操作来源 +enum BindSourceType { + DefaultBindSourceType = 0; //广告主或未填写 + ThirdPartyApi = 1; //第三方API + ADQ = 2; //ADQ平台 + MP = 3; //MP平台 + MktApi = 4; //MarketingAPI +} + +// BindSetRes 设置绑定返回 +message BindSetRes { + int32 success_num = 1; //成功数 + int32 error_num = 2; //错误数 + repeated BindError errors = 3; //绑定错误的记录 +} + +// BindDeleteRes 删除绑定返回 +message BindDeleteRes { + int32 success_num = 1; //成功数 + int32 error_num = 2; //错误数 + repeated BindError errors = 3; //绑定错误的记录 +} + +// BindError 绑定错误信息 +message BindError { + int64 bind_id = 1; //错误绑定的绑定ID + int32 bind_type = 2; //绑定类型 + string reason = 3; //错误绑定原因 +} + + +// DebugRes 调试返回 message DebugRes { string PrintOutput = 1; // print输出 string Error = 2; // 错误信息 @@ -224,6 +314,8 @@ enum ErrorCode { DATA_ERROR = 201; // 数据错误 CMD_ERROR = 202; // 命令行执行错误 + + API_ERROR = 301; // 调用内部API错误 } enum CmdErrorCode { diff --git a/cmd/saastool/bind.go b/cmd/saastool/bind.go new file mode 100644 index 0000000..95e0b55 --- /dev/null +++ b/cmd/saastool/bind.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "os" + "strings" +) + +func RunBind(args ...string) error { + name, args := ParseCommandName(args) + + // 从参数中解析出命令 + switch name { + case "", "help": + return RunBindHelp(args...) + case "setaccount": + return RunBindSetAccount(args...) + case "setad": + return RunBindSetAd(args...) + case "delete": + return RunBindDelete(args...) + default: + err := fmt.Errorf(`unknown command "%s"`+"\n"+`Run 'saastool bind help' for usage`, name) + fmt.Fprintln(os.Stderr, err) + + return err + } +} + +func RunBindHelp(args ...string) error { + fmt.Println(strings.TrimSpace(bindUsage)) + return nil +} + +const bindUsage = ` +Usage: saastoola bind COMMAND [OPTIONS] + +Commands: + setaccount Set Account binds + setad Set AdGroup binds + delete Delete binds + +"help" is the default command. + +Use "saastool bind COMMAND -help" for more information about a command. +` diff --git a/cmd/saastool/bind_delete.go b/cmd/saastool/bind_delete.go new file mode 100644 index 0000000..f9a2869 --- /dev/null +++ b/cmd/saastool/bind_delete.go @@ -0,0 +1,105 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" + "strconv" + "strings" + + "e.coding.net/rta/public/saasapi" + "e.coding.net/rta/public/saasapi/pkg/saashttp" + "google.golang.org/protobuf/encoding/protojson" +) + +type bindDeleteParams struct { + idType int + ids []int64 + saasHttp *saashttp.SaasClient +} + +func RunBindDelete(args ...string) error { + fs := flag.NewFlagSet("delete", flag.ExitOnError) + cfgFile := paramConfig(fs) + idtype := paramIdType(fs) + ids := paramIDs(fs) + + if err := fs.Parse(args); err != nil { + fmt.Fprintln(os.Stderr, "command line parse error", "err", err) + return err + } + + // 切割字符串 + idsSlice := strings.Split(*ids, ",") + if len(idsSlice) == 1 && idsSlice[0] == "" { + idsSlice = []string{} + } + + if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") { + fs.PrintDefaults() + return nil + } + + numIds := []int64{} + for _, v := range idsSlice { + n, err := strconv.ParseInt(v, 10, 64) + if err != nil { + fmt.Fprintln(os.Stderr, "id parse error", "value", v, "err", err) + return err + } + numIds = append(numIds, n) + } + + cfg, err := LoadConfigFile(*cfgFile) + if err != nil { + fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err) + return err + } + + bindDeleteParams := bindDeleteParams{ + idType: *idtype, + ids: numIds, + saasHttp: &saashttp.SaasClient{ + Client: &http.Client{}, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), + Auth: &cfg.Auth, + }, + } + + return doBindDeleteAccount(bindDeleteParams) +} + +func doBindDeleteAccount(p bindDeleteParams) error { + bindDelete := &saasapi.BindDelete{} + + saasReq := &saasapi.SaasReq{ + Cmd: &saasapi.SaasReq_BindDelete{ + BindDelete: bindDelete, + }, + } + + for _, v := range p.ids { + bindDelete.Binds = append(bindDelete.Binds, &saasapi.Bind{ + BindId: v, + BindType: saasapi.BindType(p.idType), + }) + } + + res, err := p.saasHttp.BindDelete(saasReq) + + if err != nil { + fmt.Fprintln(os.Stderr, "submit Bind Delete error", "err", err) + return err + } + + if res.Code != saasapi.ErrorCode_SUCC { + fmt.Fprintln(os.Stderr, "Bind Delete failed", "code", res.Code, "status", res.Status) + return nil + } + + bindRes := res.GetBindDeleteRes() + + fmt.Printf("bind res: %v\n", protojson.Format(bindRes)) + return nil +} diff --git a/cmd/saastool/bind_setaccount.go b/cmd/saastool/bind_setaccount.go new file mode 100644 index 0000000..342f644 --- /dev/null +++ b/cmd/saastool/bind_setaccount.go @@ -0,0 +1,107 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" + "strconv" + "strings" + + "e.coding.net/rta/public/saasapi" + "e.coding.net/rta/public/saasapi/pkg/saashttp" + "google.golang.org/protobuf/encoding/protojson" +) + +type bindSetAccountParams struct { + target string + accounts []int64 + saasHttp *saashttp.SaasClient +} + +func RunBindSetAccount(args ...string) error { + fs := flag.NewFlagSet("setaccount", flag.ExitOnError) + cfgFile := paramConfig(fs) + target := paramTarget(fs) + accounts := paramAccounts(fs) + + if err := fs.Parse(args); err != nil { + fmt.Fprintln(os.Stderr, "command line parse error", "err", err) + return err + } + + // 切割字符串 + idsSlice := strings.Split(*accounts, ",") + if len(idsSlice) == 1 && idsSlice[0] == "" { + idsSlice = []string{} + } + + if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") { + fs.PrintDefaults() + return nil + } + + numAccounts := []int64{} + for _, v := range idsSlice { + n, err := strconv.ParseInt(v, 10, 64) + if err != nil { + fmt.Fprintln(os.Stderr, "account parse error", "value", v, "err", err) + return err + } + numAccounts = append(numAccounts, n) + } + + cfg, err := LoadConfigFile(*cfgFile) + if err != nil { + fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err) + return err + } + + bindSetAccountParams := bindSetAccountParams{ + target: *target, + accounts: numAccounts, + saasHttp: &saashttp.SaasClient{ + Client: &http.Client{}, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), + Auth: &cfg.Auth, + }, + } + + return doBindSetAccount(bindSetAccountParams) +} + +func doBindSetAccount(p bindSetAccountParams) error { + bindSet := &saasapi.BindSet{} + + saasReq := &saasapi.SaasReq{ + Cmd: &saasapi.SaasReq_BindSet{ + BindSet: bindSet, + }, + } + + for _, v := range p.accounts { + bindSet.Binds = append(bindSet.Binds, &saasapi.Bind{ + BindId: v, + BindType: saasapi.BindType_AccountId, + TargetId: p.target, + AccountId: v, + }) + } + + res, err := p.saasHttp.BindSet(saasReq) + + if err != nil { + fmt.Fprintln(os.Stderr, "submit Bind Set error", "err", err) + return err + } + + if res.Code != saasapi.ErrorCode_SUCC { + fmt.Fprintln(os.Stderr, "Bind Set failed", "code", res.Code, "status", res.Status) + return nil + } + + bindRes := res.GetBindSetRes() + + fmt.Printf("bind res: %v\n", protojson.Format(bindRes)) + return nil +} diff --git a/cmd/saastool/bind_setad.go b/cmd/saastool/bind_setad.go new file mode 100644 index 0000000..db47999 --- /dev/null +++ b/cmd/saastool/bind_setad.go @@ -0,0 +1,110 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" + "strconv" + "strings" + + "e.coding.net/rta/public/saasapi" + "e.coding.net/rta/public/saasapi/pkg/saashttp" + "google.golang.org/protobuf/encoding/protojson" +) + +type bindSetAdParams struct { + target string + account int64 + ads []int64 + saasHttp *saashttp.SaasClient +} + +func RunBindSetAd(args ...string) error { + fs := flag.NewFlagSet("setad", flag.ExitOnError) + cfgFile := paramConfig(fs) + target := paramTarget(fs) + account := paramAccount(fs) + ads := paramAds(fs) + + if err := fs.Parse(args); err != nil { + fmt.Fprintln(os.Stderr, "command line parse error", "err", err) + return err + } + + // 切割字符串 + idsSlice := strings.Split(*ads, ",") + if len(idsSlice) == 1 && idsSlice[0] == "" { + idsSlice = []string{} + } + + if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") { + fs.PrintDefaults() + return nil + } + + numAds := []int64{} + for _, v := range idsSlice { + n, err := strconv.ParseInt(v, 10, 64) + if err != nil { + fmt.Fprintln(os.Stderr, "account parse error", "value", v, "err", err) + return err + } + numAds = append(numAds, n) + } + + cfg, err := LoadConfigFile(*cfgFile) + if err != nil { + fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err) + return err + } + + bindSetAdParams := bindSetAdParams{ + target: *target, + account: *account, + ads: numAds, + saasHttp: &saashttp.SaasClient{ + Client: &http.Client{}, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), + Auth: &cfg.Auth, + }, + } + + return doBindSetAd(bindSetAdParams) +} + +func doBindSetAd(p bindSetAdParams) error { + bindSet := &saasapi.BindSet{} + + saasReq := &saasapi.SaasReq{ + Cmd: &saasapi.SaasReq_BindSet{ + BindSet: bindSet, + }, + } + + for _, v := range p.ads { + bindSet.Binds = append(bindSet.Binds, &saasapi.Bind{ + BindId: v, + BindType: saasapi.BindType_AdgroupId, + TargetId: p.target, + AccountId: p.account, + }) + } + + res, err := p.saasHttp.BindSet(saasReq) + + if err != nil { + fmt.Fprintln(os.Stderr, "submit Bind Set error", "err", err) + return err + } + + if res.Code != saasapi.ErrorCode_SUCC { + fmt.Fprintln(os.Stderr, "Bind Set failed", "code", res.Code, "status", res.Status) + return nil + } + + bindRes := res.GetBindSetRes() + + fmt.Printf("bind res: %v\n", protojson.Format(bindRes)) + return nil +} diff --git a/cmd/saastool/help.go b/cmd/saastool/help.go index c65c8dd..5985e42 100644 --- a/cmd/saastool/help.go +++ b/cmd/saastool/help.go @@ -21,7 +21,9 @@ Commands: convert Convert data to write format - task Task commands + task Task commands + target Target commands + bind Bind commands "help" is the default command. diff --git a/cmd/saastool/main.go b/cmd/saastool/main.go index b368098..43e8ef8 100644 --- a/cmd/saastool/main.go +++ b/cmd/saastool/main.go @@ -30,6 +30,10 @@ func Run(args ...string) error { return RunVerify(args...) case "task": return RunTask(args...) + case "target": + return RunTarget(args...) + case "bind": + return RunBind(args...) default: err := fmt.Errorf(`unknown command "%v"`+"\n"+`Run 'saastool help' for usage`, name) fmt.Fprintln(os.Stderr, err.Error()) diff --git a/cmd/saastool/params.go b/cmd/saastool/params.go index 414855a..514d971 100644 --- a/cmd/saastool/params.go +++ b/cmd/saastool/params.go @@ -73,6 +73,38 @@ func paramDataSpaceId(fs *flag.FlagSet) *string { return fs.String("ds", "", "Data space ID") } +func paramTargets(fs *flag.FlagSet) *string { + return fs.String("targets", "", "Target IDs. Use commas to separate multiple IDs") +} + +func paramListBinds(fs *flag.FlagSet) *bool { + return fs.Bool("b", false, "List Binds") +} + +func paramTarget(fs *flag.FlagSet) *string { + return fs.String("target", "", "Target ID") +} + +func paramAccount(fs *flag.FlagSet) *int64 { + return fs.Int64("account", 0, "Advertiser ID") +} + +func paramAccounts(fs *flag.FlagSet) *string { + return fs.String("accounts", "", "Advertiser IDs. Use commas to separate multiple IDs") +} + +func paramAds(fs *flag.FlagSet) *string { + return fs.String("ads", "", "AdGroup IDs. Use commas to separate multiple IDs") +} + +func paramIdType(fs *flag.FlagSet) *int { + return fs.Int("idtype", 0, "ID Type. empty is Automatic matching, 1=AdGroup, 3=Account") +} + +func paramIDs(fs *flag.FlagSet) *string { + return fs.String("ids", "", "IDs for delete. Use commas to separate multiple IDs") +} + // ParseByteSize 解析字节大小字符串为字节数 func ParseByteSize(sizeStr string) (uint64, error) { sizeStr = strings.TrimSpace(sizeStr) diff --git a/cmd/saastool/read.go b/cmd/saastool/read.go index bb3650d..21c43fc 100644 --- a/cmd/saastool/read.go +++ b/cmd/saastool/read.go @@ -62,7 +62,7 @@ func RunRead(args ...string) error { ds: *ds, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/target.go b/cmd/saastool/target.go new file mode 100644 index 0000000..752af16 --- /dev/null +++ b/cmd/saastool/target.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "os" + "strings" +) + +func RunTarget(args ...string) error { + name, args := ParseCommandName(args) + + // 从参数中解析出命令 + switch name { + case "", "help": + return RunTargetHelp(args...) + case "list": + return RunTargetList(args...) + default: + err := fmt.Errorf(`unknown command "%s"`+"\n"+`Run 'saastool target help' for usage`, name) + fmt.Fprintln(os.Stderr, err) + + return err + } +} + +func RunTargetHelp(args ...string) error { + fmt.Println(strings.TrimSpace(targetUsage)) + return nil +} + +const targetUsage = ` +Usage: saastoola target COMMAND [OPTIONS] + +Commands: + list List targets + +"help" is the default command. + +Use "saastool target COMMAND -help" for more information about a command. +` diff --git a/cmd/saastool/target_list.go b/cmd/saastool/target_list.go new file mode 100644 index 0000000..3231a77 --- /dev/null +++ b/cmd/saastool/target_list.go @@ -0,0 +1,88 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" + "strings" + + "e.coding.net/rta/public/saasapi" + "e.coding.net/rta/public/saasapi/pkg/saashttp" + "google.golang.org/protobuf/encoding/protojson" +) + +type listTargetParams struct { + targets []string + listBinds bool + saasHttp *saashttp.SaasClient +} + +func RunTargetList(args ...string) error { + fs := flag.NewFlagSet("list", flag.ExitOnError) + cfgFile := paramConfig(fs) + targets := paramTargets(fs) + listBinds := paramListBinds(fs) + + if err := fs.Parse(args); err != nil { + fmt.Fprintln(os.Stderr, "command line parse error", "err", err) + return err + } + + if fs.NArg() > 0 { + fs.PrintDefaults() + return nil + } + + // 切割字符串 + idsSlice := strings.Split(*targets, ",") + if len(idsSlice) == 1 && idsSlice[0] == "" { + idsSlice = []string{} + } + + cfg, err := LoadConfigFile(*cfgFile) + if err != nil { + fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err) + return err + } + + listTargetParams := listTargetParams{ + listBinds: *listBinds, + targets: idsSlice, + saasHttp: &saashttp.SaasClient{ + Client: &http.Client{}, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), + Auth: &cfg.Auth, + }, + } + + return doTargetList(listTargetParams) +} + +func doTargetList(listTargetParams listTargetParams) error { + saasReq := &saasapi.SaasReq{ + Cmd: &saasapi.SaasReq_TargetList{ + TargetList: &saasapi.TargetList{ + Targets: listTargetParams.targets, + ListBind: listTargetParams.listBinds, + }, + }, + } + + res, err := listTargetParams.saasHttp.TargetList(saasReq) + + if err != nil { + fmt.Fprintln(os.Stderr, "submit List Target error", "err", err) + return err + } + + if res.Code != saasapi.ErrorCode_SUCC { + fmt.Fprintln(os.Stderr, "Target list failed", "code", res.Code, "status", res.Status) + return nil + } + + targetRes := res.GetTargetListRes() + + fmt.Printf("target res: %v\n", protojson.Format(targetRes)) + return nil +} diff --git a/cmd/saastool/task_create.go b/cmd/saastool/task_create.go index 1afaf08..49930f3 100644 --- a/cmd/saastool/task_create.go +++ b/cmd/saastool/task_create.go @@ -42,7 +42,7 @@ func RunTaskCreate(args ...string) error { hashFile: *hashFile, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, task: &saasapi.Task{}, diff --git a/cmd/saastool/task_delete.go b/cmd/saastool/task_delete.go index adee3ad..187b56f 100644 --- a/cmd/saastool/task_delete.go +++ b/cmd/saastool/task_delete.go @@ -41,7 +41,7 @@ func RunTaskDelete(args ...string) error { taskSha256: *sha256, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/task_download.go b/cmd/saastool/task_download.go index 8cd5b8e..cd09667 100644 --- a/cmd/saastool/task_download.go +++ b/cmd/saastool/task_download.go @@ -44,7 +44,7 @@ func RunTaskDownload(args ...string) error { destPath: *destPath, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } @@ -63,7 +63,7 @@ func doTaskDownload(downloadTaskParams downloadTaskParams) error { } if len(taskInfo.GetSourcePath()) == 0 { - err = fmt.Errorf("task download failed. source path is empty") + err = fmt.Errorf("task download failed. task info source path is empty") fmt.Fprintln(os.Stderr, err) return err } diff --git a/cmd/saastool/task_info.go b/cmd/saastool/task_info.go index d5e7413..1ab4cef 100644 --- a/cmd/saastool/task_info.go +++ b/cmd/saastool/task_info.go @@ -41,7 +41,7 @@ func RunTaskInfo(args ...string) error { taskSha256: *sha256, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/task_list.go b/cmd/saastool/task_list.go index ce91000..776e3da 100644 --- a/cmd/saastool/task_list.go +++ b/cmd/saastool/task_list.go @@ -40,7 +40,7 @@ func RunTaskList(args ...string) error { listTaskParams := listTaskParams{ saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/task_run.go b/cmd/saastool/task_run.go index 265d4a6..2e22568 100644 --- a/cmd/saastool/task_run.go +++ b/cmd/saastool/task_run.go @@ -41,7 +41,7 @@ func RunTaskRun(args ...string) error { taskSha256: *sha256, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/task_upload.go b/cmd/saastool/task_upload.go index 04769c2..fc71bdf 100644 --- a/cmd/saastool/task_upload.go +++ b/cmd/saastool/task_upload.go @@ -41,7 +41,7 @@ func RunTaskUpload(args ...string) error { taskSha256: *sha256, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/cmd/saastool/write.go b/cmd/saastool/write.go index b6ce77b..7375cac 100644 --- a/cmd/saastool/write.go +++ b/cmd/saastool/write.go @@ -63,7 +63,7 @@ func RunWrite(args ...string) error { clear: *clear, saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, - ApiUrls: &cfg.ApiUrls, + ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } diff --git a/pkg/saashttp/cfg.go b/pkg/saashttp/cfg.go index d99adf7..98b211d 100644 --- a/pkg/saashttp/cfg.go +++ b/pkg/saashttp/cfg.go @@ -1,5 +1,23 @@ package saashttp +const ( + baseUrl = "https://api.rta.qq.com" + writePath = "/saas/write" + readPath = "/saas/read" + columnWritePath = "/saas/column_write" + taskCreatePath = "/saas/task/create" + taskListPath = "/saas/task/list" + taskCancelPath = "/saas/task/delete" + taskInfoPath = "/saas/task/info" + taskUploadPath = "/saas/task/upload" + taskDownloadPath = "/saas/task/download" + taskDeletePath = "/saas/task/delete" + taskRunPath = "/saas/task/run" + targetListPath = "/saas/target/list" + bindSetPath = "/saas/bind/set" + bindDeletePath = "/saas/bind/delete" +) + type ApiUrls struct { BaseUrl string WritePath string @@ -12,6 +30,98 @@ type ApiUrls struct { TaskRunPath string TaskUploadPath string TaskDownloadPath string + TargetListPath string + BindSetPath string + BindDeletePath string +} + +func InitAPIUrl(c *ApiUrls) *ApiUrls { + r := &ApiUrls{} + if c.BaseUrl != "" { + r.BaseUrl = c.BaseUrl + } else { + r.BaseUrl = baseUrl + } + + if c.WritePath != "" { + r.WritePath = c.WritePath + } else { + r.WritePath = writePath + } + + if c.ReadPath != "" { + r.ReadPath = c.ReadPath + } else { + r.ReadPath = readPath + } + + if c.ColumnWritePath != "" { + r.ColumnWritePath = c.ColumnWritePath + } else { + r.ColumnWritePath = columnWritePath + } + + if c.TaskCreatePath != "" { + r.TaskCreatePath = c.TaskCreatePath + } else { + r.TaskCreatePath = taskCreatePath + } + + if c.TaskListPath != "" { + r.TaskListPath = c.TaskListPath + } else { + r.TaskListPath = taskListPath + } + + if c.TaskInfoPath != "" { + r.TaskInfoPath = c.TaskInfoPath + } else { + r.TaskInfoPath = taskInfoPath + } + + if c.TaskDeletePath != "" { + r.TaskDeletePath = c.TaskDeletePath + } else { + r.TaskDeletePath = taskDeletePath + } + + if c.TaskRunPath != "" { + r.TaskRunPath = c.TaskRunPath + } else { + r.TaskRunPath = taskRunPath + } + + if c.TaskUploadPath != "" { + r.TaskUploadPath = c.TaskUploadPath + } else { + r.TaskUploadPath = taskUploadPath + } + + if c.TaskDownloadPath != "" { + r.TaskDownloadPath = c.TaskDownloadPath + } else { + r.TaskDownloadPath = taskDownloadPath + } + + if c.TargetListPath != "" { + r.TargetListPath = c.TargetListPath + } else { + r.TargetListPath = targetListPath + } + + if c.BindSetPath != "" { + r.BindSetPath = c.BindSetPath + } else { + r.BindSetPath = bindSetPath + } + + if c.BindDeletePath != "" { + r.BindDeletePath = c.BindDeletePath + } else { + r.BindDeletePath = bindDeletePath + } + + return r } type Auth struct { diff --git a/pkg/saashttp/httpcli.go b/pkg/saashttp/httpcli.go index e2d3afb..f401bcc 100644 --- a/pkg/saashttp/httpcli.go +++ b/pkg/saashttp/httpcli.go @@ -83,6 +83,21 @@ func (c *SaasClient) TaskDownload(sha256 string, file *os.File, offset int64, si return c.download(postUrl, file, offset, size) } +func (c *SaasClient) TargetList(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { + postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.TargetListPath) + return c.post(postUrl, saasReq) +} + +func (c *SaasClient) BindSet(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { + postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.BindSetPath) + return c.post(postUrl, saasReq) +} + +func (c *SaasClient) BindDelete(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) { + postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.BindDeletePath) + return c.post(postUrl, saasReq) +} + func (c *SaasClient) makeUrl(baseUrl, path string, params ...string) string { url, err := url.Parse(baseUrl) if err != nil {