-
Notifications
You must be signed in to change notification settings - Fork 124
/
util.go
43 lines (39 loc) · 1.16 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package taskoutput
import (
"context"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/pail"
"github.com/evergreen-ci/utility"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/mongo"
)
func newBucket(ctx context.Context, config evergreen.BucketConfig, creds *credentials.Credentials) (pail.Bucket, error) {
switch config.Type {
case evergreen.BucketTypeS3:
return pail.NewS3Bucket(pail.S3Options{
Name: config.Name,
Credentials: creds,
Region: evergreen.DefaultEC2Region,
Permissions: pail.S3PermissionsPrivate,
MaxRetries: utility.ToIntPtr(10),
Compress: true,
})
case evergreen.BucketTypeGridFS:
client, err := mongo.Connect(ctx)
if err != nil {
return nil, errors.Wrap(err, "connecting to the GridFS DB")
}
return pail.NewGridFSBucketWithClient(ctx, client, pail.GridFSOptions{
Name: config.Name,
Database: config.DBName,
})
case evergreen.BucketTypeLocal:
return pail.NewLocalBucket(pail.LocalOptions{
Path: config.Name,
UseSlash: true,
})
default:
return nil, errors.Errorf("unrecognized bucket type '%s'", config.Type)
}
}