Compare commits

...

8 Commits

5 changed files with 115 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import (
. "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/common/idname"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/pkg/backup"
"github.com/alcionai/corso/src/pkg/logger"
@ -225,6 +226,13 @@ func runBackups(
err = bo.Run(ictx)
if err != nil {
if errors.Is(err, graph.ErrServiceNotEnabled) {
logger.Ctx(ctx).Debugf("Service not enabled for creating backup for %s", bo.ResourceOwner.Name())
Infof(ictx, "%v\n", err)
continue
}
errs = append(errs, clues.Wrap(err, owner).WithClues(ictx))
Errf(ictx, "%v\n", err)

View File

@ -173,6 +173,39 @@ func runExchangeBackupCategoryTest(suite *BackupExchangeE2ESuite, category strin
assert.Contains(t, result, suite.m365UserID)
}
func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_ServiceNotEnabled_email() {
runExchangeBackupServiceNotEnabledTest(suite, "email")
}
func runExchangeBackupServiceNotEnabledTest(suite *BackupExchangeE2ESuite, category string) {
recorder := strings.Builder{}
recorder.Reset()
t := suite.T()
ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr)
defer flush()
// run the command
cmd, ctx := buildExchangeBackupCmd(
ctx,
suite.cfgFP,
fmt.Sprintf("%s,%s", tester.UnlicensedM365UserID(suite.T()), suite.m365UserID),
category,
&recorder)
err := cmd.ExecuteContext(ctx)
require.NoError(t, err, clues.ToCore(err))
result := recorder.String()
t.Log("backup results", result)
// as an offhand check: the result should contain the m365 user id
assert.Contains(t, result, suite.m365UserID)
}
func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_userNotFound_email() {
runExchangeBackupUserNotFoundTest(suite, "email")
}

View File

@ -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(

View File

@ -31,18 +31,20 @@ const (
TestCfgLoadTestUserID = "loadtestm365userid"
TestCfgLoadTestOrgUsers = "loadtestm365orgusers"
TestCfgAccountProvider = "account_provider"
TestCfgUnlicensedUserID = "unlicensedm365userid"
)
// test specific env vars
const (
EnvCorsoM365TestSiteID = "CORSO_M365_TEST_SITE_ID"
EnvCorsoM365TestSiteURL = "CORSO_M365_TEST_SITE_URL"
EnvCorsoM365TestUserID = "CORSO_M365_TEST_USER_ID"
EnvCorsoSecondaryM365TestUserID = "CORSO_SECONDARY_M365_TEST_USER_ID"
EnvCorsoTertiaryM365TestUserID = "CORSO_TERTIARY_M365_TEST_USER_ID"
EnvCorsoM365LoadTestUserID = "CORSO_M365_LOAD_TEST_USER_ID"
EnvCorsoM365LoadTestOrgUsers = "CORSO_M365_LOAD_TEST_ORG_USERS"
EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE"
EnvCorsoM365TestSiteID = "CORSO_M365_TEST_SITE_ID"
EnvCorsoM365TestSiteURL = "CORSO_M365_TEST_SITE_URL"
EnvCorsoM365TestUserID = "CORSO_M365_TEST_USER_ID"
EnvCorsoSecondaryM365TestUserID = "CORSO_SECONDARY_M365_TEST_USER_ID"
EnvCorsoTertiaryM365TestUserID = "CORSO_TERTIARY_M365_TEST_USER_ID"
EnvCorsoM365LoadTestUserID = "CORSO_M365_LOAD_TEST_USER_ID"
EnvCorsoM365LoadTestOrgUsers = "CORSO_M365_LOAD_TEST_ORG_USERS"
EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE"
EnvCorsoUnlicensedM365TestUserID = "CORSO_M365_TEST_UNLICENSED_USER"
)
// global to hold the test config results.
@ -152,6 +154,12 @@ func readTestConfig() (map[string]string, error) {
os.Getenv(EnvCorsoM365TestSiteURL),
vpr.GetString(TestCfgSiteURL),
"https://10rqc2.sharepoint.com/sites/CorsoCI")
fallbackTo(
testEnv,
TestCfgUnlicensedUserID,
os.Getenv(EnvCorsoUnlicensedM365TestUserID),
vpr.GetString(TestCfgUnlicensedUserID),
"testevents@10rqc2.onmicrosoft.com")
testEnv[EnvCorsoTestConfigFilePath] = os.Getenv(EnvCorsoTestConfigFilePath)
testConfig = testEnv

View File

@ -197,3 +197,15 @@ func GetM365SiteID(ctx context.Context) string {
return strings.ToLower(cfg[TestCfgSiteID])
}
// UnlicensedM365UserID returns an userID string representing the m365UserID
// described by either the env var CORSO_M365_TEST_UNLICENSED_USER, the
// corso_test.toml config file or the default value (in that order of priority).
// The default is a last-attempt fallback that will only work on alcion's
// testing org.
func UnlicensedM365UserID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving unlicensed m365 user id from test configuration", clues.ToCore(err))
return strings.ToLower(cfg[TestCfgSecondaryUserID])
}