add precheck function
This commit is contained in:
parent
b3e9e55ff9
commit
1e477c1a23
@ -11,6 +11,7 @@ import (
|
||||
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||
"github.com/alcionai/corso/src/internal/common/idname"
|
||||
"github.com/alcionai/corso/src/internal/common/prefixmatcher"
|
||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||
"github.com/alcionai/corso/src/internal/data"
|
||||
"github.com/alcionai/corso/src/internal/diagnostics"
|
||||
"github.com/alcionai/corso/src/internal/events"
|
||||
@ -29,6 +30,7 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/logger"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
"github.com/alcionai/corso/src/pkg/store"
|
||||
)
|
||||
|
||||
@ -119,6 +121,44 @@ type backupStats struct {
|
||||
resourceCount int
|
||||
}
|
||||
|
||||
func Precheck(
|
||||
ctx context.Context,
|
||||
account account.Account,
|
||||
service path.ServiceType,
|
||||
userID string,
|
||||
) error {
|
||||
if service == path.SharePointService {
|
||||
// No "enabled" check required for sharepoint
|
||||
return nil
|
||||
}
|
||||
|
||||
cred, err := account.M365Config()
|
||||
if err != nil {
|
||||
return clues.Wrap(err, "getting creds")
|
||||
}
|
||||
|
||||
client, err := api.NewClient(cred)
|
||||
if err != nil {
|
||||
return clues.Wrap(err, "constructing api client")
|
||||
}
|
||||
|
||||
ui, err := client.Users().GetInfo(ctx, userID)
|
||||
if err != nil {
|
||||
return clues.Wrap(err, "unable to get user info")
|
||||
}
|
||||
|
||||
if ui == nil || len(ui.ServicesEnabled) == 0 {
|
||||
return graph.ErrServiceNotEnabled
|
||||
}
|
||||
|
||||
_, ok := ui.ServicesEnabled[service]
|
||||
if !ok {
|
||||
return graph.ErrServiceNotEnabled
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Primary Controller
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -151,6 +191,12 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
||||
sstore = streamstore.NewStreamer(op.kopia, op.account.ID(), op.Selectors.PathService())
|
||||
)
|
||||
|
||||
err = Precheck(ctx, op.account, op.Selectors.PathService(), op.Selectors.DiscreteOwner)
|
||||
if err != nil {
|
||||
logger.CtxErr(ctx, err).Error("running backup")
|
||||
op.Errors.Fail(clues.Wrap(err, "running backup"))
|
||||
}
|
||||
|
||||
op.Results.BackupID = model.StableID(uuid.NewString())
|
||||
|
||||
ctx = clues.Add(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user