mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-16 19:40:46 +02:00
updated aws-sdk-go-v2 and moved the trimmed s3 driver in internal to preven getting included in the jsvm types
This commit is contained in:
@@ -4,12 +4,12 @@ go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7
|
||||
github.com/aws/aws-sdk-go-v2 v1.30.4
|
||||
github.com/aws/aws-sdk-go-v2 v1.32.2
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.31
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.30
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.15
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.60.1
|
||||
github.com/aws/smithy-go v1.20.4
|
||||
github.com/aws/smithy-go v1.22.0
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2
|
||||
github.com/dop251/goja v0.0.0-20241009100908-5f46f2705ca3
|
||||
@@ -59,6 +59,7 @@ require (
|
||||
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
|
||||
@@ -27,6 +27,8 @@ github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU
|
||||
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
|
||||
github.com/aws/aws-sdk-go-v2 v1.30.4 h1:frhcagrVNrzmT95RJImMHgabt99vkXGslubDaDagTk8=
|
||||
github.com/aws/aws-sdk-go-v2 v1.30.4/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
|
||||
github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI=
|
||||
github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4/go.mod h1:/MQxMqci8tlqDH+pjmoLu1i0tbWCUP1hhyMRuFxpQCw=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.31 h1:kxBoRsjhT3pq0cKthgj6RU6bXTm/2SgdoUMyrVw0rAI=
|
||||
@@ -63,6 +65,7 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.30.5 h1:OMsEmCyz2i89XwRwPouAJvhj81wI
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.30.5/go.mod h1:vmSqFK+BVIwVpDAGZB3CoCXHzurt4qBE8lf+I/kRTh0=
|
||||
github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4=
|
||||
github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
|
||||
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
@@ -161,6 +164,7 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@@ -339,6 +343,7 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
+4491
-29517
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem/internal/s3lite"
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
"gocloud.dev/blob"
|
||||
"gocloud.dev/blob/fileblob"
|
||||
@@ -47,25 +48,23 @@ func NewS3(
|
||||
|
||||
cred := credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(ctx,
|
||||
cfg, err := config.LoadDefaultConfig(
|
||||
ctx,
|
||||
config.WithCredentialsProvider(cred),
|
||||
config.WithRegion(region),
|
||||
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
||||
// ensure that the endpoint has url scheme for
|
||||
// backward compatibility with v1 of the aws sdk
|
||||
prefixedEndpoint := endpoint
|
||||
if !strings.Contains(endpoint, "://") {
|
||||
prefixedEndpoint = "https://" + endpoint
|
||||
}
|
||||
|
||||
return aws.Endpoint{URL: prefixedEndpoint, SigningRegion: region}, nil
|
||||
})),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
||||
// ensure that the endpoint has url scheme for
|
||||
// backward compatibility with v1 of the aws sdk
|
||||
if !strings.Contains(endpoint, "://") {
|
||||
endpoint = "https://" + endpoint
|
||||
}
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
|
||||
o.UsePathStyle = s3ForcePathStyle
|
||||
|
||||
// Google Cloud Storage alters the Accept-Encoding header,
|
||||
@@ -76,7 +75,7 @@ func NewS3(
|
||||
}
|
||||
})
|
||||
|
||||
bucket, err := OpenBucketV2(ctx, client, bucketName, nil)
|
||||
bucket, err := s3lite.OpenBucketV2(ctx, client, bucketName, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
// (V1) *s3.PutObjectInput; (V2) *s3v2.PutObjectInput, when Options.Method == http.MethodPut, or
|
||||
// (V1) *s3.DeleteObjectInput; (V2) [not supported] when Options.Method == http.MethodDelete
|
||||
|
||||
package filesystem
|
||||
package s3lite
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -82,7 +82,6 @@ import (
|
||||
"strings"
|
||||
|
||||
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
|
||||
awsv2cfg "github.com/aws/aws-sdk-go-v2/config"
|
||||
s3managerv2 "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
||||
s3v2 "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
typesv2 "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
@@ -244,116 +243,8 @@ func URLUnescape(s string) string {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// UseV2 returns true iff the URL parameters indicate that the provider
|
||||
// should use the AWS SDK v2.
|
||||
//
|
||||
// "awssdk=v1" will force V1.
|
||||
// "awssdk=v2" will force V2.
|
||||
// No "awssdk" parameter (or any other value) will return the default, currently V1.
|
||||
// Note that the default may change in the future.
|
||||
func UseV2(q url.Values) bool {
|
||||
if values, ok := q["awssdk"]; ok {
|
||||
if values[0] == "v2" || values[0] == "V2" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// NewDefaultV2Config returns a aws.Config for AWS SDK v2, using the default options.
|
||||
func NewDefaultV2Config(ctx context.Context) (awsv2.Config, error) {
|
||||
return awsv2cfg.LoadDefaultConfig(ctx)
|
||||
}
|
||||
|
||||
// V2ConfigFromURLParams returns an aws.Config for AWS SDK v2 initialized based on the URL
|
||||
// parameters in q. It is intended to be used by URLOpeners for AWS services if
|
||||
// UseV2 returns true.
|
||||
//
|
||||
// https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#Config
|
||||
//
|
||||
// It returns an error if q contains any unknown query parameters; callers
|
||||
// should remove any query parameters they know about from q before calling
|
||||
// V2ConfigFromURLParams.
|
||||
//
|
||||
// The following query options are supported:
|
||||
// - region: The AWS region for requests; sets WithRegion.
|
||||
// - profile: The shared config profile to use; sets SharedConfigProfile.
|
||||
// - endpoint: The AWS service endpoint to send HTTP request.
|
||||
func V2ConfigFromURLParams(ctx context.Context, q url.Values) (awsv2.Config, error) {
|
||||
var opts []func(*awsv2cfg.LoadOptions) error
|
||||
for param, values := range q {
|
||||
value := values[0]
|
||||
switch param {
|
||||
case "region":
|
||||
opts = append(opts, awsv2cfg.WithRegion(value))
|
||||
case "endpoint":
|
||||
customResolver := awsv2.EndpointResolverWithOptionsFunc(
|
||||
func(service, region string, options ...interface{}) (awsv2.Endpoint, error) {
|
||||
return awsv2.Endpoint{
|
||||
PartitionID: "aws",
|
||||
URL: value,
|
||||
SigningRegion: region,
|
||||
}, nil
|
||||
})
|
||||
opts = append(opts, awsv2cfg.WithEndpointResolverWithOptions(customResolver))
|
||||
case "profile":
|
||||
opts = append(opts, awsv2cfg.WithSharedConfigProfile(value))
|
||||
case "awssdk":
|
||||
// ignore, should be handled before this
|
||||
default:
|
||||
return awsv2.Config{}, fmt.Errorf("unknown query parameter %q", param)
|
||||
}
|
||||
}
|
||||
return awsv2cfg.LoadDefaultConfig(ctx, opts...)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const defaultPageSize = 1000
|
||||
|
||||
func init() {
|
||||
blob.DefaultURLMux().RegisterBucket(Scheme, new(urlSessionOpener))
|
||||
}
|
||||
|
||||
type urlSessionOpener struct{}
|
||||
|
||||
func (o *urlSessionOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket, error) {
|
||||
opener := &URLOpener{UseV2: true}
|
||||
return opener.OpenBucketURL(ctx, u)
|
||||
}
|
||||
|
||||
// Scheme is the URL scheme s3blob registers its URLOpener under on
|
||||
// blob.DefaultMux.
|
||||
const Scheme = "s3"
|
||||
|
||||
// URLOpener opens S3 URLs like "s3://mybucket".
|
||||
//
|
||||
// The URL host is used as the bucket name.
|
||||
//
|
||||
// Use "awssdk=v1" to force using AWS SDK v1, "awssdk=v2" to force using AWS SDK v2,
|
||||
// or anything else to accept the default.
|
||||
//
|
||||
// For V1, see gocloud.dev/aws/ConfigFromURLParams for supported query parameters
|
||||
// for overriding the aws.Session from the URL.
|
||||
// For V2, see gocloud.dev/aws/V2ConfigFromURLParams.
|
||||
type URLOpener struct {
|
||||
// UseV2 indicates whether the AWS SDK V2 should be used.
|
||||
UseV2 bool
|
||||
|
||||
// Options specifies the options to pass to OpenBucket.
|
||||
Options Options
|
||||
}
|
||||
|
||||
// OpenBucketURL opens a blob.Bucket based on u.
|
||||
func (o *URLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket, error) {
|
||||
cfg, err := V2ConfigFromURLParams(ctx, u.Query())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open bucket %v: %v", u, err)
|
||||
}
|
||||
clientV2 := s3v2.NewFromConfig(cfg)
|
||||
return OpenBucketV2(ctx, clientV2, u.Host, &o.Options)
|
||||
}
|
||||
|
||||
// Options sets options for constructing a *blob.Bucket backed by fileblob.
|
||||
type Options struct {
|
||||
// UseLegacyList forces the use of ListObjects instead of ListObjectsV2.
|
||||
@@ -676,64 +567,6 @@ func (b *bucket) listObjectsV2(ctx context.Context, in *s3v2.ListObjectsV2Input,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// func (b *bucket) listObjects(ctx context.Context, in *s3.ListObjectsV2Input, opts *driver.ListOptions) (*s3.ListObjectsV2Output, error) {
|
||||
// if !b.useLegacyList {
|
||||
// if opts.BeforeList != nil {
|
||||
// asFunc := func(i interface{}) bool {
|
||||
// if p, ok := i.(**s3.ListObjectsV2Input); ok {
|
||||
// *p = in
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
// if err := opts.BeforeList(asFunc); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
// return b.client.ListObjectsV2WithContext(ctx, in)
|
||||
// }
|
||||
|
||||
// // Use the legacy ListObjects request.
|
||||
// legacyIn := &s3.ListObjectsInput{
|
||||
// Bucket: in.Bucket,
|
||||
// Delimiter: in.Delimiter,
|
||||
// EncodingType: in.EncodingType,
|
||||
// Marker: in.ContinuationToken,
|
||||
// MaxKeys: in.MaxKeys,
|
||||
// Prefix: in.Prefix,
|
||||
// RequestPayer: in.RequestPayer,
|
||||
// }
|
||||
// if opts.BeforeList != nil {
|
||||
// asFunc := func(i interface{}) bool {
|
||||
// p, ok := i.(**s3.ListObjectsInput)
|
||||
// if !ok {
|
||||
// return false
|
||||
// }
|
||||
// *p = legacyIn
|
||||
// return true
|
||||
// }
|
||||
// if err := opts.BeforeList(asFunc); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
// legacyResp, err := b.client.ListObjectsWithContext(ctx, legacyIn)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// var nextContinuationToken *string
|
||||
// if legacyResp.NextMarker != nil {
|
||||
// nextContinuationToken = legacyResp.NextMarker
|
||||
// } else if awsv2.ToBool(legacyResp.IsTruncated) {
|
||||
// nextContinuationToken = awsv2.String(awsv2.ToString(legacyResp.Contents[len(legacyResp.Contents)-1].Key))
|
||||
// }
|
||||
// return &s3.ListObjectsV2Output{
|
||||
// CommonPrefixes: legacyResp.CommonPrefixes,
|
||||
// Contents: legacyResp.Contents,
|
||||
// NextContinuationToken: nextContinuationToken,
|
||||
// }, nil
|
||||
// }
|
||||
|
||||
// As implements driver.As.
|
||||
func (b *bucket) As(i interface{}) bool {
|
||||
p, ok := i.(**s3v2.Client)
|
||||
Reference in New Issue
Block a user