Allow opening S3 repo at a specific point-in-time

Thread the PointInTime argument through corso to kopia so that S3 repos
can be opened at a specific point if they're using versioning and object
locking.
This commit is contained in:
Ashlie Martinez 2023-06-20 15:54:44 -07:00
parent 9f7a6422a0
commit a0ebe13565
3 changed files with 22 additions and 5 deletions

View File

@ -71,7 +71,7 @@ func NewConn(s storage.Storage) *conn {
}
func (w *conn) Initialize(ctx context.Context, opts repository.Options) error {
bst, err := blobStoreByProvider(ctx, w.storage)
bst, err := blobStoreByProvider(ctx, opts, w.storage)
if err != nil {
return clues.Wrap(err, "initializing storage")
}
@ -111,7 +111,7 @@ func (w *conn) Initialize(ctx context.Context, opts repository.Options) error {
}
func (w *conn) Connect(ctx context.Context, opts repository.Options) error {
bst, err := blobStoreByProvider(ctx, w.storage)
bst, err := blobStoreByProvider(ctx, opts, w.storage)
if err != nil {
return clues.Wrap(err, "initializing storage")
}
@ -174,10 +174,14 @@ func (w *conn) commonConnect(
return nil
}
func blobStoreByProvider(ctx context.Context, s storage.Storage) (blob.Storage, error) {
func blobStoreByProvider(
ctx context.Context,
opts repository.Options,
s storage.Storage,
) (blob.Storage, error) {
switch s.Provider {
case storage.ProviderS3:
return s3BlobStorage(ctx, s)
return s3BlobStorage(ctx, opts, s)
default:
return nil, clues.New("storage provider details are required").WithClues(ctx)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/blob/s3"
"github.com/alcionai/corso/src/pkg/control/repository"
"github.com/alcionai/corso/src/pkg/storage"
)
@ -14,7 +15,11 @@ const (
defaultS3Endpoint = "s3.amazonaws.com" // matches kopia's default value
)
func s3BlobStorage(ctx context.Context, s storage.Storage) (blob.Storage, error) {
func s3BlobStorage(
ctx context.Context,
repoOpts repository.Options,
s storage.Storage,
) (blob.Storage, error) {
cfg, err := s.S3Config()
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
@ -36,6 +41,7 @@ func s3BlobStorage(ctx context.Context, s storage.Storage) (blob.Storage, error)
RoleARN: s.Role,
RoleDuration: s.SessionDuration,
TLSHandshakeTimeout: 60,
PointInTime: repoOpts.ViewTimestamp,
}
store, err := s3.New(ctx, &opts, false)

View File

@ -1,9 +1,16 @@
package repository
import (
"time"
)
// Repo represents options that are specific to the repo storing backed up data.
type Options struct {
User string `json:"user"`
Host string `json:"host"`
// ViewTimestamp is the time at which the repo should be opened at if
// immutable backups are being used. If nil then the current time is used.
ViewTimestamp *time.Time `json:"viewTimestamp"`
}
type Maintenance struct {