76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.algo.com.cn/public/saasapi"
|
|
"git.algo.com.cn/public/saasapi/pkg/saashttp"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
type expGrantAddParams struct {
|
|
srtaAccountId uint32
|
|
saasHttp *saashttp.SaasClient
|
|
}
|
|
|
|
func RunExpGrantAdd(args ...string) error {
|
|
fs := flag.NewFlagSet("add", flag.ExitOnError)
|
|
cfgFile := paramConfig(fs)
|
|
srtaAccountId := paramSrtaAccountId(fs)
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
return fmt.Errorf("Command line parse error: %w", err)
|
|
}
|
|
|
|
if fs.NArg() > 0 {
|
|
fs.PrintDefaults()
|
|
return nil
|
|
}
|
|
|
|
if *srtaAccountId == 0 {
|
|
fs.PrintDefaults()
|
|
return fmt.Errorf("sRTA account ID is required")
|
|
}
|
|
|
|
cfg, err := LoadConfigFile(*cfgFile)
|
|
if err != nil {
|
|
return fmt.Errorf("LoadConfigFile error: %w", err)
|
|
}
|
|
|
|
expGrantAddParams := expGrantAddParams{
|
|
srtaAccountId: uint32(*srtaAccountId),
|
|
saasHttp: &saashttp.SaasClient{
|
|
Client: &http.Client{},
|
|
ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
|
|
Auth: &cfg.Auth,
|
|
},
|
|
}
|
|
|
|
return doExpGrantAdd(expGrantAddParams)
|
|
}
|
|
|
|
func doExpGrantAdd(params expGrantAddParams) error {
|
|
saasReq := &saasapi.SaasReq{
|
|
Cmd: &saasapi.SaasReq_ExpGrantAdd{
|
|
ExpGrantAdd: &saasapi.ExpGrant{
|
|
TargetAccountId: params.srtaAccountId,
|
|
},
|
|
},
|
|
}
|
|
|
|
res, err := params.saasHttp.ExpGrantAdd(saasReq)
|
|
if err != nil {
|
|
return fmt.Errorf("Submit Command error: %w", err)
|
|
}
|
|
|
|
if res.Code != saasapi.ErrorCode_SUCC {
|
|
return fmt.Errorf("Command failed. code:%v, status:%v", res.Code, res.Status)
|
|
}
|
|
|
|
expGrantRes := res.GetExpGrantAddRes()
|
|
fmt.Printf("exp grant add res: %v\n", protojson.Format(expGrantRes))
|
|
return nil
|
|
}
|