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
+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))
}