~bigbes/core-go

3e875f2892eaf98b699b07618d0a6eef69e1ea32 — Conrad Hoffmann 10 months ago 87bd2cb
objects: bring back support for plain HTTP

This got lost during the transition from minio to S3 client.
2 files changed, 9 insertions(+), 2 deletions(-)

M client/graphql.go
M objects/middleware.go
M client/graphql.go => client/graphql.go +1 -1
@@ 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),

M objects/middleware.go => objects/middleware.go +8 -1
@@ 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(),