working commit
This commit is contained in:
+89
-18
@@ -14,16 +14,18 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/handler"
|
||||
"mstore/app/operator"
|
||||
)
|
||||
|
||||
func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, pattern string) error {
|
||||
func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
|
||||
apiuri, err := setApiPath(hosturi, "/v3/api/grant/create")
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.CreateGrantParams{
|
||||
AccountID: accountID,
|
||||
@@ -32,54 +34,57 @@ func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, p
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.CreateGrantResult]()
|
||||
err = json.Unmarshal(respBytes, operRes)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
if !operRes.Error {
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
return err
|
||||
res = operRes.Result.GrantID
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetGrant(ctx context.Context, hosturi, id, username string) error {
|
||||
func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/get")
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.GetGrantParams{
|
||||
GrantID: id,
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.GetGrantResult]()
|
||||
err = json.Unmarshal(respBytes, operRes)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
if !operRes.Error {
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
return err
|
||||
res = operRes.Result.Grant
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
||||
@@ -106,7 +111,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !operRes.Error {
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return err
|
||||
}
|
||||
@@ -137,9 +142,75 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !operRes.Error {
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID string) ([]descr.Grant, error) {
|
||||
var err error
|
||||
res := make([]descr.Grant, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.ListGrantsParams{
|
||||
AccountID: accountID,
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.ListGrantsResult]()
|
||||
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.Grants
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username string) ([]descr.Grant, error) {
|
||||
var err error
|
||||
res := make([]descr.Grant, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.ListGrantsParams{
|
||||
Username: username,
|
||||
}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.ListGrantsResult]()
|
||||
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.Grants
|
||||
return res, err
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user