From 7f0f173115dd28e3fdcf2aa22a3c56fe7faf35f0 Mon Sep 17 00:00:00 2001 From: schwannden Date: Fri, 29 Oct 2021 01:51:35 +0800 Subject: [PATCH] adding option to skip tls verification error (#30) * adding option to skip tls verification error * merge options * removed merged option from README Co-authored-by: Schwannden Kuo --- cmd/backup/main.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/backup/main.go b/cmd/backup/main.go index f294094..12ff91e 100644 --- a/cmd/backup/main.go +++ b/cmd/backup/main.go @@ -159,11 +159,24 @@ func newScript() (*script, error) { } else { return nil, errors.New("newScript: AWS_S3_BUCKET_NAME is defined, but no credentials were provided") } - - mc, err := minio.New(s.c.AwsEndpoint, &minio.Options{ + options := minio.Options{ Creds: creds, - Secure: !s.c.AwsEndpointInsecure && s.c.AwsEndpointProto == "https", - }) + Secure: s.c.AwsEndpointProto == "https", + } + if s.c.AwsEndpointInsecure { + if options.Secure { + transport, err := minio.DefaultTransport(options.Secure) + if err != nil { + return nil, fmt.Errorf("newScript: failed to create default minio transport") + } + transport.TLSClientConfig.InsecureSkipVerify = true + options.Transport = transport + } else { + return nil, errors.New("newScript: AWS_ENDPOINT_INSECURE = true is only meaningful for https") + } + } + + mc, err := minio.New(s.c.AwsEndpoint, &options) if err != nil { return nil, fmt.Errorf("newScript: error setting up minio client: %w", err) }