From 3e875f2892eaf98b699b07618d0a6eef69e1ea32 Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Mon, 22 Sep 2025 12:28:23 +0200 Subject: [PATCH] objects: bring back support for plain HTTP This got lost during the transition from minio to S3 client. --- client/graphql.go | 2 +- objects/middleware.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/graphql.go b/client/graphql.go index c148d7579d786310f79c3229920b2f8def8551d0..57750f2ad602bc3b2b4dde38fa017a53ca305897 100644 --- a/client/graphql.go +++ b/client/graphql.go @@ -129,7 +129,7 @@ func Do(ctx context.Context, username string, svc string, req.Header.Add("Content-Type", contentType) req.Header.Add("User-Agent", fmt.Sprintf("%s -- SourceHut core-go (https://git.sr.ht/~sircmpwn/core-go)", - config.ServiceName(ctx))) + config.ServiceName(ctx))) auth := InternalAuth{ Name: username, ClientID: config.ServiceName(ctx), diff --git a/objects/middleware.go b/objects/middleware.go index 0c2da48864f81c1163e28389b72a804ff89082d5..efdb4b57bffc601e90fc8e6e7c2871bc6eb5a20a 100644 --- a/objects/middleware.go +++ b/objects/middleware.go @@ -11,6 +11,8 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/smithy-go/endpoints" "github.com/vaughan0/go-ini" + + "git.sr.ht/~sircmpwn/core-go/config" ) var s3CtxKey = &contextKey{"s3"} @@ -76,12 +78,17 @@ func NewClient(conf ini.File) (*s3.Client, error) { region = "default" } + scheme := "https://" + if config.GetBool(conf, "objects", "s3-insecure", false) { + scheme = "http://" + } + creds := credentials.NewStaticCredentialsProvider(accessKey, secretKey, "") return s3.NewFromConfig(aws.Config{ Region: region, Credentials: creds, }, func(opts *s3.Options) { - opts.BaseEndpoint = aws.String("https://" + upstream) + opts.BaseEndpoint = aws.String(scheme + upstream) opts.EndpointResolverV2 = &S3Resolver{ conf, s3.NewDefaultEndpointResolverV2(),