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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user