支持数据授权管理功能
This commit is contained in:
70
cmd/saastool/grant_list.go
Normal file
70
cmd/saastool/grant_list.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.algo.com.cn/public/saasapi"
|
||||
"git.algo.com.cn/public/saasapi/pkg/saashttp"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
type grantListParams struct {
|
||||
saasHttp *saashttp.SaasClient
|
||||
}
|
||||
|
||||
func RunGrantList(args ...string) error {
|
||||
fs := flag.NewFlagSet("list", flag.ExitOnError)
|
||||
cfgFile := paramConfig(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
|
||||
}
|
||||
|
||||
cfg, err := LoadConfigFile(*cfgFile)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
grantListParams := grantListParams{
|
||||
saasHttp: &saashttp.SaasClient{
|
||||
Client: &http.Client{},
|
||||
ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
|
||||
Auth: &cfg.Auth,
|
||||
},
|
||||
}
|
||||
|
||||
return doGrantList(grantListParams)
|
||||
}
|
||||
|
||||
func doGrantList(params grantListParams) error {
|
||||
saasReq := &saasapi.SaasReq{
|
||||
Cmd: &saasapi.SaasReq_GrantList{
|
||||
GrantList: &saasapi.GrantList{},
|
||||
},
|
||||
}
|
||||
|
||||
res, err := params.saasHttp.GrantList(saasReq)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "submit Grant List error", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if res.Code != saasapi.ErrorCode_SUCC {
|
||||
fmt.Fprintln(os.Stderr, "Grant list failed", "code", res.Code, "status", res.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
grantRes := res.GetGrantListRes()
|
||||
fmt.Printf("grant list res: %v\n", protojson.Format(grantRes))
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user