Gc restore multi framework (#639)
* Abstraction extended to restore. Application logic moved to service_functions.go
This commit is contained in:
parent
b524053e96
commit
6e7335cc4d
@ -258,6 +258,37 @@ func GetCopyRestoreFolder(service graph.Service, user string) (*string, error) {
|
||||
return isFolder, nil
|
||||
}
|
||||
|
||||
func RestoreExchangeObject(
|
||||
ctx context.Context,
|
||||
bits []byte,
|
||||
category string,
|
||||
policy control.CollisionPolicy,
|
||||
service graph.Service,
|
||||
destination, user string,
|
||||
) error {
|
||||
var setting optionIdentifier
|
||||
switch category {
|
||||
case mailCategory:
|
||||
setting = messages
|
||||
case contactsCategory:
|
||||
setting = contacts
|
||||
default:
|
||||
return fmt.Errorf("type: %s not supported for exchange restore", category)
|
||||
}
|
||||
|
||||
switch setting {
|
||||
case messages:
|
||||
switch policy {
|
||||
case control.Copy:
|
||||
return RestoreMailMessage(ctx, bits, service, control.Copy, destination, user)
|
||||
default:
|
||||
return fmt.Errorf("restore policy: %s not supported", policy)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("type: %s not supported for exchange restore", category)
|
||||
}
|
||||
}
|
||||
|
||||
// RestoreMailMessage utility function to place an exchange.Mail
|
||||
// message into the user's M365 Exchange account.
|
||||
// @param bits - byte array representation of exchange.Message from Corso backstore
|
||||
|
||||
@ -278,14 +278,11 @@ func (gc *GraphConnector) RestoreMessages(ctx context.Context, dcs []data.Collec
|
||||
errs = support.WrapAndAppend(itemData.UUID(), err, errs)
|
||||
continue
|
||||
}
|
||||
switch policy {
|
||||
case control.Copy:
|
||||
err = exchange.RestoreMailMessage(ctx, buf.Bytes(), &gc.graphService, control.Copy, *folderID, user)
|
||||
category := dc.FullPath()[2]
|
||||
err = exchange.RestoreExchangeObject(ctx, buf.Bytes(), category, policy, &gc.graphService, *folderID, user)
|
||||
|
||||
if err != nil {
|
||||
errs = support.WrapAndAppend(itemData.UUID(), err, errs)
|
||||
}
|
||||
default:
|
||||
errs = support.WrapAndAppend(itemData.UUID(), errors.New("restore policy not supported"), errs)
|
||||
continue
|
||||
}
|
||||
successes++
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user