Now we can use s3 config to interact with b2

0 views
Skip to first unread message

nor...@perkeep.org

unread,
Jun 17, 2022, 10:36:01 AM6/17/22
to camlistor...@googlegroups.com


https://github.com/perkeep/perkeep/commit/d6bbe05073cdbd14b76627234c3c7e883cebb12c

commit d6bbe05073cdbd14b76627234c3c7e883cebb12c
Author: kalidor <kal...@unixed.fr>
Date: Fri Mar 4 15:48:13 2022 +0100

Now we can use s3 config to interact with b2

diff --git a/pkg/blobserver/s3/s3.go b/pkg/blobserver/s3/s3.go
index d63fd66..b0da9c8 100644
--- a/pkg/blobserver/s3/s3.go
+++ b/pkg/blobserver/s3/s3.go
@@ -136,7 +136,7 @@ func newFromConfigWithTransport(_ blobserver.Loader, config jsonconfig.Obj, tran

ctx := context.TODO() // TODO: 5 min timeout or something?
if !skipStartupCheck {
- info, err := normalizeBucketLocation(ctx, awsSession, hostname, bucket)
+ info, err := normalizeBucketLocation(ctx, awsSession, hostname, bucket, region)
if err != nil {
return nil, err
}
diff --git a/pkg/blobserver/s3/s3_preflight.go b/pkg/blobserver/s3/s3_preflight.go
index 512f931..af5a7ca 100644
--- a/pkg/blobserver/s3/s3_preflight.go
+++ b/pkg/blobserver/s3/s3_preflight.go
@@ -60,13 +60,13 @@ type bucketInfo struct {
// "test.s3-us-west-1.amazonaws.com", and it would return
// endpoint=s3.us-west-1.amazonaws.com, isAWS=true, region=us-west-1 (assuming,
// of course, the bucket is in us-west-1).
-func normalizeBucketLocation(ctx context.Context, cfg client.ConfigProvider, endpoint string, bucket string) (bucketInfo, error) {
+func normalizeBucketLocation(ctx context.Context, cfg client.ConfigProvider, endpoint string, bucket string, configRegion string) (bucketInfo, error) {
if strings.HasPrefix(endpoint, "https://") || strings.HasPrefix(endpoint, "http://") {
return bucketInfo{}, fmt.Errorf("invalid s3 endpoint: must not include uri scheme")
}

svc := s3.New(cfg)
- endpoint, region, err := determineEndpoint(ctx, svc, endpoint, bucket, "")
+ endpoint, region, err := determineEndpoint(ctx, svc, endpoint, bucket, configRegion)
if err != nil {
return bucketInfo{}, err
}
@@ -77,6 +77,14 @@ func normalizeBucketLocation(ctx context.Context, cfg client.ConfigProvider, end
if err != nil {
return bucketInfo{}, err
}
+ // if isAWS is false, this is b2 related, region should be provided
+ if !isAWS {
+ return bucketInfo{
+ endpoint: endpoint,
+ isAWS: isAWS,
+ region: region,
+ }, nil
+ }
// the endpoint should be corrected before being used to determine a region
// or else the region request can fail spuriously
svc.Config.WithEndpoint(endpoint)
Reply all
Reply to author
Forward
0 new messages