working commit
This commit is contained in:
+96
-96
@@ -26,29 +26,46 @@ const (
|
||||
defaultHostname = "localhost:1025"
|
||||
)
|
||||
|
||||
type AccountUtil struct {
|
||||
createAccountParams CreateAccountParams
|
||||
updateAccountParams UpdateAccountParams
|
||||
getAccountParams GetAccountParams
|
||||
deleteAccountParams DeleteAccountParams
|
||||
listAccountsParams ListAccountsParams
|
||||
commonAccountParams CommonAccountParams
|
||||
}
|
||||
|
||||
type CommonAccountParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "account",
|
||||
Short: "Account operation",
|
||||
Use: "accounts",
|
||||
Short: "Account operation",
|
||||
Aliases: []string{"account"},
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Username, "user", "u", "", "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "p", "", "Password")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
subCmd.MarkPersistentFlagRequired("host")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
// CreateAccount
|
||||
var createAccountCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create user account",
|
||||
Run: util.CreateAccount,
|
||||
}
|
||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Username, "user", "u", "", "Username")
|
||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Password, "pass", "p", "", "Password")
|
||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
createAccountCmd.Flags().Uint64VarP(&util.createAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewUsername, "newuser", "U", "", "New account username")
|
||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewPassword, "newpass", "P", "", "New account password")
|
||||
createAccountCmd.MarkFlagRequired("host")
|
||||
createAccountCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
||||
createAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(createAccountCmd)
|
||||
|
||||
// GetAccount
|
||||
@@ -57,38 +74,23 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
Short: "Get account info",
|
||||
Run: util.GetAccount,
|
||||
}
|
||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Username, "user", "u", "", "Username")
|
||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Password, "pass", "p", "", "Password")
|
||||
getAccountCmd.Flags().Uint64VarP(&util.getAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
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.MarkFlagRequired("host")
|
||||
getAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||
getAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(getAccountCmd)
|
||||
|
||||
// UpdateAccount
|
||||
var updateAccountCmd = &cobra.Command{
|
||||
Use: "info",
|
||||
Use: "update",
|
||||
Short: "Update account parameters",
|
||||
Run: util.UpdateAccount,
|
||||
}
|
||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Username, "user", "u", "", "Username")
|
||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Password, "pass", "p", "", "Password")
|
||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Hostname, "host", "x", "", "File path")
|
||||
updateAccountCmd.Flags().Uint64VarP(&util.updateAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
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.NewPassword, "newpass", "P", "", "New password")
|
||||
updateAccountCmd.MarkFlagRequired("host")
|
||||
updateAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
||||
|
||||
subCmd.AddCommand(updateAccountCmd)
|
||||
|
||||
// DeleteAccount
|
||||
@@ -97,85 +99,71 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
Short: "Delete account",
|
||||
Run: util.DeleteAccount,
|
||||
}
|
||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Username, "user", "u", "", "Username")
|
||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Password, "pass", "p", "", "Password")
|
||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
deleteAccountCmd.Flags().Uint64VarP(&util.deleteAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.AccountID, "id", "I", "", "Account ID")
|
||||
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
||||
deleteAccountCmd.MarkFlagRequired("host")
|
||||
deleteAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||
deleteAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(deleteAccountCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccountsCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "accounts",
|
||||
Short: "Accounts operation",
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
// ListAccounts
|
||||
// ListAccount
|
||||
var listAccountsCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "list accounts",
|
||||
Run: util.ListAccounts,
|
||||
}
|
||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Username, "user", "u", "", "Username")
|
||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Password, "pass", "p", "", "Password")
|
||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
listAccountsCmd.Flags().Uint64VarP(&util.listAccountsParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
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.MarkFlagRequired("host")
|
||||
|
||||
subCmd.AddCommand(listAccountsCmd)
|
||||
return subCmd
|
||||
}
|
||||
|
||||
type AccountUtil struct {
|
||||
createAccountParams CreateAccountParams
|
||||
updateAccountParams UpdateAccountParams
|
||||
getAccountParams GetAccountParams
|
||||
deleteAccountParams DeleteAccountParams
|
||||
listAccountsParams ListAccountsParams
|
||||
return subCmd
|
||||
}
|
||||
|
||||
// CreateAccount
|
||||
type CreateAccountParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
NewUsername string
|
||||
NewPassword string
|
||||
Timeout uint64
|
||||
}
|
||||
type CreateAccountResult struct {
|
||||
AccountID string
|
||||
AccountID string `json:"accountId"`
|
||||
GrantIDs []string `json:"grantsIds,omitempty"`
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
res, err := util.createAccount(&util.createAccountParams)
|
||||
res, err := util.createAccount(&util.commonAccountParams, &util.createAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *AccountUtil) createAccount(params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &CreateAccountResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.NewUsername, params.NewPassword)
|
||||
res := &CreateAccountResult{
|
||||
GrantIDs: make([]string, 0),
|
||||
}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
accountID, err := client.NewClient().CreateAccount(ctx, params.Hostname, params.NewUsername, params.NewPassword)
|
||||
accountID, err := client.NewClient().CreateAccount(ctx, hostname, params.NewUsername, params.NewPassword)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
fullRights := []string{
|
||||
descr.RightWriteAccounts,
|
||||
descr.RightReadAccounts,
|
||||
descr.RightWriteFiles,
|
||||
descr.RightReadFiles,
|
||||
descr.RightWriteImages,
|
||||
descr.RightReadImages,
|
||||
}
|
||||
for _, right := range fullRights {
|
||||
id, err := client.NewClient().CreateGrant(ctx, hostname, accountID, right, ".*")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.GrantIDs = append(res.GrantIDs, id)
|
||||
}
|
||||
res.AccountID = accountID
|
||||
return res, err
|
||||
}
|
||||
@@ -195,25 +183,25 @@ type UpdateAccountResult struct {
|
||||
}
|
||||
|
||||
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
||||
res, err := util.updateAccount(&util.updateAccountParams)
|
||||
res, err := util.updateAccount(&util.commonAccountParams, &util.updateAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *AccountUtil) updateAccount(params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
||||
func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
||||
var err error
|
||||
res := &UpdateAccountResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
err = client.NewClient().UpdateAccountByID(ctx, params.Hostname, id, params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
|
||||
} else {
|
||||
err = client.NewClient().UpdateAccountByName(ctx, params.Hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -231,7 +219,7 @@ type GetAccountParams struct {
|
||||
}
|
||||
|
||||
func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
||||
res, err := util.getAccount(&util.getAccountParams)
|
||||
res, err := util.getAccount(&util.commonAccountParams, &util.getAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
@@ -239,23 +227,23 @@ type GetAccountResult struct {
|
||||
Account *descr.AccountShort `json:"account,omitempty"`
|
||||
}
|
||||
|
||||
func (util *AccountUtil) getAccount(params *GetAccountParams) (*GetAccountResult, error) {
|
||||
func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAccountParams) (*GetAccountResult, error) {
|
||||
var err error
|
||||
res := &GetAccountResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
opRes := &descr.AccountShort{}
|
||||
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
opRes, err = client.NewClient().GetAccountByID(ctx, params.Hostname, id)
|
||||
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
opRes, err = client.NewClient().GetAccountByName(ctx, params.Hostname, params.AccountID)
|
||||
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -276,24 +264,24 @@ type DeleteAccountParams struct {
|
||||
type DeleteAccountResult struct{}
|
||||
|
||||
func (util *AccountUtil) DeleteAccount(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteAccount(&util.deleteAccountParams)
|
||||
res, err := util.deleteAccount(&util.commonAccountParams, &util.deleteAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *AccountUtil) deleteAccount(params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
||||
func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
||||
var err error
|
||||
res := &DeleteAccountResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
err = client.NewClient().DeleteAccountByID(ctx, params.Hostname, id)
|
||||
err = client.NewClient().DeleteAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
err = client.NewClient().DeleteAccountByName(ctx, params.Hostname, params.AccountID)
|
||||
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -311,19 +299,24 @@ type ListAccountsParams struct {
|
||||
Regex string
|
||||
}
|
||||
|
||||
type Userinfo struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Rights []string `json:"rights,omitempty"`
|
||||
}
|
||||
|
||||
type ListAccountsResult struct {
|
||||
Accounts []descr.AccountShort `json:"accounts,omitempty"`
|
||||
Usernames []string `json:"names,omitempty"`
|
||||
Accounts []descr.AccountShort `json:"accounts,omitempty"`
|
||||
Users []Userinfo `json:"users,omitempty"`
|
||||
}
|
||||
|
||||
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
||||
res, err := util.listAccounts(&util.listAccountsParams)
|
||||
res, err := util.listAccounts(&util.commonAccountParams, &util.listAccountsParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccountsResult, error) {
|
||||
func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListAccountsParams) (*ListAccountsResult, error) {
|
||||
var err error
|
||||
res := &ListAccountsResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -332,9 +325,9 @@ func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccounts
|
||||
return res, err
|
||||
}
|
||||
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
accounts, err := client.NewClient().ListAccounts(ctx, params.Hostname)
|
||||
accounts, err := client.NewClient().ListAccounts(ctx, hostname)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -351,9 +344,16 @@ func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccounts
|
||||
if params.Detail {
|
||||
res.Accounts = outAccounts
|
||||
} else {
|
||||
res.Usernames = make([]string, 0)
|
||||
for _, item := range outAccounts {
|
||||
res.Usernames = append(res.Usernames, item.Username)
|
||||
res.Users = make([]Userinfo, 0)
|
||||
for _, account := range outAccounts {
|
||||
userinfo := Userinfo{
|
||||
Username: account.Username,
|
||||
Rights: make([]string, 0),
|
||||
}
|
||||
for _, grant := range account.Grants {
|
||||
userinfo.Rights = append(userinfo.Rights, grant.Right)
|
||||
}
|
||||
res.Users = append(res.Users, userinfo)
|
||||
}
|
||||
}
|
||||
return res, err
|
||||
|
||||
+53
-82
@@ -22,40 +22,42 @@ import (
|
||||
|
||||
func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "file",
|
||||
Short: "File operation",
|
||||
Use: "files",
|
||||
Short: "File operation",
|
||||
Aliases: []string{"file"},
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonFileParams.Username, "user", "u", "", "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonFileParams.Password, "pass", "p", "", "Password")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
subCmd.MarkPersistentFlagRequired("host")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
// PutFile
|
||||
var putFileCmd = &cobra.Command{
|
||||
Use: "put",
|
||||
Short: "Put file to storage",
|
||||
Run: util.PutFile,
|
||||
Use: "put",
|
||||
Aliases: []string{"push"},
|
||||
Short: "Put file to storage",
|
||||
Run: util.PutFile,
|
||||
}
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Username, "user", "u", "", "Username")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Password, "pass", "p", "", "Password")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Source, "src", "s", "", "Source path")
|
||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||
putFileCmd.Flags().Uint64VarP(&util.putFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
putFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
||||
putFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
putFileCmd.MarkFlagFilename("src")
|
||||
|
||||
subCmd.AddCommand(putFileCmd)
|
||||
|
||||
// GetFile
|
||||
var getFileCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get file from storage",
|
||||
Run: util.GetFile,
|
||||
Use: "get",
|
||||
Aliases: []string{"pull"},
|
||||
Short: "Get file from storage",
|
||||
Run: util.GetFile,
|
||||
}
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Username, "user", "u", "", "Username")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Password, "pass", "p", "", "Password")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Source, "src", "s", "", "Source path")
|
||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||
getFileCmd.Flags().Uint64VarP(&util.getFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
getFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
||||
getFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(getFileCmd)
|
||||
|
||||
@@ -65,53 +67,30 @@ func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
||||
Short: "Show file information",
|
||||
Run: util.FileInfo,
|
||||
}
|
||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Username, "user", "u", "", "Username")
|
||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Password, "pass", "p", "", "Password")
|
||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Filepath, "path", "d", "", "File path")
|
||||
fileInfoCmd.Flags().Uint64VarP(&util.fileInfoParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
fileInfoCmd.MarkFlagRequired("path")
|
||||
fileInfoCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(fileInfoCmd)
|
||||
|
||||
// DeleteFile
|
||||
var deleteFileCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete file in storage",
|
||||
Run: util.DeleteFile,
|
||||
Use: "delete",
|
||||
Aliases: []string{"remove"},
|
||||
Short: "Delete file in storage",
|
||||
Run: util.DeleteFile,
|
||||
}
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Username, "user", "u", "", "Username")
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Password, "pass", "p", "", "Password")
|
||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Filepath, "path", "d", "", "File path")
|
||||
deleteFileCmd.Flags().Uint64VarP(&util.deleteFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
deleteFileCmd.MarkFlagRequired("path")
|
||||
deleteFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(deleteFileCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
func (util *FileUtil) CreateFilesCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "files",
|
||||
Short: "Files operation",
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
|
||||
// ListFiles
|
||||
var listFilesCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List file in storage",
|
||||
Run: util.ListFiles,
|
||||
}
|
||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Username, "user", "u", "", "Username")
|
||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Password, "pass", "p", "", "Password")
|
||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Filepath, "catalog", "c", "", "Catalog path")
|
||||
listFilesCmd.Flags().Uint64VarP(&util.listFilesParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
listFilesCmd.MarkFlagRequired("catalog")
|
||||
listFilesCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(listFilesCmd)
|
||||
|
||||
return subCmd
|
||||
@@ -123,32 +102,36 @@ type FileUtil struct {
|
||||
getFileParams GetFileParams
|
||||
deleteFileParams DeleteFileParams
|
||||
listFilesParams ListFilesParams
|
||||
commonFileParams CommonFileParams
|
||||
}
|
||||
|
||||
type CommonFileParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
}
|
||||
|
||||
// FileInfo
|
||||
type FileInfoParams struct {
|
||||
Filepath string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
}
|
||||
type FileInfoResult struct {
|
||||
File *descr.File `json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {
|
||||
res, err := util.fileInfo(&util.fileInfoParams)
|
||||
res, err := util.fileInfo(&util.commonFileParams, &util.fileInfoParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *FileUtil) fileInfo(params *FileInfoParams) (*FileInfoResult, error) {
|
||||
func (util *FileUtil) fileInfo(common *CommonFileParams, params *FileInfoParams) (*FileInfoResult, error) {
|
||||
var err error
|
||||
res := &FileInfoResult{}
|
||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
||||
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
exists, opres, err := client.NewClient().FileInfo(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
@@ -164,27 +147,24 @@ func (util *FileUtil) fileInfo(params *FileInfoParams) (*FileInfoResult, error)
|
||||
|
||||
// PutFile
|
||||
type PutFileParams struct {
|
||||
Source string
|
||||
Dest string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
Source string
|
||||
Dest string
|
||||
}
|
||||
type PutFileResult struct{}
|
||||
|
||||
func (util *FileUtil) PutFile(cmd *cobra.Command, args []string) {
|
||||
res, err := util.putFile(&util.putFileParams)
|
||||
res, err := util.putFile(&util.commonFileParams, &util.putFileParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *FileUtil) putFile(params *PutFileParams) (*PutFileResult, error) {
|
||||
func (util *FileUtil) putFile(common *CommonFileParams, params *PutFileParams) (*PutFileResult, error) {
|
||||
var err error
|
||||
res := &PutFileResult{}
|
||||
params.Dest, err = packUserinfo(params.Dest, params.Username, params.Password)
|
||||
params.Dest, err = packUserinfo(params.Dest, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
err = client.NewClient().PutFile(ctx, params.Source, params.Dest)
|
||||
if err != nil {
|
||||
@@ -195,28 +175,25 @@ func (util *FileUtil) putFile(params *PutFileParams) (*PutFileResult, error) {
|
||||
|
||||
// Get file
|
||||
type GetFileParams struct {
|
||||
Source string
|
||||
Dest string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
Source string
|
||||
Dest string
|
||||
}
|
||||
|
||||
func (util *FileUtil) GetFile(cmd *cobra.Command, args []string) {
|
||||
res, err := util.getFile(&util.getFileParams)
|
||||
res, err := util.getFile(&util.commonFileParams, &util.getFileParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type GetFileResult struct{}
|
||||
|
||||
func (util *FileUtil) getFile(params *GetFileParams) (*GetFileResult, error) {
|
||||
func (util *FileUtil) getFile(common *CommonFileParams, params *GetFileParams) (*GetFileResult, error) {
|
||||
var err error
|
||||
res := &GetFileResult{}
|
||||
params.Dest, err = packUserinfo(params.Source, params.Username, params.Password)
|
||||
params.Dest, err = packUserinfo(params.Source, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
_, err = client.NewClient().GetFile(ctx, params.Dest, params.Source)
|
||||
if err != nil {
|
||||
@@ -228,25 +205,22 @@ func (util *FileUtil) getFile(params *GetFileParams) (*GetFileResult, error) {
|
||||
// DeleteFile
|
||||
type DeleteFileParams struct {
|
||||
Filepath string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
}
|
||||
|
||||
type DeleteFileResult struct{}
|
||||
|
||||
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteFile(&util.deleteFileParams)
|
||||
res, err := util.deleteFile(&util.commonFileParams, &util.deleteFileParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *FileUtil) deleteFile(params *DeleteFileParams) (*DeleteFileResult, error) {
|
||||
func (util *FileUtil) deleteFile(common *CommonFileParams, params *DeleteFileParams) (*DeleteFileResult, error) {
|
||||
var err error
|
||||
res := &DeleteFileResult{}
|
||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
||||
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
err = client.NewClient().DeleteFile(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
@@ -258,9 +232,6 @@ func (util *FileUtil) deleteFile(params *DeleteFileParams) (*DeleteFileResult, e
|
||||
// ListFiles
|
||||
type ListFilesParams struct {
|
||||
Filepath string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
}
|
||||
|
||||
type ListFilesResult struct {
|
||||
@@ -268,17 +239,17 @@ type ListFilesResult struct {
|
||||
}
|
||||
|
||||
func (util *FileUtil) ListFiles(cmd *cobra.Command, args []string) {
|
||||
res, err := util.listFiles(&util.listFilesParams)
|
||||
res, err := util.listFiles(&util.commonFileParams, &util.listFilesParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *FileUtil) listFiles(params *ListFilesParams) (*ListFilesResult, error) {
|
||||
func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParams) (*ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{}
|
||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
||||
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
|
||||
+55
-100
@@ -23,28 +23,28 @@ import (
|
||||
|
||||
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "account",
|
||||
Short: "Grant operation",
|
||||
Use: "grants",
|
||||
Short: "Grant operation",
|
||||
Aliases: []string{"grant"},
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Username, "user", "u", "", "Username")
|
||||
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.MarkPersistentFlagRequired("host")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
// CreateGrant
|
||||
var createGrantCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create grant",
|
||||
Run: util.CreateGrant,
|
||||
}
|
||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Username, "username", "u", "", "Username")
|
||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Password, "password", "p", "", "Password")
|
||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
createGrantCmd.Flags().Uint64VarP(&util.createGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Right, "newuser", "U", "", "New account username")
|
||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Pattern, "newpass", "P", "", "New account password")
|
||||
createGrantCmd.MarkFlagRequired("host")
|
||||
createGrantCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
||||
createGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
||||
|
||||
subCmd.AddCommand(createGrantCmd)
|
||||
|
||||
// GetGrant
|
||||
@@ -53,17 +53,9 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
Short: "Get detail grant info",
|
||||
Run: util.GetGrant,
|
||||
}
|
||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Username, "username", "u", "", "Username")
|
||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Password, "password", "p", "", "Password")
|
||||
getGrantCmd.Flags().Uint64VarP(&util.getGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
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.MarkFlagRequired("host")
|
||||
getGrantCmd.MarkFlagsOneRequired("id", "name")
|
||||
getGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
||||
|
||||
subCmd.AddCommand(getGrantCmd)
|
||||
|
||||
// UpdateGrant
|
||||
@@ -72,18 +64,13 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
Short: "Update grant parameters",
|
||||
Run: util.UpdateGrant,
|
||||
}
|
||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Username, "username", "u", "", "Username")
|
||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Password, "password", "p", "", "Password")
|
||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Hostname, "host", "x", "", "File path")
|
||||
updateGrantCmd.Flags().Uint64VarP(&util.updateGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
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, "newuser", "U", "", "New username")
|
||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Pattern, "pass", "P", "", "New password")
|
||||
updateGrantCmd.MarkFlagRequired("host")
|
||||
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)
|
||||
|
||||
// DeleteGrant
|
||||
@@ -92,44 +79,24 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
Short: "Delete grant",
|
||||
Run: util.DeleteGrant,
|
||||
}
|
||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Username, "username", "u", "", "Username")
|
||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Password, "password", "p", "", "Password")
|
||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
deleteGrantCmd.Flags().Uint64VarP(&util.deleteGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
|
||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.GrantID, "id", "I", "", "Grant ID")
|
||||
deleteGrantCmd.MarkFlagRequired("host")
|
||||
deleteGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
||||
|
||||
deleteGrantCmd.MarkFlagRequired("id")
|
||||
subCmd.AddCommand(deleteGrantCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
func (util *GrantUtil) CreateGrantsCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "grans",
|
||||
Short: "Grants operation",
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
// ListGrants
|
||||
var listGrantsCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "list user grants",
|
||||
Run: util.ListGrants,
|
||||
}
|
||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Username, "username", "u", "", "Username")
|
||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Password, "password", "p", "", "Password")
|
||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
listGrantsCmd.Flags().Uint64VarP(&util.listGrantsParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
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)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
@@ -139,37 +106,41 @@ type GrantUtil struct {
|
||||
getGrantParams GetGrantParams
|
||||
deleteGrantParams DeleteGrantParams
|
||||
listGrantsParams ListGrantsParams
|
||||
commonGrantParams CommonGrantParams
|
||||
}
|
||||
|
||||
type CommonGrantParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
}
|
||||
|
||||
// CreateGrant
|
||||
type CreateGrantParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
AccountID string
|
||||
Right string
|
||||
Pattern string
|
||||
Timeout uint64
|
||||
}
|
||||
type CreateGrantResult struct {
|
||||
GrantID string `json:"grantId"`
|
||||
}
|
||||
|
||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
res, err := util.createGrant(&util.createGrantParams)
|
||||
res, err := util.createGrant(&util.commonGrantParams, &util.createGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *GrantUtil) createGrant(params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||
func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||
var err error
|
||||
res := &CreateGrantResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Right, params.Pattern)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
accountID, err := client.NewClient().CreateGrant(ctx, params.Hostname, params.AccountID, params.Right, params.Pattern)
|
||||
accountID, err := client.NewClient().CreateGrant(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -179,32 +150,28 @@ func (util *GrantUtil) createGrant(params *CreateGrantParams) (*CreateGrantResul
|
||||
|
||||
// UpdateGrant
|
||||
type UpdateGrantParams struct {
|
||||
Hostname string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
GrantID string
|
||||
Right string
|
||||
Pattern string
|
||||
GrantID string
|
||||
Right string
|
||||
Pattern string
|
||||
}
|
||||
type UpdateGrantResult struct{}
|
||||
|
||||
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
||||
res, err := util.updateGrant(&util.updateGrantParams)
|
||||
res, err := util.updateGrant(&util.commonGrantParams, &util.updateGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *GrantUtil) updateGrant(params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||
func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||
var err error
|
||||
res := &UpdateGrantResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient().UpdateGrant(ctx, params.Hostname, id, params.Pattern)
|
||||
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -213,11 +180,7 @@ func (util *GrantUtil) updateGrant(params *UpdateGrantParams) (*UpdateGrantResul
|
||||
|
||||
// GetGrant
|
||||
type GetGrantParams struct {
|
||||
Hostname string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
GrantID string
|
||||
GrantID string
|
||||
}
|
||||
|
||||
type GetGrantResult struct {
|
||||
@@ -225,23 +188,23 @@ type GetGrantResult struct {
|
||||
}
|
||||
|
||||
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
||||
res, err := util.getGrant(&util.getGrantParams)
|
||||
res, err := util.getGrant(&util.commonGrantParams, &util.getGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *GrantUtil) getGrant(params *GetGrantParams) (*GetGrantResult, error) {
|
||||
func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParams) (*GetGrantResult, error) {
|
||||
var err error
|
||||
res := &GetGrantResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
opRes := &descr.Grant{}
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
opRes, err = client.NewClient().GetGrant(ctx, params.Hostname, id)
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -251,30 +214,26 @@ func (util *GrantUtil) getGrant(params *GetGrantParams) (*GetGrantResult, error)
|
||||
|
||||
// DeleteGrant
|
||||
type DeleteGrantParams struct {
|
||||
Hostname string
|
||||
Username string
|
||||
Password string
|
||||
GrantID string
|
||||
Timeout uint64
|
||||
GrantID string
|
||||
}
|
||||
|
||||
type DeleteGrantResult struct{}
|
||||
|
||||
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteGrant(&util.deleteGrantParams)
|
||||
res, err := util.deleteGrant(&util.commonGrantParams, &util.deleteGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *GrantUtil) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||
func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||
var err error
|
||||
res := &DeleteGrantResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient().DeleteGrant(ctx, params.Hostname, id)
|
||||
err = client.NewClient().DeleteGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -283,10 +242,6 @@ func (util *GrantUtil) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResul
|
||||
|
||||
// ListGrants
|
||||
type ListGrantsParams struct {
|
||||
Hostname string
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
Detail bool
|
||||
AccountID string
|
||||
}
|
||||
@@ -297,25 +252,25 @@ type ListGrantsResult struct {
|
||||
}
|
||||
|
||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||
res, err := util.listGrants(&util.listGrantsParams)
|
||||
res, err := util.listGrants(&util.commonGrantParams, &util.listGrantsParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
func (util *GrantUtil) listGrants(params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||
func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||
var err error
|
||||
res := &ListGrantsResult{}
|
||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
grants := make([]descr.Grant, 0)
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, params.Hostname, params.AccountID)
|
||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, params.AccountID)
|
||||
} else {
|
||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, params.Hostname, params.AccountID)
|
||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
||||
+36
-52
@@ -43,24 +43,25 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
const defaultTimeout uint64 = 30 // Second
|
||||
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "image",
|
||||
Short: "Image operation",
|
||||
Use: "images",
|
||||
Short: "Image operation",
|
||||
Aliases: []string{"image"},
|
||||
}
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonImageParams.Username, "user", "u", "", "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonImageParams.Password, "pass", "p", "", "Password")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
// PushImage
|
||||
var pushImageCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "Pull container image into local file",
|
||||
Short: "Push container image from local tar file into registry",
|
||||
Run: util.PushImage,
|
||||
}
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Username, "user", "u", "", "Username")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Password, "pass", "p", "", "Password")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local file path")
|
||||
pushImageCmd.Flags().Uint64VarP(&util.pushImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local tar file path")
|
||||
pushImageCmd.MarkFlagRequired("image")
|
||||
pushImageCmd.MarkFlagRequired("file")
|
||||
pushImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(pushImageCmd)
|
||||
|
||||
@@ -70,46 +71,34 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
Short: "Show container image info",
|
||||
Run: util.ImageInfo,
|
||||
}
|
||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Username, "user", "u", "", "Username")
|
||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Password, "pass", "p", "", "Password")
|
||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
imageInfoCmd.Flags().Uint64VarP(&util.imageInfoParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
imageInfoCmd.MarkFlagRequired("image")
|
||||
imageInfoCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(imageInfoCmd)
|
||||
|
||||
// PullImage
|
||||
var pullImageCmd = &cobra.Command{
|
||||
Use: "pull",
|
||||
Short: "Pull container image into local file",
|
||||
Short: "Pull container image from registry into local file",
|
||||
Run: util.PullImage,
|
||||
}
|
||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Username, "user", "u", "", "Username")
|
||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Password, "pass", "p", "", "Password")
|
||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Filepath, "file", "f", "", "Local file path")
|
||||
pullImageCmd.Flags().Uint64VarP(&util.pullImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
pullImageCmd.MarkFlagRequired("image")
|
||||
pullImageCmd.MarkFlagRequired("file")
|
||||
pullImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(pullImageCmd)
|
||||
|
||||
// DeleteImage
|
||||
var deleteImageCmd = &cobra.Command{
|
||||
Use: "info",
|
||||
Short: "Show container image info",
|
||||
Use: "delete",
|
||||
Short: "Delete container image from registry",
|
||||
Run: util.DeleteImage,
|
||||
}
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Username, "user", "u", "", "Username")
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Password, "pass", "p", "", "Password")
|
||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||
deleteImageCmd.Flags().Uint64VarP(&util.deleteImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
deleteImageCmd.MarkFlagRequired("image")
|
||||
deleteImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
subCmd.AddCommand(imageInfoCmd)
|
||||
subCmd.AddCommand(deleteImageCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
@@ -119,32 +108,36 @@ type ImageUtil struct {
|
||||
pullImageParams PullImageParams
|
||||
pushImageParams PushImageParams
|
||||
deleteImageParams DeleteImageParams
|
||||
commonImageParams CommonImageParams
|
||||
}
|
||||
|
||||
type CommonImageParams struct {
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
// PushImage
|
||||
type PushImageParams struct {
|
||||
Imagepath string
|
||||
Filepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type PushImageResult struct{}
|
||||
|
||||
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.pushImage(&util.pushImageParams)
|
||||
res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, error) {
|
||||
func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -159,9 +152,6 @@ func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, err
|
||||
// ImageInfo
|
||||
type ImageInfoParams struct {
|
||||
Imagepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type ImageInfoResult struct {
|
||||
@@ -169,19 +159,19 @@ type ImageInfoResult struct {
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageInfo(cmd *cobra.Command, args []string) {
|
||||
res, err := util.imageInfo(&util.imageInfoParams)
|
||||
res, err := util.imageInfo(&util.commonImageParams, &util.imageInfoParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageInfo(params *ImageInfoParams) (*ImageInfoResult, error) {
|
||||
func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageInfoParams) (*ImageInfoResult, error) {
|
||||
var err error
|
||||
res := &ImageInfoResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -198,27 +188,24 @@ func (util *ImageUtil) imageInfo(params *ImageInfoParams) (*ImageInfoResult, err
|
||||
type PullImageParams struct {
|
||||
Imagepath string
|
||||
Filepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type PullImageResult struct{}
|
||||
|
||||
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.pullImage(&util.pullImageParams)
|
||||
res, err := util.pullImage(&util.commonImageParams, &util.pullImageParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, error) {
|
||||
func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
res := &PullImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -233,28 +220,25 @@ func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, err
|
||||
// DeleteImage
|
||||
type DeleteImageParams struct {
|
||||
Imagepath string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type DeleteImageResult struct {
|
||||
}
|
||||
|
||||
func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteImage(&util.deleteImageParams)
|
||||
res, err := util.deleteImage(&util.commonImageParams, &util.deleteImageParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) deleteImage(params *DeleteImageParams) (*DeleteImageResult, error) {
|
||||
func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImageParams) (*DeleteImageResult, error) {
|
||||
var err error
|
||||
res := &DeleteImageResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -52,15 +52,11 @@ func (util *Util) Build() error {
|
||||
SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
rootCmd.AddCommand(util.CreateFileCmds())
|
||||
rootCmd.AddCommand(util.CreateFilesCmds())
|
||||
rootCmd.AddCommand(util.CreateImageCmds())
|
||||
|
||||
rootCmd.AddCommand(util.CreateAccountCmds())
|
||||
rootCmd.AddCommand(util.CreateAccountsCmds())
|
||||
|
||||
rootCmd.AddCommand(util.CreateGrantCmds())
|
||||
rootCmd.AddCommand(util.CreateGrantsCmds())
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
|
||||
|
||||
Reference in New Issue
Block a user