Skip to content

Commit

Permalink
fix: Online Restore honors credentials passed in (#6295)
Browse files Browse the repository at this point in the history
  • Loading branch information
gja committed Aug 27, 2020
1 parent 6f883a4 commit a8a6e85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 2 additions & 3 deletions worker/backup_handler.go
Expand Up @@ -148,14 +148,13 @@ type loadFn func(reader io.Reader, groupId uint32, preds predicateSet) (uint64,

// LoadBackup will scan location l for backup files in the given backup series and load them
// sequentially. Returns the maximum Since value on success, otherwise an error.
func LoadBackup(location, backupId string, fn loadFn) LoadResult {
func LoadBackup(location, backupId string, creds *Credentials, fn loadFn) LoadResult {
uri, err := url.Parse(location)
if err != nil {
return LoadResult{0, 0, err}
}

// TODO(martinmr): allow overriding credentials during restore.
h := getHandler(uri.Scheme, nil)
h := getHandler(uri.Scheme, creds)
if h == nil {
return LoadResult{0, 0, errors.Errorf("Unsupported URI: %v", uri)}
}
Expand Down
11 changes: 10 additions & 1 deletion worker/online_restore_ee.go
Expand Up @@ -285,8 +285,17 @@ func getEncConfig(req *pb.RestoreRequest) (*viper.Viper, error) {
return config, nil
}

func getCredentialsFromRestoreRequest(req *pb.RestoreRequest) *Credentials {
return &Credentials{
AccessKey: req.AccessKey,
SecretKey: req.SecretKey,
SessionToken: req.SessionToken,
Anonymous: req.Anonymous,
}
}

func writeBackup(ctx context.Context, req *pb.RestoreRequest) error {
res := LoadBackup(req.Location, req.BackupId,
res := LoadBackup(req.Location, req.BackupId, getCredentialsFromRestoreRequest(req),
func(r io.Reader, groupId uint32, preds predicateSet) (uint64, error) {
if groupId != req.GroupId {
// LoadBackup will try to call the backup function for every group.
Expand Down
2 changes: 1 addition & 1 deletion worker/restore.go
Expand Up @@ -43,7 +43,7 @@ func RunRestore(pdir, location, backupId string, key x.SensitiveByteSlice) LoadR

// Scan location for backup files and load them. Each file represents a node group,
// and we create a new p dir for each.
return LoadBackup(location, backupId,
return LoadBackup(location, backupId, nil,
func(r io.Reader, groupId uint32, preds predicateSet) (uint64, error) {

dir := filepath.Join(pdir, fmt.Sprintf("p%d", groupId))
Expand Down

0 comments on commit a8a6e85

Please sign in to comment.