working commit
This commit is contained in:
+42
-3
@@ -19,7 +19,7 @@ import (
|
||||
"mstore/app/operator"
|
||||
)
|
||||
|
||||
func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) {
|
||||
func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
|
||||
@@ -54,6 +54,43 @@ func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, p
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
|
||||
apiuri, err := setApiPath(hosturi, "/v3/api/grant/create")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.CreateGrantParams{
|
||||
Username: username,
|
||||
Right: right,
|
||||
Pattern: pattern,
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.CreateGrantResult]()
|
||||
err = json.Unmarshal(respBytes, operRes)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return res, err
|
||||
}
|
||||
res = operRes.Result.GrantID
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
@@ -87,6 +124,8 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Gra
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
||||
var err error
|
||||
|
||||
@@ -153,7 +192,7 @@ func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID
|
||||
var err error
|
||||
res := make([]descr.Grant, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grants/list")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -186,7 +225,7 @@ func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username s
|
||||
var err error
|
||||
res := make([]descr.Grant, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grants/list")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user