working commit
This commit is contained in:
+2
-22
@@ -121,17 +121,7 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
for _, grantDescrs := range grantDescrs {
|
accountShort.Grants = grantDescrs
|
||||||
grantShorts := descr.Grant{
|
|
||||||
Right: grantDescrs.Right,
|
|
||||||
Pattern: grantDescrs.Pattern,
|
|
||||||
CreatedAt: grantDescrs.CreatedAt,
|
|
||||||
UpdatedAt: grantDescrs.UpdatedAt,
|
|
||||||
CreatedBy: grantDescrs.CreatedBy,
|
|
||||||
UpdatedBy: grantDescrs.UpdatedBy,
|
|
||||||
}
|
|
||||||
accountShort.Grants = append(accountShort.Grants, grantShorts)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Account = accountShort
|
res.Account = accountShort
|
||||||
return res, err
|
return res, err
|
||||||
@@ -289,17 +279,7 @@ func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsPara
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
for _, grantDescrs := range grantDescrs {
|
accountShort.Grants = grantDescrs
|
||||||
grantShorts := descr.Grant{
|
|
||||||
Right: grantDescrs.Right,
|
|
||||||
Pattern: grantDescrs.Pattern,
|
|
||||||
CreatedAt: grantDescrs.CreatedAt,
|
|
||||||
UpdatedAt: grantDescrs.UpdatedAt,
|
|
||||||
CreatedBy: grantDescrs.CreatedBy,
|
|
||||||
UpdatedBy: grantDescrs.UpdatedBy,
|
|
||||||
}
|
|
||||||
accountShort.Grants = append(accountShort.Grants, grantShorts)
|
|
||||||
}
|
|
||||||
res.Accounts = append(res.Accounts, accountShort)
|
res.Accounts = append(res.Accounts, accountShort)
|
||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
+27
-1
@@ -13,6 +13,7 @@ import (
|
|||||||
// CreateGrant
|
// CreateGrant
|
||||||
type CreateGrantParams struct {
|
type CreateGrantParams struct {
|
||||||
AccountID string `json:"accountID"`
|
AccountID string `json:"accountID"`
|
||||||
|
Username string `json:"username"`
|
||||||
Right string `json:"operation"`
|
Right string `json:"operation"`
|
||||||
Pattern string `json:"pattern"`
|
Pattern string `json:"pattern"`
|
||||||
}
|
}
|
||||||
@@ -43,6 +44,31 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var accountDescr *descr.Account
|
||||||
|
var accountExists bool
|
||||||
|
switch {
|
||||||
|
case params.AccountID != "":
|
||||||
|
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
if !accountExists {
|
||||||
|
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
case params.Username != "":
|
||||||
|
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
if !accountExists {
|
||||||
|
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
err := fmt.Errorf("Empty username and accountId parameter")
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern)
|
grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
@@ -55,7 +81,7 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
|
|||||||
now := auxtool.TimeNow()
|
now := auxtool.TimeNow()
|
||||||
grantDescr := &descr.Grant{
|
grantDescr := &descr.Grant{
|
||||||
ID: auxuuid.NewUUID(),
|
ID: auxuuid.NewUUID(),
|
||||||
AccountID: params.AccountID,
|
AccountID: accountDescr.ID,
|
||||||
Right: params.Right,
|
Right: params.Right,
|
||||||
Pattern: params.Pattern,
|
Pattern: params.Pattern,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
|
|||||||
+29
-46
@@ -16,7 +16,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"mstore/app/descr"
|
"mstore/app/descr"
|
||||||
"mstore/pkg/client"
|
"mstore/pkg/client"
|
||||||
@@ -55,75 +54,59 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
|||||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "p", "", "Password")
|
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "p", "", "Password")
|
||||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||||
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
subCmd.MarkPersistentFlagRequired("host")
|
|
||||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||||
|
|
||||||
// CreateAccount
|
// CreateAccount
|
||||||
var createAccountCmd = &cobra.Command{
|
var createAccountCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create host username password",
|
||||||
Short: "Create user account",
|
Short: "Create user account",
|
||||||
|
Args: cobra.ExactArgs(3),
|
||||||
Run: util.CreateAccount,
|
Run: util.CreateAccount,
|
||||||
}
|
}
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewUsername, "newuser", "U", "", "New account username")
|
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewPassword, "newpass", "P", "", "New account password")
|
|
||||||
createAccountCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
|
||||||
subCmd.AddCommand(createAccountCmd)
|
subCmd.AddCommand(createAccountCmd)
|
||||||
|
|
||||||
// GetAccount
|
// GetAccount
|
||||||
var getAccountCmd = &cobra.Command{
|
var getAccountCmd = &cobra.Command{
|
||||||
Use: "get",
|
Use: "get hostname accountId|username",
|
||||||
Short: "Get account info",
|
Short: "Get account info",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
Run: util.GetAccount,
|
Run: util.GetAccount,
|
||||||
}
|
}
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "id", "I", "", "Account ID or name")
|
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "name", "n", "", "Account ID or name")
|
|
||||||
getAccountCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
subCmd.AddCommand(getAccountCmd)
|
subCmd.AddCommand(getAccountCmd)
|
||||||
|
|
||||||
// UpdateAccount
|
// UpdateAccount
|
||||||
var updateAccountCmd = &cobra.Command{
|
var updateAccountCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "update hostname username|accounId",
|
||||||
Short: "Update account parameters",
|
Short: "Update account parameters",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
Run: util.UpdateAccount,
|
Run: util.UpdateAccount,
|
||||||
}
|
}
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "id", "I", "", "Account ID or username")
|
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewUsername, "newname", "N", "", "New username")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewUsername, "newname", "N", "", "New username")
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "P", "", "New password")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "P", "", "New password")
|
||||||
updateAccountCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
||||||
subCmd.AddCommand(updateAccountCmd)
|
subCmd.AddCommand(updateAccountCmd)
|
||||||
|
|
||||||
// DeleteAccount
|
// DeleteAccount
|
||||||
var deleteAccountCmd = &cobra.Command{
|
var deleteAccountCmd = &cobra.Command{
|
||||||
Use: "delete",
|
Use: "delete hostname username|accountId",
|
||||||
Short: "Delete account",
|
Short: "Delete account",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
Run: util.DeleteAccount,
|
Run: util.DeleteAccount,
|
||||||
}
|
}
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.AccountID, "id", "I", "", "Account ID")
|
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
||||||
deleteAccountCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
subCmd.AddCommand(deleteAccountCmd)
|
subCmd.AddCommand(deleteAccountCmd)
|
||||||
|
|
||||||
// ListAccount
|
// ListAccount
|
||||||
var listAccountsCmd = &cobra.Command{
|
var listAccountsCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list hostname",
|
||||||
Short: "list accounts",
|
Short: "list accounts",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
Run: util.ListAccounts,
|
Run: util.ListAccounts,
|
||||||
}
|
}
|
||||||
listAccountsCmd.Flags().BoolVarP(&util.listAccountsParams.Detail, "detail", "d", false, "Show detail information")
|
listAccountsCmd.Flags().BoolVarP(&util.listAccountsParams.Detail, "detail", "d", false, "Show detail information")
|
||||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Regex, "regex", "r", "", "Output regexp for usernames")
|
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Regex, "regex", "r", "", "Output regexp for usernames")
|
||||||
listAccountsCmd.MarkFlagRequired("host")
|
|
||||||
subCmd.AddCommand(listAccountsCmd)
|
subCmd.AddCommand(listAccountsCmd)
|
||||||
|
|
||||||
viper.BindPFlags(subCmd.Flags())
|
|
||||||
viper.SetEnvPrefix("MSTORE")
|
|
||||||
|
|
||||||
// Bind environment variables
|
|
||||||
viper.BindEnv("user")
|
|
||||||
viper.BindEnv("pass")
|
|
||||||
viper.BindEnv("host")
|
|
||||||
|
|
||||||
return subCmd
|
return subCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,10 +117,13 @@ type CreateAccountParams struct {
|
|||||||
}
|
}
|
||||||
type CreateAccountResult struct {
|
type CreateAccountResult struct {
|
||||||
AccountID string `yaml:"accountId"`
|
AccountID string `yaml:"accountId"`
|
||||||
GrantIDs []string `yaml:"grantsIds,omitempty"`
|
Grants map[string]string `yaml:"grantsIds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonAccountParams.Hostname = args[0]
|
||||||
|
util.createAccountParams.NewUsername = args[1]
|
||||||
|
util.createAccountParams.NewPassword = args[2]
|
||||||
res, err := util.createAccount(&util.commonAccountParams, &util.createAccountParams)
|
res, err := util.createAccount(&util.commonAccountParams, &util.createAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -145,7 +131,7 @@ func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
|||||||
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
|
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &CreateAccountResult{
|
res := &CreateAccountResult{
|
||||||
GrantIDs: make([]string, 0),
|
Grants: make(map[string]string, 0),
|
||||||
}
|
}
|
||||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -167,11 +153,11 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
|||||||
descr.RightReadImages,
|
descr.RightReadImages,
|
||||||
}
|
}
|
||||||
for _, right := range fullRights {
|
for _, right := range fullRights {
|
||||||
id, err := client.NewClient().CreateGrant(ctx, hostname, accountID, right, ".*")
|
id, err := client.NewClient().CreateGrantByAccountID(ctx, hostname, accountID, right, ".*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res.GrantIDs = append(res.GrantIDs, id)
|
res.Grants[id] = right
|
||||||
}
|
}
|
||||||
res.AccountID = accountID
|
res.AccountID = accountID
|
||||||
return res, err
|
return res, err
|
||||||
@@ -179,9 +165,6 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
|||||||
|
|
||||||
// UpdateAccount
|
// UpdateAccount
|
||||||
type UpdateAccountParams struct {
|
type UpdateAccountParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
Timeout uint64
|
||||||
AccountID string
|
AccountID string
|
||||||
NewUsername string
|
NewUsername string
|
||||||
@@ -192,6 +175,8 @@ type UpdateAccountResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonAccountParams.Hostname = args[0]
|
||||||
|
util.updateAccountParams.AccountID = args[1]
|
||||||
res, err := util.updateAccount(&util.commonAccountParams, &util.updateAccountParams)
|
res, err := util.updateAccount(&util.commonAccountParams, &util.updateAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -220,14 +205,13 @@ func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *Upda
|
|||||||
|
|
||||||
// Get file
|
// Get file
|
||||||
type GetAccountParams struct {
|
type GetAccountParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
Timeout uint64
|
||||||
AccountID string
|
AccountID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonAccountParams.Hostname = args[0]
|
||||||
|
util.getAccountParams.AccountID = args[1]
|
||||||
res, err := util.getAccount(&util.commonAccountParams, &util.getAccountParams)
|
res, err := util.getAccount(&util.commonAccountParams, &util.getAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -263,9 +247,6 @@ func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAcco
|
|||||||
|
|
||||||
// DeleteAccount
|
// DeleteAccount
|
||||||
type DeleteAccountParams struct {
|
type DeleteAccountParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
AccountID string
|
AccountID string
|
||||||
Timeout uint64
|
Timeout uint64
|
||||||
}
|
}
|
||||||
@@ -273,6 +254,8 @@ type DeleteAccountParams struct {
|
|||||||
type DeleteAccountResult struct{}
|
type DeleteAccountResult struct{}
|
||||||
|
|
||||||
func (util *AccountUtil) DeleteAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) DeleteAccount(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonAccountParams.Hostname = args[0]
|
||||||
|
util.deleteAccountParams.AccountID = args[1]
|
||||||
res, err := util.deleteAccount(&util.commonAccountParams, &util.deleteAccountParams)
|
res, err := util.deleteAccount(&util.commonAccountParams, &util.deleteAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -300,9 +283,6 @@ func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *Dele
|
|||||||
|
|
||||||
// ListAccounts
|
// ListAccounts
|
||||||
type ListAccountsParams struct {
|
type ListAccountsParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
Timeout uint64
|
||||||
Detail bool
|
Detail bool
|
||||||
Regex string
|
Regex string
|
||||||
@@ -310,7 +290,8 @@ type ListAccountsParams struct {
|
|||||||
|
|
||||||
type Userinfo struct {
|
type Userinfo struct {
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `yaml:"username,omitempty"`
|
||||||
Rights []string `yaml:"rights,omitempty"`
|
AccountID string `yaml:"accountId,omitempty"`
|
||||||
|
Rights map[string]string `yaml:"rights,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListAccountsResult struct {
|
type ListAccountsResult struct {
|
||||||
@@ -319,6 +300,7 @@ type ListAccountsResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonAccountParams.Hostname = args[0]
|
||||||
res, err := util.listAccounts(&util.commonAccountParams, &util.listAccountsParams)
|
res, err := util.listAccounts(&util.commonAccountParams, &util.listAccountsParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -357,10 +339,11 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
|
|||||||
for _, account := range outAccounts {
|
for _, account := range outAccounts {
|
||||||
userinfo := Userinfo{
|
userinfo := Userinfo{
|
||||||
Username: account.Username,
|
Username: account.Username,
|
||||||
Rights: make([]string, 0),
|
AccountID: account.ID,
|
||||||
|
Rights: make(map[string]string, 0),
|
||||||
}
|
}
|
||||||
for _, grant := range account.Grants {
|
for _, grant := range account.Grants {
|
||||||
userinfo.Rights = append(userinfo.Rights, grant.Right)
|
userinfo.Rights[grant.ID] = grant.Right
|
||||||
}
|
}
|
||||||
res.Users = append(res.Users, userinfo)
|
res.Users = append(res.Users, userinfo)
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-33
@@ -31,69 +31,53 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
|||||||
|
|
||||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Username, "user", "u", "", "Username")
|
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Username, "user", "u", "", "Username")
|
||||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Password, "pass", "p", "", "Password")
|
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Password, "pass", "p", "", "Password")
|
||||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
subCmd.PersistentFlags().Uint64VarP(&util.commonGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
subCmd.PersistentFlags().Uint64VarP(&util.commonGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
subCmd.MarkPersistentFlagRequired("host")
|
|
||||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
// CreateGrant
|
// CreateGrant
|
||||||
var createGrantCmd = &cobra.Command{
|
var createGrantCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create hostname[:port] username|accountId rigth pattern",
|
||||||
Short: "Create grant",
|
Short: "Create grant",
|
||||||
|
Args: cobra.ExactArgs(4),
|
||||||
Run: util.CreateGrant,
|
Run: util.CreateGrant,
|
||||||
}
|
}
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Right, "newuser", "U", "", "New account username")
|
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Pattern, "newpass", "P", "", "New account password")
|
|
||||||
createGrantCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
|
||||||
subCmd.AddCommand(createGrantCmd)
|
subCmd.AddCommand(createGrantCmd)
|
||||||
|
|
||||||
// GetGrant
|
// GetGrant
|
||||||
var getGrantCmd = &cobra.Command{
|
var getGrantCmd = &cobra.Command{
|
||||||
Use: "get",
|
Use: "get hostname[:port] grantId",
|
||||||
Short: "Get detail grant info",
|
Short: "Get detail grant info",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
Run: util.GetGrant,
|
Run: util.GetGrant,
|
||||||
}
|
}
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "id", "I", "", "Grant ID or name")
|
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "name", "n", "", "Grant ID or name")
|
|
||||||
getGrantCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
subCmd.AddCommand(getGrantCmd)
|
subCmd.AddCommand(getGrantCmd)
|
||||||
|
|
||||||
// UpdateGrant
|
// UpdateGrant
|
||||||
var updateGrantCmd = &cobra.Command{
|
var updateGrantCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "update hostname[:port] gruntId newPattern",
|
||||||
Short: "Update grant parameters",
|
Short: "Update grant parameters",
|
||||||
|
Args: cobra.ExactArgs(3),
|
||||||
Run: util.UpdateGrant,
|
Run: util.UpdateGrant,
|
||||||
}
|
}
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "id", "I", "", "Grant ID or username")
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "name", "n", "", "Grant ID or username")
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Right, "rigth", "U", "", "Rigth")
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Pattern, "pattern", "P", "", "New pattern")
|
|
||||||
updateGrantCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
updateGrantCmd.MarkFlagRequired("rigth")
|
|
||||||
updateGrantCmd.MarkFlagRequired("pattern")
|
|
||||||
subCmd.AddCommand(updateGrantCmd)
|
subCmd.AddCommand(updateGrantCmd)
|
||||||
|
|
||||||
// DeleteGrant
|
// DeleteGrant
|
||||||
var deleteGrantCmd = &cobra.Command{
|
var deleteGrantCmd = &cobra.Command{
|
||||||
Use: "delete",
|
Use: "delete hostname[:port] gruntId ",
|
||||||
Short: "Delete grant",
|
Short: "Delete grant",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
|
||||||
Run: util.DeleteGrant,
|
Run: util.DeleteGrant,
|
||||||
}
|
}
|
||||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.GrantID, "id", "I", "", "Grant ID")
|
|
||||||
deleteGrantCmd.MarkFlagRequired("id")
|
|
||||||
subCmd.AddCommand(deleteGrantCmd)
|
subCmd.AddCommand(deleteGrantCmd)
|
||||||
|
|
||||||
// ListGrants
|
// ListGrants
|
||||||
var listGrantsCmd = &cobra.Command{
|
var listGrantsCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list hostname[:port] accountId|username",
|
||||||
Short: "list user grants",
|
Short: "list user grants",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
Run: util.ListGrants,
|
Run: util.ListGrants,
|
||||||
}
|
}
|
||||||
listGrantsCmd.Flags().BoolVarP(&util.listGrantsParams.Detail, "detail", "d", false, "Show detail information")
|
listGrantsCmd.Flags().BoolVarP(&util.listGrantsParams.Detail, "detail", "d", false, "Show detail information")
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "id", "I", "", "User account ID")
|
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "name", "n", "", "User account ID")
|
|
||||||
listGrantsCmd.MarkFlagRequired("host")
|
|
||||||
listGrantsCmd.MarkFlagsOneRequired("id", "name")
|
|
||||||
|
|
||||||
subCmd.AddCommand(listGrantsCmd)
|
subCmd.AddCommand(listGrantsCmd)
|
||||||
|
|
||||||
@@ -127,6 +111,10 @@ type CreateGrantResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonGrantParams.Hostname = args[0]
|
||||||
|
util.createGrantParams.AccountID = args[1]
|
||||||
|
util.createGrantParams.Right = args[2]
|
||||||
|
util.createGrantParams.Pattern = args[3]
|
||||||
res, err := util.createGrant(&util.commonGrantParams, &util.createGrantParams)
|
res, err := util.createGrant(&util.commonGrantParams, &util.createGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -140,23 +128,32 @@ func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGran
|
|||||||
}
|
}
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
accountID, err := client.NewClient().CreateGrant(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
re := regexp.MustCompile(uuidRegex)
|
||||||
|
id := strings.ToLower(params.AccountID)
|
||||||
|
var operRes string
|
||||||
|
if re.MatchString(id) {
|
||||||
|
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||||
|
} else {
|
||||||
|
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res.GrantID = accountID
|
res.GrantID = operRes
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateGrant
|
// UpdateGrant
|
||||||
type UpdateGrantParams struct {
|
type UpdateGrantParams struct {
|
||||||
GrantID string
|
GrantID string
|
||||||
Right string
|
|
||||||
Pattern string
|
Pattern string
|
||||||
}
|
}
|
||||||
type UpdateGrantResult struct{}
|
type UpdateGrantResult struct{}
|
||||||
|
|
||||||
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonGrantParams.Hostname = args[0]
|
||||||
|
util.updateGrantParams.GrantID = args[1]
|
||||||
|
util.updateGrantParams.Pattern = args[2]
|
||||||
res, err := util.updateGrant(&util.commonGrantParams, &util.updateGrantParams)
|
res, err := util.updateGrant(&util.commonGrantParams, &util.updateGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -188,6 +185,9 @@ type GetGrantResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonGrantParams.Hostname = args[0]
|
||||||
|
util.getGrantParams.GrantID = args[1]
|
||||||
|
|
||||||
res, err := util.getGrant(&util.commonGrantParams, &util.getGrantParams)
|
res, err := util.getGrant(&util.commonGrantParams, &util.getGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -220,6 +220,8 @@ type DeleteGrantParams struct {
|
|||||||
type DeleteGrantResult struct{}
|
type DeleteGrantResult struct{}
|
||||||
|
|
||||||
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonGrantParams.Hostname = args[0]
|
||||||
|
util.deleteGrantParams.GrantID = args[1]
|
||||||
res, err := util.deleteGrant(&util.commonGrantParams, &util.deleteGrantParams)
|
res, err := util.deleteGrant(&util.commonGrantParams, &util.deleteGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -248,10 +250,12 @@ type ListGrantsParams struct {
|
|||||||
|
|
||||||
type ListGrantsResult struct {
|
type ListGrantsResult struct {
|
||||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
Grants []descr.Grant `yaml:"grants,omitempty"`
|
||||||
Rights []string `yaml:"rights,omitempty"`
|
Rights map[string]string `yaml:"rights,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||||
|
util.commonGrantParams.Hostname = args[0]
|
||||||
|
util.listGrantsParams.AccountID = args[1]
|
||||||
res, err := util.listGrants(&util.commonGrantParams, &util.listGrantsParams)
|
res, err := util.listGrants(&util.commonGrantParams, &util.listGrantsParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
@@ -278,9 +282,9 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
|
|||||||
if params.Detail {
|
if params.Detail {
|
||||||
res.Grants = grants
|
res.Grants = grants
|
||||||
} else {
|
} else {
|
||||||
res.Rights = make([]string, 0)
|
res.Rights = make(map[string]string, 0)
|
||||||
for _, item := range grants {
|
for _, item := range grants {
|
||||||
res.Rights = append(res.Rights, item.Right)
|
res.Rights[item.ID] = item.Right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (util *Util) Build() error {
|
|||||||
rootCmd := cobra.Command{
|
rootCmd := cobra.Command{
|
||||||
Use: execName,
|
Use: execName,
|
||||||
Short: "\nA brief description the command",
|
Short: "\nA brief description the command",
|
||||||
SilenceUsage: true,
|
//SilenceUsage: true,
|
||||||
}
|
}
|
||||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,25 @@ require (
|
|||||||
github.com/docker/cli v29.0.3+incompatible // indirect
|
github.com/docker/cli v29.0.3+incompatible // indirect
|
||||||
github.com/docker/distribution v2.8.3+incompatible // indirect
|
github.com/docker/distribution v2.8.3+incompatible // indirect
|
||||||
github.com/docker/docker-credential-helpers v0.9.3 // indirect
|
github.com/docker/docker-credential-helpers v0.9.3 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.1 // indirect
|
github.com/klauspost/compress v1.18.1 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
github.com/spf13/pflag v1.0.9 // indirect
|
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||||
|
github.com/spf13/afero v1.15.0 // indirect
|
||||||
|
github.com/spf13/cast v1.10.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
|
github.com/spf13/viper v1.21.0 // indirect
|
||||||
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/vbatts/tar-split v0.12.2 // indirect
|
github.com/vbatts/tar-split v0.12.2 // indirect
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/sync v0.18.0 // indirect
|
golang.org/x/sync v0.18.0 // indirect
|
||||||
golang.org/x/sys v0.38.0 // indirect
|
golang.org/x/sys v0.38.0 // indirect
|
||||||
|
golang.org/x/text v0.28.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,8 +12,12 @@ github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBi
|
|||||||
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8=
|
github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8=
|
||||||
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
|
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
|
||||||
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/go-containerregistry v0.20.7 h1:24VGNpS0IwrOZ2ms2P1QE3Xa5X9p4phx0aUgzYzHW6I=
|
github.com/google/go-containerregistry v0.20.7 h1:24VGNpS0IwrOZ2ms2P1QE3Xa5X9p4phx0aUgzYzHW6I=
|
||||||
@@ -37,23 +41,40 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
|
|||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
||||||
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
|
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||||
|
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
|
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||||
|
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||||
|
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||||
|
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||||
|
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||||
|
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||||
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
||||||
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
||||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||||
|
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
|
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||||
|
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||||
github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4=
|
github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4=
|
||||||
github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
|
github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
|
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
@@ -62,6 +83,8 @@ golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
|||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
||||||
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
|
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
|
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
+42
-3
@@ -19,7 +19,7 @@ import (
|
|||||||
"mstore/app/operator"
|
"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 err error
|
||||||
var res string
|
var res string
|
||||||
|
|
||||||
@@ -54,6 +54,43 @@ func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, right, p
|
|||||||
return res, err
|
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) {
|
func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &descr.Grant{}
|
res := &descr.Grant{}
|
||||||
@@ -87,6 +124,8 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Gra
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -153,7 +192,7 @@ func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID
|
|||||||
var err error
|
var err error
|
||||||
res := make([]descr.Grant, 0)
|
res := make([]descr.Grant, 0)
|
||||||
|
|
||||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
apipath, err := setApiPath(hosturi, "/v3/api/grants/list")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -186,7 +225,7 @@ func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username s
|
|||||||
var err error
|
var err error
|
||||||
res := make([]descr.Grant, 0)
|
res := make([]descr.Grant, 0)
|
||||||
|
|
||||||
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
|
apipath, err := setApiPath(hosturi, "/v3/api/grants/list")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user