added skip vetify of server cert
This commit is contained in:
+21
-20
@@ -38,10 +38,11 @@ type AccountUtil struct {
|
||||
}
|
||||
|
||||
type CommonAccountParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
SkipTLSVerify bool
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
@@ -52,10 +53,11 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
}
|
||||
const defaultTimeout uint64 = 10
|
||||
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Username, "user", "u", util.commonAccountParams.Username, "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "p", util.commonAccountParams.Password, "Password")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Username, "user", "U", util.commonAccountParams.Username, "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "P", util.commonAccountParams.Password, "Password")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "X", defaultHostname, "Hostname")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "T", defaultTimeout, "Operation timeout")
|
||||
subCmd.PersistentFlags().BoolVarP(&util.commonAccountParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
vi := viper.New()
|
||||
@@ -90,8 +92,8 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.UpdateAccount,
|
||||
}
|
||||
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.NewUsername, "newname", "u", "", "New username")
|
||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "p", "", "New password")
|
||||
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
||||
subCmd.AddCommand(updateAccountCmd)
|
||||
|
||||
@@ -102,7 +104,6 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.DeleteAccount,
|
||||
}
|
||||
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
||||
subCmd.AddCommand(deleteAccountCmd)
|
||||
|
||||
// ListAccount
|
||||
@@ -148,7 +149,7 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
accountID, err := client.NewClient().CreateAccount(ctx, hostname, params.NewUsername, params.NewPassword)
|
||||
accountID, err := client.NewClient(common.SkipTLSVerify).CreateAccount(ctx, hostname, params.NewUsername, params.NewPassword)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -162,7 +163,7 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
||||
terms.RightReadImages,
|
||||
}
|
||||
for _, right := range fullRights {
|
||||
id, err := client.NewClient().CreateGrantByAccountID(ctx, hostname, accountID, right, ".*")
|
||||
id, err := client.NewClient(common.SkipTLSVerify).CreateGrantByAccountID(ctx, hostname, accountID, right, ".*")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -202,9 +203,9 @@ func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *Upda
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient(common.SkipTLSVerify).UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
|
||||
} else {
|
||||
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient(common.SkipTLSVerify).UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -243,9 +244,9 @@ func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAcco
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id)
|
||||
opRes, err = client.NewClient(common.SkipTLSVerify).GetAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
|
||||
opRes, err = client.NewClient(common.SkipTLSVerify).GetAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -280,9 +281,9 @@ func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *Dele
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
err = client.NewClient().DeleteAccountByID(ctx, hostname, id)
|
||||
err = client.NewClient(common.SkipTLSVerify).DeleteAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||
err = client.NewClient(common.SkipTLSVerify).DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -327,7 +328,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
|
||||
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
accounts, err := client.NewClient().ListAccounts(ctx, hostname)
|
||||
accounts, err := client.NewClient(common.SkipTLSVerify).ListAccounts(ctx, hostname)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
+15
-13
@@ -41,6 +41,7 @@ func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
||||
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.PersistentFlags().BoolVarP(&util.commonFileParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
subCmd.MarkPersistentFlagRequired("host")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
@@ -181,9 +182,10 @@ type FileUtil struct {
|
||||
}
|
||||
|
||||
type CommonFileParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
SkipTLSVerify bool
|
||||
}
|
||||
|
||||
// FileInfo
|
||||
@@ -209,7 +211,7 @@ func (util *FileUtil) fileInfo(common *CommonFileParams, params *FileInfoParams)
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
exists, opres, err := client.NewClient().FileInfo(ctx, params.Filepath)
|
||||
exists, opres, err := client.NewClient(common.SkipTLSVerify).FileInfo(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -244,7 +246,7 @@ func (util *FileUtil) putFile(common *CommonFileParams, params *PutFileParams) (
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
err = client.NewClient().PutFile(ctx, params.Source, params.Dest)
|
||||
err = client.NewClient(common.SkipTLSVerify).PutFile(ctx, params.Source, params.Dest)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -275,7 +277,7 @@ func (util *FileUtil) getFile(common *CommonFileParams, params *GetFileParams) (
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
_, err = client.NewClient().GetFile(ctx, params.Dest, params.Source)
|
||||
_, err = client.NewClient(common.SkipTLSVerify).GetFile(ctx, params.Dest, params.Source)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -303,7 +305,7 @@ func (util *FileUtil) deleteFile(common *CommonFileParams, params *DeleteFilePar
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
err = client.NewClient().DeleteFile(ctx, params.Filepath)
|
||||
err = client.NewClient(common.SkipTLSVerify).DeleteFile(ctx, params.Filepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -349,7 +351,7 @@ func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParam
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathUsage)
|
||||
files, err := client.NewClient(common.SkipTLSVerify).ListFiles(ctx, params.Filepath, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -413,7 +415,7 @@ func (util *FileUtil) importFiles(common *CommonFileParams, params *ImportFilesP
|
||||
putErrors = append(putErrors, err)
|
||||
return nil
|
||||
}
|
||||
err = client.NewClient().PutFile(ctx, walkPath, dest)
|
||||
err = client.NewClient(common.SkipTLSVerify).PutFile(ctx, walkPath, dest)
|
||||
if err != nil {
|
||||
putErrors = append(putErrors, err)
|
||||
fmt.Printf("- %s: error: %v \n", walkPath, err)
|
||||
@@ -475,7 +477,7 @@ func (util *FileUtil) exportFiles(common *CommonFileParams, params *ExportFilesP
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathUsage)
|
||||
files, err := client.NewClient(common.SkipTLSVerify).ListFiles(ctx, params.Filepath, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -494,7 +496,7 @@ func (util *FileUtil) exportFiles(common *CommonFileParams, params *ExportFilesP
|
||||
destpath := filepath.Join(params.Dest, file.Collection, file.Name)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
_, err = client.NewClient().GetFile(ctx, srcpath, destpath)
|
||||
_, err = client.NewClient(common.SkipTLSVerify).GetFile(ctx, srcpath, destpath)
|
||||
if err != nil {
|
||||
fmt.Printf("- %s: error %v\n", srcpath, err)
|
||||
//return res, err
|
||||
@@ -564,7 +566,7 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
collecions, err := client.NewClient().ListCollections(ctx, params.Path, pathUsage)
|
||||
collecions, err := client.NewClient(common.SkipTLSVerify).ListCollections(ctx, params.Path, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -610,7 +612,7 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
|
||||
default:
|
||||
pathUsage = terms.AsFinePath
|
||||
}
|
||||
files, err := client.NewClient().DeleteCollection(ctx, params.Path, pathUsage, params.DryRun)
|
||||
files, err := client.NewClient(common.SkipTLSVerify).DeleteCollection(ctx, params.Path, pathUsage, params.DryRun)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
+13
-11
@@ -33,6 +33,7 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Username, "user", "u", "", "Username")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Password, "pass", "p", "", "Password")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||
subCmd.PersistentFlags().BoolVarP(&util.commonGrantParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
|
||||
vi := viper.New()
|
||||
vi.SetEnvPrefix("mstore")
|
||||
@@ -102,10 +103,11 @@ type GrantUtil struct {
|
||||
}
|
||||
|
||||
type CommonGrantParams struct {
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
Hostname string
|
||||
Timeout uint64
|
||||
SkipTLSVerify bool
|
||||
}
|
||||
|
||||
// CreateGrant
|
||||
@@ -140,9 +142,9 @@ func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGran
|
||||
id := strings.ToLower(params.AccountID)
|
||||
var operRes string
|
||||
if re.MatchString(id) {
|
||||
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, id, params.Right, params.Pattern)
|
||||
operRes, err = client.NewClient(common.SkipTLSVerify).CreateGrantByAccountID(ctx, hostname, id, params.Right, params.Pattern)
|
||||
} else {
|
||||
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
operRes, err = client.NewClient(common.SkipTLSVerify).CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -176,7 +178,7 @@ func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGran
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||
err = client.NewClient(common.SkipTLSVerify).UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -212,7 +214,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam
|
||||
opRes := &descr.Grant{}
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, id)
|
||||
opRes, err = client.NewClient(common.SkipTLSVerify).GetGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -243,7 +245,7 @@ func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGran
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient().DeleteGrant(ctx, hostname, id)
|
||||
err = client.NewClient(common.SkipTLSVerify).DeleteGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -280,9 +282,9 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
id := strings.ToLower(params.AccountID)
|
||||
if re.MatchString(id) {
|
||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, id)
|
||||
grants, err = client.NewClient(common.SkipTLSVerify).ListGrantsByAccountID(ctx, hostname, id)
|
||||
} else {
|
||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
grants, err = client.NewClient(common.SkipTLSVerify).ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
||||
@@ -52,6 +52,7 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
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.PersistentFlags().BoolVarP(&util.commonImageParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
vi := viper.New()
|
||||
@@ -109,9 +110,10 @@ type ImageUtil struct {
|
||||
}
|
||||
|
||||
type CommonImageParams struct {
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
Timeout uint64
|
||||
Username string
|
||||
Password string
|
||||
SkipTLSVerify bool
|
||||
}
|
||||
|
||||
// PushImage
|
||||
@@ -135,7 +137,7 @@ func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImagePar
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
@@ -169,7 +171,7 @@ func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageInfoPar
|
||||
res := &ImageInfoResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient()
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
@@ -209,7 +211,7 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
|
||||
ctx := context.Background()
|
||||
res := &PullImageResult{}
|
||||
|
||||
cli := client.NewClient()
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
@@ -249,7 +251,7 @@ func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImag
|
||||
res := &DeleteImageResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient()
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
|
||||
Reference in New Issue
Block a user