Persist repo owner info in config (#3840)
If repo owner info is set then persist those values in the config file. This is expected to apply only to maintenance commands right now --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) * #3569 #### Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
91e6108060
commit
22f990a709
@ -276,7 +276,7 @@ func genericDeleteCommand(
|
|||||||
|
|
||||||
ctx := clues.Add(cmd.Context(), "delete_backup_id", bID)
|
ctx := clues.Add(cmd.Context(), "delete_backup_id", bID)
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, pst, repo.S3Overrides(cmd))
|
r, _, _, _, err := utils.GetAccountAndConnect(ctx, pst, repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ func genericListCommand(
|
|||||||
) error {
|
) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, service, repo.S3Overrides(cmd))
|
r, _, _, _, err := utils.GetAccountAndConnect(ctx, service, repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -275,15 +275,13 @@ func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
|
|||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
opts := utils.MakeExchangeOpts(cmd)
|
opts := utils.MakeExchangeOpts(cmd)
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, path.ExchangeService, repo.S3Overrides(cmd))
|
r, _, _, ctrlOpts, err := utils.GetAccountAndConnect(ctx, path.ExchangeService, repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer utils.CloseRepo(ctx, r)
|
defer utils.CloseRepo(ctx, r)
|
||||||
|
|
||||||
ctrlOpts := utils.Control()
|
|
||||||
|
|
||||||
ds, err := runDetailsExchangeCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
ds, err := runDetailsExchangeCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
|
|||||||
@ -234,15 +234,13 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
opts := utils.MakeOneDriveOpts(cmd)
|
opts := utils.MakeOneDriveOpts(cmd)
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, path.OneDriveService, repo.S3Overrides(cmd))
|
r, _, _, ctrlOpts, err := utils.GetAccountAndConnect(ctx, path.OneDriveService, repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer utils.CloseRepo(ctx, r)
|
defer utils.CloseRepo(ctx, r)
|
||||||
|
|
||||||
ctrlOpts := utils.Control()
|
|
||||||
|
|
||||||
ds, err := runDetailsOneDriveCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
ds, err := runDetailsOneDriveCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
|
|||||||
@ -325,15 +325,13 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
|
|||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
opts := utils.MakeSharePointOpts(cmd)
|
opts := utils.MakeSharePointOpts(cmd)
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, path.SharePointService, repo.S3Overrides(cmd))
|
r, _, _, ctrlOpts, err := utils.GetAccountAndConnect(ctx, path.SharePointService, repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer utils.CloseRepo(ctx, r)
|
defer utils.CloseRepo(ctx, r)
|
||||||
|
|
||||||
ctrlOpts := utils.Control()
|
|
||||||
|
|
||||||
ds, err := runDetailsSharePointCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
ds, err := runDetailsSharePointCmd(ctx, r, flags.BackupIDFV, opts, ctrlOpts.SkipReduce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
. "github.com/alcionai/corso/src/cli/print"
|
. "github.com/alcionai/corso/src/cli/print"
|
||||||
"github.com/alcionai/corso/src/internal/common/str"
|
"github.com/alcionai/corso/src/internal/common/str"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/storage"
|
"github.com/alcionai/corso/src/pkg/storage"
|
||||||
)
|
)
|
||||||
@ -204,9 +205,15 @@ func WriteRepoConfig(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
s3Config storage.S3Config,
|
s3Config storage.S3Config,
|
||||||
m365Config account.M365Config,
|
m365Config account.M365Config,
|
||||||
|
repoOpts repository.Options,
|
||||||
repoID string,
|
repoID string,
|
||||||
) error {
|
) error {
|
||||||
return writeRepoConfigWithViper(GetViper(ctx), s3Config, m365Config, repoID)
|
return writeRepoConfigWithViper(
|
||||||
|
GetViper(ctx),
|
||||||
|
s3Config,
|
||||||
|
m365Config,
|
||||||
|
repoOpts,
|
||||||
|
repoID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeRepoConfigWithViper implements WriteRepoConfig, but takes in a viper
|
// writeRepoConfigWithViper implements WriteRepoConfig, but takes in a viper
|
||||||
@ -215,6 +222,7 @@ func writeRepoConfigWithViper(
|
|||||||
vpr *viper.Viper,
|
vpr *viper.Viper,
|
||||||
s3Config storage.S3Config,
|
s3Config storage.S3Config,
|
||||||
m365Config account.M365Config,
|
m365Config account.M365Config,
|
||||||
|
repoOpts repository.Options,
|
||||||
repoID string,
|
repoID string,
|
||||||
) error {
|
) error {
|
||||||
s3Config = s3Config.Normalize()
|
s3Config = s3Config.Normalize()
|
||||||
@ -228,6 +236,15 @@ func writeRepoConfigWithViper(
|
|||||||
vpr.Set(DisableTLSVerificationKey, s3Config.DoNotVerifyTLS)
|
vpr.Set(DisableTLSVerificationKey, s3Config.DoNotVerifyTLS)
|
||||||
vpr.Set(RepoID, repoID)
|
vpr.Set(RepoID, repoID)
|
||||||
|
|
||||||
|
// Need if-checks as Viper will write empty values otherwise.
|
||||||
|
if len(repoOpts.User) > 0 {
|
||||||
|
vpr.Set(CorsoUser, repoOpts.User)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(repoOpts.Host) > 0 {
|
||||||
|
vpr.Set(CorsoHost, repoOpts.Host)
|
||||||
|
}
|
||||||
|
|
||||||
vpr.Set(AccountProviderTypeKey, account.ProviderM365.String())
|
vpr.Set(AccountProviderTypeKey, account.ProviderM365.String())
|
||||||
vpr.Set(AzureTenantIDKey, m365Config.AzureTenantID)
|
vpr.Set(AzureTenantIDKey, m365Config.AzureTenantID)
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/internal/tester/tconfig"
|
"github.com/alcionai/corso/src/internal/tester/tconfig"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/credentials"
|
"github.com/alcionai/corso/src/pkg/credentials"
|
||||||
"github.com/alcionai/corso/src/pkg/storage"
|
"github.com/alcionai/corso/src/pkg/storage"
|
||||||
storeTD "github.com/alcionai/corso/src/pkg/storage/testdata"
|
storeTD "github.com/alcionai/corso/src/pkg/storage/testdata"
|
||||||
@ -135,8 +136,11 @@ func (suite *ConfigSuite) TestWriteReadConfig() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
bkt = "write-read-config-bucket"
|
bkt = "write-read-config-bucket"
|
||||||
tid = "3c0748d2-470e-444c-9064-1268e52609d5"
|
tid = "3c0748d2-470e-444c-9064-1268e52609d5"
|
||||||
|
repoID = "repoid"
|
||||||
|
user = "a-user"
|
||||||
|
host = "some-host"
|
||||||
)
|
)
|
||||||
|
|
||||||
err := initWithViper(vpr, testConfigFilePath)
|
err := initWithViper(vpr, testConfigFilePath)
|
||||||
@ -145,7 +149,12 @@ func (suite *ConfigSuite) TestWriteReadConfig() {
|
|||||||
s3Cfg := storage.S3Config{Bucket: bkt, DoNotUseTLS: true, DoNotVerifyTLS: true}
|
s3Cfg := storage.S3Config{Bucket: bkt, DoNotUseTLS: true, DoNotVerifyTLS: true}
|
||||||
m365 := account.M365Config{AzureTenantID: tid}
|
m365 := account.M365Config{AzureTenantID: tid}
|
||||||
|
|
||||||
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, "repoid")
|
rOpts := repository.Options{
|
||||||
|
User: user,
|
||||||
|
Host: host,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, rOpts, repoID)
|
||||||
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
|
|
||||||
err = vpr.ReadInConfig()
|
err = vpr.ReadInConfig()
|
||||||
@ -160,6 +169,10 @@ func (suite *ConfigSuite) TestWriteReadConfig() {
|
|||||||
readM365, err := m365ConfigsFromViper(vpr)
|
readM365, err := m365ConfigsFromViper(vpr)
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
assert.Equal(t, readM365.AzureTenantID, m365.AzureTenantID)
|
||||||
|
|
||||||
|
gotUser, gotHost := getUserHost(vpr, true)
|
||||||
|
assert.Equal(t, user, gotUser)
|
||||||
|
assert.Equal(t, host, gotHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfigSuite) TestMustMatchConfig() {
|
func (suite *ConfigSuite) TestMustMatchConfig() {
|
||||||
@ -181,7 +194,7 @@ func (suite *ConfigSuite) TestMustMatchConfig() {
|
|||||||
s3Cfg := storage.S3Config{Bucket: bkt}
|
s3Cfg := storage.S3Config{Bucket: bkt}
|
||||||
m365 := account.M365Config{AzureTenantID: tid}
|
m365 := account.M365Config{AzureTenantID: tid}
|
||||||
|
|
||||||
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, "repoid")
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
||||||
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
|
|
||||||
err = vpr.ReadInConfig()
|
err = vpr.ReadInConfig()
|
||||||
@ -383,7 +396,7 @@ func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount() {
|
|||||||
}
|
}
|
||||||
m365 := account.M365Config{AzureTenantID: tid}
|
m365 := account.M365Config{AzureTenantID: tid}
|
||||||
|
|
||||||
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, "repoid")
|
err = writeRepoConfigWithViper(vpr, s3Cfg, m365, repository.Options{}, "repoid")
|
||||||
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
require.NoError(t, err, "writing repo config", clues.ToCore(err))
|
||||||
|
|
||||||
err = vpr.ReadInConfig()
|
err = vpr.ReadInConfig()
|
||||||
|
|||||||
@ -121,7 +121,7 @@ func handleMaintenanceCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, path.UnknownService, S3Overrides(cmd))
|
r, _, err := utils.AccountConnectAndWriteRepoConfig(ctx, path.UnknownService, S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return print.Only(ctx, err)
|
return print.Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -171,7 +171,7 @@ func initS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
Infof(ctx, "Initialized a S3 repository within bucket %s.", s3Cfg.Bucket)
|
Infof(ctx, "Initialized a S3 repository within bucket %s.", s3Cfg.Bucket)
|
||||||
|
|
||||||
if err = config.WriteRepoConfig(ctx, s3Cfg, m365, r.GetID()); err != nil {
|
if err = config.WriteRepoConfig(ctx, s3Cfg, m365, opt.Repo, r.GetID()); err != nil {
|
||||||
return Only(ctx, clues.Wrap(err, "Failed to write repository configuration"))
|
return Only(ctx, clues.Wrap(err, "Failed to write repository configuration"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,12 +228,14 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, clues.New(invalidEndpointErr))
|
return Only(ctx, clues.New(invalidEndpointErr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts := utils.ControlWithConfig(cfg)
|
||||||
|
|
||||||
r, err := repository.ConnectAndSendConnectEvent(
|
r, err := repository.ConnectAndSendConnectEvent(
|
||||||
ctx,
|
ctx,
|
||||||
cfg.Account,
|
cfg.Account,
|
||||||
cfg.Storage,
|
cfg.Storage,
|
||||||
repoID,
|
repoID,
|
||||||
utils.ControlWithConfig(cfg))
|
opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, clues.Wrap(err, "Failed to connect to the S3 repository"))
|
return Only(ctx, clues.Wrap(err, "Failed to connect to the S3 repository"))
|
||||||
}
|
}
|
||||||
@ -242,7 +244,7 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
Infof(ctx, "Connected to S3 bucket %s.", s3Cfg.Bucket)
|
Infof(ctx, "Connected to S3 bucket %s.", s3Cfg.Bucket)
|
||||||
|
|
||||||
if err = config.WriteRepoConfig(ctx, s3Cfg, m365, r.GetID()); err != nil {
|
if err = config.WriteRepoConfig(ctx, s3Cfg, m365, opts.Repo, r.GetID()); err != nil {
|
||||||
return Only(ctx, clues.Wrap(err, "Failed to write repository configuration"))
|
return Only(ctx, clues.Wrap(err, "Failed to write repository configuration"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,7 @@ func runRestore(
|
|||||||
sel selectors.Selector,
|
sel selectors.Selector,
|
||||||
backupID, serviceName string,
|
backupID, serviceName string,
|
||||||
) error {
|
) error {
|
||||||
r, _, _, err := utils.GetAccountAndConnect(ctx, sel.PathService(), repo.S3Overrides(cmd))
|
r, _, _, _, err := utils.GetAccountAndConnect(ctx, sel.PathService(), repo.S3Overrides(cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,10 @@ func GetAccountAndConnect(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
pst path.ServiceType,
|
pst path.ServiceType,
|
||||||
overrides map[string]string,
|
overrides map[string]string,
|
||||||
) (repository.Repository, *storage.Storage, *account.Account, error) {
|
) (repository.Repository, *storage.Storage, *account.Account, *control.Options, error) {
|
||||||
cfg, err := config.GetConfigRepoDetails(ctx, true, true, overrides)
|
cfg, err := config.GetConfigRepoDetails(ctx, true, true, overrides)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repoID := cfg.RepoID
|
repoID := cfg.RepoID
|
||||||
@ -34,18 +34,20 @@ func GetAccountAndConnect(
|
|||||||
repoID = events.RepoIDNotFound
|
repoID = events.RepoIDNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, repoID, ControlWithConfig(cfg))
|
opts := ControlWithConfig(cfg)
|
||||||
|
|
||||||
|
r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, repoID, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, clues.Wrap(err, "connecting to the "+cfg.Storage.Provider.String()+" repository")
|
return nil, nil, nil, nil, 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, clues.Wrap(err, "connecting to m365")
|
return nil, nil, nil, nil, clues.Wrap(err, "connecting to m365")
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, &cfg.Storage, &cfg.Account, nil
|
return r, &cfg.Storage, &cfg.Account, &opts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountConnectAndWriteRepoConfig(
|
func AccountConnectAndWriteRepoConfig(
|
||||||
@ -53,7 +55,7 @@ func AccountConnectAndWriteRepoConfig(
|
|||||||
pst path.ServiceType,
|
pst path.ServiceType,
|
||||||
overrides map[string]string,
|
overrides map[string]string,
|
||||||
) (repository.Repository, *account.Account, error) {
|
) (repository.Repository, *account.Account, error) {
|
||||||
r, stg, acc, err := GetAccountAndConnect(ctx, pst, overrides)
|
r, stg, acc, opts, err := GetAccountAndConnect(ctx, pst, overrides)
|
||||||
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
|
||||||
@ -73,7 +75,7 @@ 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, s3Config, m365Config, r.GetID())
|
err = config.WriteRepoConfig(ctx, s3Config, m365Config, 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
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func main() {
|
|||||||
fatal(cc.Context(), "unknown service", nil)
|
fatal(cc.Context(), "unknown service", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, _, _, err := utils.GetAccountAndConnect(cc.Context(), service, nil)
|
r, _, _, _, err := utils.GetAccountAndConnect(cc.Context(), service, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(cc.Context(), "unable to connect account", err)
|
fatal(cc.Context(), "unable to connect account", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user