working commit
This commit is contained in:
+37
-6
@@ -13,7 +13,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/handler"
|
||||
@@ -54,9 +53,9 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (descr.AccountShort, error) {
|
||||
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (*descr.AccountShort, error) {
|
||||
var err error
|
||||
var res descr.AccountShort
|
||||
res := &descr.AccountShort{}
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
|
||||
if err != nil {
|
||||
@@ -84,13 +83,14 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (desc
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return res, err
|
||||
}
|
||||
res = operRes.Result.Account
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/get")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
|
||||
func (cli *Client) UpdateAccount(ctx context.Context, hosturi, id, username, newUsername, newPassword string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/update")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/update")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (cli *Client) UpdateAccount(ctx context.Context, hosturi, id, username, new
|
||||
func (cli *Client) DeleteAccount(ctx context.Context, hosturi, id, username string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/delete")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/delete")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -182,3 +182,34 @@ func (cli *Client) DeleteAccount(ctx context.Context, hosturi, id, username stri
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (cli *Client) ListAccounts(ctx context.Context, hosturi string) ([]descr.AccountShort, error) {
|
||||
var err error
|
||||
res := make([]descr.AccountShort, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/accounts/list")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.ListAccountsParams{}
|
||||
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.ListAccountsResult]()
|
||||
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.Accounts
|
||||
return res, err
|
||||
}
|
||||
|
||||
+18
-12
@@ -22,6 +22,7 @@ import (
|
||||
"mstore/app/server"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
func TestAccountLife(t *testing.T) {
|
||||
@@ -95,21 +96,26 @@ func TestAccountLife(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
|
||||
|
||||
_, err = cli.GetAccountByID(ctx, srvaddr, accountID)
|
||||
accountDescr, err := cli.GetAccountByID(ctx, srvaddr, accountID)
|
||||
require.NoError(t, err)
|
||||
accountYAML, err := yaml.Marshal(accountDescr)
|
||||
fmt.Printf("account:\n%s\n", string(accountYAML))
|
||||
}
|
||||
{
|
||||
// ListAccounts
|
||||
fmt.Printf("=== ListAccounts ===\n")
|
||||
cli := NewClient()
|
||||
ctx := context.Background()
|
||||
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
|
||||
|
||||
accountDescrs, err := cli.ListAccounts(ctx, srvaddr+"/")
|
||||
require.NoError(t, err)
|
||||
require.NotZero(t, len(accountDescrs))
|
||||
accountsYAML, err := yaml.Marshal(accountDescrs)
|
||||
fmt.Printf("accounts:\n%s\n", string(accountsYAML))
|
||||
|
||||
}
|
||||
/*
|
||||
{
|
||||
// ListAccounts
|
||||
fmt.Printf("=== ListAccounts ===\n")
|
||||
cli := NewClient()
|
||||
ctx := context.Background()
|
||||
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
|
||||
|
||||
files, err := cli.ListAccounts(ctx, srvaddr+"/")
|
||||
require.NoError(t, err)
|
||||
require.NotZero(t, len(files))
|
||||
}
|
||||
|
||||
{
|
||||
// DeleteAccount
|
||||
|
||||
+4
-5
@@ -13,7 +13,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"mstore/app/handler"
|
||||
"mstore/app/operator"
|
||||
@@ -22,7 +21,7 @@ import (
|
||||
func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, operation, pattern string) error {
|
||||
var err error
|
||||
|
||||
apiuri, err := url.JoinPath(hosturi, "/v3/api/grant/create")
|
||||
apiuri, err := setApiPath(hosturi, "/v3/api/grant/create")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +54,7 @@ func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, operatio
|
||||
func (cli *Client) GetGrant(ctx context.Context, hosturi, id, username string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/grant/get")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/get")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -86,7 +85,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id, username string) e
|
||||
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/grant/update")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/update")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -117,7 +116,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
|
||||
func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/grant/delete")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user