added skip vetify of server cert

This commit is contained in:
2026-02-21 14:07:19 +02:00
parent 7be3cf8de7
commit b2c60c41c4
15 changed files with 113 additions and 94 deletions
+17 -16
View File
@@ -42,6 +42,7 @@ type CommonAccountParams struct {
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
}
+12 -10
View File
@@ -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")
@@ -184,6 +185,7 @@ type CommonFileParams struct {
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
}
+9 -7
View File
@@ -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")
@@ -106,6 +107,7 @@ type CommonGrantParams struct {
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
+6 -4
View File
@@ -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()
@@ -112,6 +113,7 @@ type CommonImageParams struct {
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)
+8 -8
View File
@@ -35,7 +35,7 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apiuri, paramsJson)
if err != nil {
return res, err
}
@@ -69,7 +69,7 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, accountID string
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
@@ -102,7 +102,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
@@ -136,7 +136,7 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi string, accoun
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -167,7 +167,7 @@ func (cli *Client) UpdateAccountByName(ctx context.Context, hosturi, username, n
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -197,7 +197,7 @@ func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username st
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -228,7 +228,7 @@ func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi, accountID str
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -258,7 +258,7 @@ func (cli *Client) ListAccounts(ctx context.Context, hosturi string) ([]descr.Ac
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
+8 -4
View File
@@ -9,8 +9,12 @@
*/
package client
type Client struct{}
func NewClient() *Client {
return &Client{}
type Client struct {
skipTLSVerify bool
}
func NewClient(skipTLSVerify bool) *Client {
return &Client{
skipTLSVerify: skipTLSVerify,
}
}
+7 -7
View File
@@ -45,7 +45,7 @@ func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.F
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return exists, file, err
@@ -100,7 +100,7 @@ func (cli *Client) PutFile(ctx context.Context, filename, fileuri string) error
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
@@ -135,7 +135,7 @@ func (cli *Client) GetFile(ctx context.Context, fileuri, filename string) (int64
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return size, err
@@ -195,7 +195,7 @@ func (cli *Client) DeleteFile(ctx context.Context, fileuri string) error {
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return err
@@ -238,7 +238,7 @@ func (cli *Client) ListFiles(ctx context.Context, catalogURI, usePathAs string)
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return res, err
@@ -307,7 +307,7 @@ func (cli *Client) ListCollections(ctx context.Context, catalogURI, usePathAs st
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return res, err
@@ -378,7 +378,7 @@ func (cli *Client) DeleteCollection(ctx context.Context, catalogURI, usePathAs s
basic := auxhttp.EncodeBasicAuth(username, password)
req.Header.Add("Authorization", basic)
}
client := makeHTTPClient()
client := makeHTTPClient(cli.skipTLSVerify)
resp, err := client.Do(req)
if err != nil {
return res, err
+2 -2
View File
@@ -17,10 +17,10 @@ import (
"strings"
)
func makeHTTPClient() *http.Client {
func makeHTTPClient(skipTLSVerify bool) *http.Client {
transport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: skipTLSVerify,
},
}
client := &http.Client{
+7 -7
View File
@@ -36,7 +36,7 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi string, a
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apiuri, paramsJson)
if err != nil {
return res, err
}
@@ -71,7 +71,7 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apiuri, paramsJson)
if err != nil {
return res, err
}
@@ -104,7 +104,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, grantID string) (*desc
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
@@ -137,7 +137,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -167,7 +167,7 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return err
}
@@ -199,7 +199,7 @@ func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
@@ -232,7 +232,7 @@ func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username s
if err != nil {
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
respBytes, err := doHTTPCall(ctx, cli.skipTLSVerify, apipath, paramsJson)
if err != nil {
return res, err
}
+2 -2
View File
@@ -41,7 +41,7 @@ func setApiPath(base, apipath string) (string, error) {
}
func doHTTPCall(ctx context.Context, apiuri string, reqBytes []byte) ([]byte, error) {
func doHTTPCall(ctx context.Context, skipTLSVerify bool, apiuri string, reqBytes []byte) ([]byte, error) {
var err error
respBytes := make([]byte, 0)
@@ -60,7 +60,7 @@ func doHTTPCall(ctx context.Context, apiuri string, reqBytes []byte) ([]byte, er
httpReq.Header.Add("Authorization", basicHeader)
}
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTLSVerify},
}
httpClient := &http.Client{
Transport: transport,
+11 -3
View File
@@ -16,11 +16,19 @@ import (
"strings"
)
type roundTripper struct{}
type RoundTripper struct {
skipTLSVerify bool
}
func (t *roundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
func NewRoundTripper(skipTLSVerify bool) *RoundTripper {
return &RoundTripper{
skipTLSVerify: skipTLSVerify,
}
}
func (t *RoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: t.skipTLSVerify,
}
httpTransport := &http.Transport{
TLSClientConfig: tlsConfig,
+2 -2
View File
@@ -38,7 +38,7 @@ func (cli *Client) DeleteImage(ctx context.Context, imagepath string) error {
}
if username != "" && password != "" {
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
scopes := []string{repo.Scope(transport.PullScope)}
regName := repo.RegistryStr()
@@ -56,7 +56,7 @@ func (cli *Client) DeleteImage(ctx context.Context, imagepath string) error {
}
options = append(options, crane.WithTransport(authTransport))
} else {
transport := &roundTripper{}
transport := NewRoundTripper(cli.skipTLSVerify)
options = append(options, crane.WithTransport(transport))
}
+4 -4
View File
@@ -47,7 +47,7 @@ func (cli *Client) ImageInfo(ctx context.Context, imagepath string) (*ImageDescr
}
if username != "" && password != "" {
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
scopes := []string{repo.Scope(transport.PullScope)}
regName := repo.RegistryStr()
@@ -65,7 +65,7 @@ func (cli *Client) ImageInfo(ctx context.Context, imagepath string) (*ImageDescr
}
options = append(options, crane.WithTransport(authTransport))
} else {
transport := &roundTripper{}
transport := NewRoundTripper(cli.skipTLSVerify)
options = append(options, crane.WithTransport(transport))
}
@@ -92,7 +92,7 @@ func (cli *Client) ImageInfo(ctx context.Context, imagepath string) (*ImageDescr
remoteOptions = append(remoteOptions, remote.WithContext(ctx))
if username != "" && password != "" {
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
scopes := []string{repo.Scope(transport.PullScope)}
regName := repo.RegistryStr()
@@ -110,7 +110,7 @@ func (cli *Client) ImageInfo(ctx context.Context, imagepath string) (*ImageDescr
}
remoteOptions = append(remoteOptions, remote.WithTransport(authTransport))
} else {
transport := &roundTripper{}
transport := NewRoundTripper(cli.skipTLSVerify)
options = append(options, crane.WithTransport(transport))
}
+2 -2
View File
@@ -42,7 +42,7 @@ func (cli *Client) PullImage(ctx context.Context, imagepath, filepath string) er
if err != nil {
return err
}
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
scopes := []string{repo.Scope(transport.PullScope)}
@@ -61,7 +61,7 @@ func (cli *Client) PullImage(ctx context.Context, imagepath, filepath string) er
}
options = append(options, crane.WithTransport(authTransport))
} else {
transport := &roundTripper{}
transport := NewRoundTripper(cli.skipTLSVerify)
options = append(options, crane.WithTransport(transport))
}
+2 -2
View File
@@ -43,7 +43,7 @@ func (cli *Client) PushImage(ctx context.Context, filepath, imagepath string) er
if err != nil {
return err
}
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
scopes := []string{
repo.Scope(transport.PushScope),
@@ -66,7 +66,7 @@ func (cli *Client) PushImage(ctx context.Context, filepath, imagepath string) er
}
options = append(options, crane.WithTransport(authTransport))
} else {
defaultTransport := &roundTripper{}
defaultTransport := NewRoundTripper(cli.skipTLSVerify)
options = append(options, crane.WithTransport(defaultTransport))
}