quick cleanup before next step (#4347)

adds a container-of-things to reduce mostly-unused return value bloat, and updates some func names to be more appropriate to their behavior.

No logical changes, just renaming/movement.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🧹 Tech Debt/Cleanup
This commit is contained in:
Keepers 2023-09-27 11:17:31 -06:00 committed by GitHub
parent 38ef3b6ef6
commit 3c96eb6437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 62 deletions

View File

@ -265,10 +265,7 @@ func genericDeleteCommand(
ctx := clues.Add(cmd.Context(), "delete_backup_id", bID) ctx := clues.Add(cmd.Context(), "delete_backup_id", bID)
r, _, _, _, err := utils.GetAccountAndConnectWithOverrides( r, _, err := utils.GetAccountAndConnect(ctx, cmd, pst)
ctx,
cmd,
pst)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -298,10 +295,7 @@ func genericListCommand(
return nil return nil
} }
r, _, _, _, err := utils.GetAccountAndConnectWithOverrides( r, _, err := utils.GetAccountAndConnect(ctx, cmd, service)
ctx,
cmd,
service)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -275,17 +275,19 @@ func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.MakeExchangeOpts(cmd) opts := utils.MakeExchangeOpts(cmd)
r, _, _, ctrlOpts, err := utils.GetAccountAndConnectWithOverrides( r, rdao, err := utils.GetAccountAndConnect(ctx, cmd, path.ExchangeService)
ctx,
cmd,
path.ExchangeService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
defer utils.CloseRepo(ctx, r) defer utils.CloseRepo(ctx, r)
ds, err := runDetailsExchangeCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce) ds, err := runDetailsExchangeCmd(
ctx,
r,
flags.BackupIDFV,
opts,
rdao.Opts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -228,17 +228,19 @@ func detailsGroupsCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.MakeGroupsOpts(cmd) opts := utils.MakeGroupsOpts(cmd)
r, _, _, ctrlOpts, err := utils.GetAccountAndConnectWithOverrides( r, rdao, err := utils.GetAccountAndConnect(ctx, cmd, path.GroupsService)
ctx,
cmd,
path.GroupsService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
defer utils.CloseRepo(ctx, r) defer utils.CloseRepo(ctx, r)
ds, err := runDetailsGroupsCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce) ds, err := runDetailsGroupsCmd(
ctx,
r,
flags.BackupIDFV,
opts,
rdao.Opts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -232,17 +232,19 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.MakeOneDriveOpts(cmd) opts := utils.MakeOneDriveOpts(cmd)
r, _, _, ctrlOpts, err := utils.GetAccountAndConnectWithOverrides( r, rdao, err := utils.GetAccountAndConnect(ctx, cmd, path.OneDriveService)
ctx,
cmd,
path.OneDriveService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
defer utils.CloseRepo(ctx, r) defer utils.CloseRepo(ctx, r)
ds, err := runDetailsOneDriveCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce) ds, err := runDetailsOneDriveCmd(
ctx,
r,
flags.BackupIDFV,
opts,
rdao.Opts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -327,17 +327,19 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
opts := utils.MakeSharePointOpts(cmd) opts := utils.MakeSharePointOpts(cmd)
r, _, _, ctrlOpts, err := utils.GetAccountAndConnectWithOverrides( r, rdao, err := utils.GetAccountAndConnect(ctx, cmd, path.SharePointService)
ctx,
cmd,
path.SharePointService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
defer utils.CloseRepo(ctx, r) defer utils.CloseRepo(ctx, r)
ds, err := runDetailsSharePointCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce) ds, err := runDetailsSharePointCmd(
ctx,
r,
flags.BackupIDFV,
opts,
rdao.Opts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -67,10 +67,7 @@ func runExport(
return Only(ctx, err) return Only(ctx, err)
} }
r, _, _, _, err := utils.GetAccountAndConnectWithOverrides( r, _, err := utils.GetAccountAndConnect(ctx, cmd, sel.PathService())
ctx,
cmd,
sel.PathService())
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -100,10 +100,7 @@ func runRestore(
return Only(ctx, err) return Only(ctx, err)
} }
r, _, _, _, err := utils.GetAccountAndConnectWithOverrides( r, _, err := utils.GetAccountAndConnect(ctx, cmd, sel.PathService())
ctx,
cmd,
sel.PathService())
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -22,30 +22,35 @@ import (
"github.com/alcionai/corso/src/pkg/storage" "github.com/alcionai/corso/src/pkg/storage"
) )
type RepoDetailsAndOpts struct {
Repo config.RepoDetails
Opts control.Options
}
var ErrNotYetImplemented = clues.New("not yet implemented") var ErrNotYetImplemented = clues.New("not yet implemented")
// GetAccountAndConnectWithOverrides is a wrapper for GetAccountAndConnect // GetAccountAndConnect is a wrapper for GetAccountAndConnectWithOverrides
// that also gets the storage provider and any storage provider specific // that automatically gets the storage provider and any storage provider specific
// flag overrides from the command line. // flag overrides from the command line.
func GetAccountAndConnectWithOverrides( func GetAccountAndConnect(
ctx context.Context, ctx context.Context,
cmd *cobra.Command, cmd *cobra.Command,
pst path.ServiceType, pst path.ServiceType,
) (repository.Repositoryer, *storage.Storage, *account.Account, *control.Options, error) { ) (repository.Repositoryer, RepoDetailsAndOpts, error) {
provider, overrides, err := GetStorageProviderAndOverrides(ctx, cmd) provider, overrides, err := GetStorageProviderAndOverrides(ctx, cmd)
if err != nil { if err != nil {
return nil, nil, nil, nil, clues.Stack(err) return nil, RepoDetailsAndOpts{}, clues.Stack(err)
} }
return GetAccountAndConnect(ctx, pst, provider, overrides) return GetAccountAndConnectWithOverrides(ctx, pst, provider, overrides)
} }
func GetAccountAndConnect( func GetAccountAndConnectWithOverrides(
ctx context.Context, ctx context.Context,
pst path.ServiceType, pst path.ServiceType,
provider storage.ProviderType, provider storage.ProviderType,
overrides map[string]string, overrides map[string]string,
) (repository.Repositoryer, *storage.Storage, *account.Account, *control.Options, error) { ) (repository.Repositoryer, RepoDetailsAndOpts, error) {
cfg, err := config.GetConfigRepoDetails( cfg, err := config.GetConfigRepoDetails(
ctx, ctx,
provider, provider,
@ -53,7 +58,7 @@ func GetAccountAndConnect(
true, true,
overrides) overrides)
if err != nil { if err != nil {
return nil, nil, nil, nil, err return nil, RepoDetailsAndOpts{}, err
} }
repoID := cfg.RepoID repoID := cfg.RepoID
@ -70,20 +75,25 @@ func GetAccountAndConnect(
opts, opts,
repoID) repoID)
if err != nil { if err != nil {
return nil, nil, nil, nil, clues.Wrap(err, "creating a repository controller") return nil, RepoDetailsAndOpts{}, clues.Wrap(err, "creating a repository controller")
} }
if err := r.Connect(ctx); err != nil { if err := r.Connect(ctx); err != nil {
return nil, nil, nil, nil, clues.Wrap(err, "connecting to the "+cfg.Storage.Provider.String()+" repository") return nil, RepoDetailsAndOpts{}, clues.Wrap(err, "connecting to the "+cfg.Storage.Provider.String()+" repository")
} }
// this initializes our graph api client configurations, // this initializes our graph api client configurations,
// including control options such as concurency limitations. // including control options such as concurency limitations.
if _, err := r.ConnectToM365(ctx, pst); err != nil { if _, err := r.ConnectToM365(ctx, pst); err != nil {
return nil, nil, nil, nil, clues.Wrap(err, "connecting to m365") return nil, RepoDetailsAndOpts{}, clues.Wrap(err, "connecting to m365")
} }
return r, &cfg.Storage, &cfg.Account, &opts, nil rdao := RepoDetailsAndOpts{
Repo: cfg,
Opts: opts,
}
return r, rdao, nil
} }
func AccountConnectAndWriteRepoConfig( func AccountConnectAndWriteRepoConfig(
@ -91,22 +101,19 @@ func AccountConnectAndWriteRepoConfig(
cmd *cobra.Command, cmd *cobra.Command,
pst path.ServiceType, pst path.ServiceType,
) (repository.Repositoryer, *account.Account, error) { ) (repository.Repositoryer, *account.Account, error) {
r, stg, acc, opts, err := GetAccountAndConnectWithOverrides( r, rdao, err := GetAccountAndConnect(ctx, cmd, pst)
ctx,
cmd,
pst)
if err != nil { if err != nil {
logger.CtxErr(ctx, err).Info("getting and connecting account") logger.CtxErr(ctx, err).Info("getting and connecting account")
return nil, nil, err return nil, nil, err
} }
sc, err := stg.StorageConfig() sc, err := rdao.Repo.Storage.StorageConfig()
if err != nil { if err != nil {
logger.CtxErr(ctx, err).Info("getting storage configuration") logger.CtxErr(ctx, err).Info("getting storage configuration")
return nil, nil, err return nil, nil, err
} }
m365Config, err := acc.M365Config() m365Config, err := rdao.Repo.Account.M365Config()
if err != nil { if err != nil {
logger.CtxErr(ctx, err).Info("getting m365 configuration") logger.CtxErr(ctx, err).Info("getting m365 configuration")
return nil, nil, err return nil, nil, err
@ -114,13 +121,13 @@ func AccountConnectAndWriteRepoConfig(
// repo config gets set during repo connect and init. // repo config gets set during repo connect and init.
// This call confirms we have the correct values. // This call confirms we have the correct values.
err = config.WriteRepoConfig(ctx, sc, m365Config, opts.Repo, r.GetID()) err = config.WriteRepoConfig(ctx, sc, m365Config, rdao.Opts.Repo, r.GetID())
if err != nil { if err != nil {
logger.CtxErr(ctx, err).Info("writing to repository configuration") logger.CtxErr(ctx, err).Info("writing to repository configuration")
return nil, nil, err return nil, nil, err
} }
return r, acc, nil return r, &rdao.Repo.Account, nil
} }
// CloseRepo handles closing a repo. // CloseRepo handles closing a repo.

View File

@ -31,11 +31,7 @@ func deleteBackups(
) ([]string, error) { ) ([]string, error) {
ctx = clues.Add(ctx, "cutoff_days", deletionDays) ctx = clues.Add(ctx, "cutoff_days", deletionDays)
r, _, _, _, err := utils.GetAccountAndConnect( r, _, err := utils.GetAccountAndConnectWithOverrides(ctx, service, storage.ProviderS3, nil)
ctx,
service,
storage.ProviderS3,
nil)
if err != nil { if err != nil {
return nil, clues.Wrap(err, "connecting to account").WithClues(ctx) return nil, clues.Wrap(err, "connecting to account").WithClues(ctx)
} }