Exposes the s3 endpoint option as a cli flag and storage config property. Uses the kopia default s3.amazonaws.com as a fallback.
30 lines
632 B
Go
30 lines
632 B
Go
package kopia
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/kopia/kopia/repo/blob"
|
|
"github.com/kopia/kopia/repo/blob/s3"
|
|
|
|
"github.com/alcionai/corso/pkg/storage"
|
|
)
|
|
|
|
const (
|
|
defaultS3Endpoint = "s3.amazonaws.com" // matches kopia's default value
|
|
)
|
|
|
|
func s3BlobStorage(ctx context.Context, cfg storage.S3Config) (blob.Storage, error) {
|
|
endpoint := defaultS3Endpoint
|
|
if len(cfg.Endpoint) > 0 {
|
|
endpoint = cfg.Endpoint
|
|
}
|
|
opts := s3.Options{
|
|
AccessKeyID: cfg.AccessKey,
|
|
BucketName: cfg.Bucket,
|
|
Endpoint: endpoint,
|
|
SecretAccessKey: cfg.SecretKey,
|
|
SessionToken: cfg.SessionToken,
|
|
}
|
|
return s3.New(ctx, &opts)
|
|
}
|