调整授权功能

This commit is contained in:
algotao
2025-11-23 12:01:33 +08:00
parent 4575590faa
commit c9d794430e
6 changed files with 51 additions and 45 deletions

View File

@@ -14,15 +14,15 @@ import (
type grantAddParams struct {
srtaAccountId uint32
grantIndex string
ds string
ds uint32
saasHttp *saashttp.SaasClient
}
func RunGrantAdd(args ...string) error {
fs := flag.NewFlagSet("add", flag.ExitOnError)
cfgFile := paramConfig(fs)
ds := paramDataSpaceId(fs)
srtaAccountId := paramSrtaAccountId(fs)
dsid := paramRawDataSpaceId(fs)
grantIndex := paramGrantIndex(fs)
if err := fs.Parse(args); err != nil {
@@ -35,12 +35,6 @@ func RunGrantAdd(args ...string) error {
return nil
}
if len(*ds) == 0 {
fmt.Fprintln(os.Stderr, "Error: data space is required")
fs.PrintDefaults()
return fmt.Errorf("data space is required")
}
if *srtaAccountId == 0 {
fmt.Fprintln(os.Stderr, "Error: sRTA account ID is required")
fs.PrintDefaults()
@@ -53,6 +47,12 @@ func RunGrantAdd(args ...string) error {
return fmt.Errorf("grant index is required")
}
if *dsid == 0 {
fmt.Fprintln(os.Stderr, "Error: data space ID is required")
fs.PrintDefaults()
return fmt.Errorf("data space ID is required")
}
cfg, err := LoadConfigFile(*cfgFile)
if err != nil {
fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err)
@@ -62,7 +62,7 @@ func RunGrantAdd(args ...string) error {
grantAddParams := grantAddParams{
srtaAccountId: uint32(*srtaAccountId),
grantIndex: *grantIndex,
ds: *ds,
ds: uint32(*dsid),
saasHttp: &saashttp.SaasClient{
Client: &http.Client{},
ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
@@ -77,9 +77,9 @@ func doGrantAdd(params grantAddParams) error {
saasReq := &saasapi.SaasReq{
Cmd: &saasapi.SaasReq_GrantAdd{
GrantAdd: &saasapi.Grant{
SrtaAccountId: params.srtaAccountId,
GrantIndex: params.grantIndex,
DataspaceId: params.ds,
TargetAccountId: params.srtaAccountId,
GrantIndex: params.grantIndex,
DataspaceId: params.ds,
},
},
}