* validate required storage props (#85) Centralizes validation of required storage config properties within the storage package. Requiremens are checked eagerly at configuration creation, and lazily at config retrieval. Additionally, updates /pkg/storage tests to use suites and assert funcs. * add validation failure tests to storage
35 lines
724 B
Go
35 lines
724 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, s storage.Storage) (blob.Storage, error) {
|
|
cfg, err := s.S3Config()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
endpoint := defaultS3Endpoint
|
|
if len(cfg.Endpoint) > 0 {
|
|
endpoint = cfg.Endpoint
|
|
}
|
|
opts := s3.Options{
|
|
AccessKeyID: cfg.AccessKey,
|
|
BucketName: cfg.Bucket,
|
|
Endpoint: endpoint,
|
|
Prefix: cfg.Prefix,
|
|
SecretAccessKey: cfg.SecretKey,
|
|
SessionToken: cfg.SessionToken,
|
|
}
|
|
return s3.New(ctx, &opts)
|
|
}
|