支持dataspace

This commit is contained in:
algotao
2025-05-21 17:06:32 +08:00
parent e7d4aa27f1
commit b8c2a3a7d4
7 changed files with 265 additions and 342 deletions

View File

@@ -19,6 +19,7 @@ const (
type readParams struct {
cfg *Config
appid string
ds string
userids []string
saasHttp *saashttp.SaasClient
}
@@ -27,6 +28,7 @@ func RunRead(args ...string) error {
fs := flag.NewFlagSet("read", flag.ExitOnError)
cfgFile := paramConfig(fs)
appid := paramAppid(fs)
ds := paramDataSpaceId(fs)
userids := paramUserids(fs)
if err := fs.Parse(args); err != nil {
@@ -37,11 +39,16 @@ func RunRead(args ...string) error {
// 切割字符串
idsSlice := strings.Split(*userids, ",")
if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") || len(idsSlice) > getIdsMax {
if fs.NArg() > 0 || len(idsSlice) == 0 || (len(idsSlice) == 1 && idsSlice[0] == "") || len(idsSlice) > getIdsMax || len(*ds) == 0 {
fs.PrintDefaults()
return nil
}
if strings.ToLower(*ds) == "openid" && len(*appid) == 0 {
fmt.Fprintln(os.Stderr, "appid must be set when data space is openid")
return nil
}
cfg, err := LoadConfigFile(*cfgFile)
if err != nil {
fmt.Fprintln(os.Stderr, "load config file error", "err", err)
@@ -52,6 +59,7 @@ func RunRead(args ...string) error {
cfg: cfg,
userids: idsSlice,
appid: *appid,
ds: *ds,
saasHttp: &saashttp.SaasClient{
Client: &http.Client{},
ApiUrls: &cfg.ApiUrls,
@@ -63,16 +71,17 @@ func RunRead(args ...string) error {
}
func doRead(readParams readParams) error {
read := &saasapi.Read{
DataspaceId: readParams.ds,
Appid: readParams.appid,
}
saasReq := &saasapi.SaasReq{
Cmd: &saasapi.SaasReq_Read{
Read: &saasapi.Read{},
Read: read,
},
}
if readParams.appid != "" {
saasReq.UseridType = saasapi.UserIdType_OPENID
saasReq.Appid = readParams.appid
}
saasReadItems := []*saasapi.ReadItem{}
for _, userid := range readParams.userids {
saasReadItems = append(saasReadItems, &saasapi.ReadItem{
@@ -80,7 +89,7 @@ func doRead(readParams readParams) error {
})
}
saasReq.Cmd.(*saasapi.SaasReq_Read).Read.ReadItems = saasReadItems
read.ReadItems = saasReadItems
res, err := readParams.saasHttp.Read(saasReq)