增加策略列表、绑定、解绑

This commit is contained in:
algotao
2025-08-09 15:54:57 +08:00
parent 6ca9fe7a02
commit edb12c3b1f
22 changed files with 1674 additions and 125 deletions

1024
cmd.pb.go

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,12 @@ message SaasReq {
TaskDelete task_delete = 23; // 删除任务 TaskDelete task_delete = 23; // 删除任务
TaskInfo task_info = 24; // 任务详情 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 string task_sha256 = 1; // 任务sha256
} }
// FileInfo 任务文件信息
message FileInfo { message FileInfo {
string file_name = 1; // 文件名 string file_name = 1; // 文件名
uint64 file_size = 2; // 文件大小 uint64 file_size = 2; // 文件大小
repeated FileBlock file_blocks = 3; // 文件块列表 repeated FileBlock file_blocks = 3; // 文件块列表
} }
// FileBlock 文件块信息
message FileBlock { message FileBlock {
string block_sha256 = 1; // 块的sha256 string block_sha256 = 1; // 块的sha256
uint64 block_length = 2; // 块的字节长度 uint64 block_length = 2; // 块的字节长度
bool uploaded = 3; // 是否已上传在TaskCreate/TaskInfo请求返回 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 { message Debug {
string lua_script = 1; // 要调试的lua脚本 string lua_script = 1; // 要调试的lua脚本
bool use_server_data = 2; // 是否使用服务端用户数据 bool use_server_data = 2; // 是否使用服务端用户数据
@@ -158,15 +182,22 @@ message SaasRes {
Task task_run_res = 22; // 运行任务返回状态 Task task_run_res = 22; // 运行任务返回状态
Task task_delete_res = 23; // 删除任务返回状态 Task task_delete_res = 23; // 删除任务返回状态
Task task_info_res = 24; // 任务详情返回状态 Task task_info_res = 24; // 任务详情返回状态
TargetListRes target_list_res = 50; // 列出策略及绑定返回状态
BindSetRes bind_set_res = 61; // 设置绑定返回状态
BindDeleteRes bind_delete_res = 62; // 删除绑定返回状态
} }
} }
// ReadRes 读记录返回
message ReadRes { message ReadRes {
uint32 succ_cmd_count = 1; // 成功的命令数量 uint32 succ_cmd_count = 1; // 成功的命令数量
uint32 fail_cmd_count = 2; // 失败的命令数量 uint32 fail_cmd_count = 2; // 失败的命令数量
repeated ValueItem cmd_res = 3; // 返回的命令 repeated ValueItem cmd_res = 3; // 返回的命令
} }
// WriteRes 写记录返回
message WriteRes { message WriteRes {
//uint32 succ_cmd_count = 1; // 成功的命令数量 //uint32 succ_cmd_count = 1; // 成功的命令数量
//uint32 fail_cmd_count = 2; // 失败的命令数量 //uint32 fail_cmd_count = 2; // 失败的命令数量
@@ -183,10 +214,69 @@ message ValueItem {
uint32 last_modify_time = 6; // 最后修改时间 uint32 last_modify_time = 6; // 最后修改时间
} }
// TaskListRes 任务列表返回
message TaskListRes { message TaskListRes {
repeated Task tasks = 1; // 任务列表 repeated Task tasks = 1; // 任务列表
} }
// TargetListRes 策略列表返回
message TargetListRes {
map<string, Binds> 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 { message DebugRes {
string PrintOutput = 1; // print输出 string PrintOutput = 1; // print输出
string Error = 2; // 错误信息 string Error = 2; // 错误信息
@@ -224,6 +314,8 @@ enum ErrorCode {
DATA_ERROR = 201; // 数据错误 DATA_ERROR = 201; // 数据错误
CMD_ERROR = 202; // 命令行执行错误 CMD_ERROR = 202; // 命令行执行错误
API_ERROR = 301; // 调用内部API错误
} }
enum CmdErrorCode { enum CmdErrorCode {

46
cmd/saastool/bind.go Normal file
View File

@@ -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.
`

105
cmd/saastool/bind_delete.go Normal file
View File

@@ -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
}

View File

@@ -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
}

110
cmd/saastool/bind_setad.go Normal file
View File

@@ -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
}

View File

@@ -21,7 +21,9 @@ Commands:
convert Convert data to write format convert Convert data to write format
task Task commands task Task commands
target Target commands
bind Bind commands
"help" is the default command. "help" is the default command.

View File

@@ -30,6 +30,10 @@ func Run(args ...string) error {
return RunVerify(args...) return RunVerify(args...)
case "task": case "task":
return RunTask(args...) return RunTask(args...)
case "target":
return RunTarget(args...)
case "bind":
return RunBind(args...)
default: default:
err := fmt.Errorf(`unknown command "%v"`+"\n"+`Run 'saastool help' for usage`, name) err := fmt.Errorf(`unknown command "%v"`+"\n"+`Run 'saastool help' for usage`, name)
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())

View File

@@ -73,6 +73,38 @@ func paramDataSpaceId(fs *flag.FlagSet) *string {
return fs.String("ds", "", "Data space ID") 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 解析字节大小字符串为字节数 // ParseByteSize 解析字节大小字符串为字节数
func ParseByteSize(sizeStr string) (uint64, error) { func ParseByteSize(sizeStr string) (uint64, error) {
sizeStr = strings.TrimSpace(sizeStr) sizeStr = strings.TrimSpace(sizeStr)

View File

@@ -62,7 +62,7 @@ func RunRead(args ...string) error {
ds: *ds, ds: *ds,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

40
cmd/saastool/target.go Normal file
View File

@@ -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.
`

View File

@@ -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
}

View File

@@ -42,7 +42,7 @@ func RunTaskCreate(args ...string) error {
hashFile: *hashFile, hashFile: *hashFile,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
task: &saasapi.Task{}, task: &saasapi.Task{},

View File

@@ -41,7 +41,7 @@ func RunTaskDelete(args ...string) error {
taskSha256: *sha256, taskSha256: *sha256,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -44,7 +44,7 @@ func RunTaskDownload(args ...string) error {
destPath: *destPath, destPath: *destPath,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }
@@ -63,7 +63,7 @@ func doTaskDownload(downloadTaskParams downloadTaskParams) error {
} }
if len(taskInfo.GetSourcePath()) == 0 { 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) fmt.Fprintln(os.Stderr, err)
return err return err
} }

View File

@@ -41,7 +41,7 @@ func RunTaskInfo(args ...string) error {
taskSha256: *sha256, taskSha256: *sha256,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -40,7 +40,7 @@ func RunTaskList(args ...string) error {
listTaskParams := listTaskParams{ listTaskParams := listTaskParams{
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -41,7 +41,7 @@ func RunTaskRun(args ...string) error {
taskSha256: *sha256, taskSha256: *sha256,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -41,7 +41,7 @@ func RunTaskUpload(args ...string) error {
taskSha256: *sha256, taskSha256: *sha256,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -63,7 +63,7 @@ func RunWrite(args ...string) error {
clear: *clear, clear: *clear,
saasHttp: &saashttp.SaasClient{ saasHttp: &saashttp.SaasClient{
Client: &http.Client{}, Client: &http.Client{},
ApiUrls: &cfg.ApiUrls, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth, Auth: &cfg.Auth,
}, },
} }

View File

@@ -1,5 +1,23 @@
package saashttp 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 { type ApiUrls struct {
BaseUrl string BaseUrl string
WritePath string WritePath string
@@ -12,6 +30,98 @@ type ApiUrls struct {
TaskRunPath string TaskRunPath string
TaskUploadPath string TaskUploadPath string
TaskDownloadPath 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 { type Auth struct {

View File

@@ -83,6 +83,21 @@ func (c *SaasClient) TaskDownload(sha256 string, file *os.File, offset int64, si
return c.download(postUrl, file, offset, size) 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 { func (c *SaasClient) makeUrl(baseUrl, path string, params ...string) string {
url, err := url.Parse(baseUrl) url, err := url.Parse(baseUrl)
if err != nil { if err != nil {