fetch repoID from kopia is not found in config (#3578)
<!-- PR description--> Some events in have a empty repoID. This could be because of multiple config files used. And new config files might have repoID missing. Solution- Fetch repoID from Kopia is not found locally in the config file. Note: Since the Corso Start event happens before we connect to Kopia, it might have repoID missing if the config file is used for the first time. All the consecutive events will have correct values. Corso start event will start populating correct values if the config file is used once. #### Does this PR need a docs update or release note? - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🐛 Bugfix #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * https://github.com/alcionai/corso/issues/3388 #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual
This commit is contained in:
parent
d415be6844
commit
0a17a72800
@ -279,7 +279,7 @@ func genericDeleteCommand(cmd *cobra.Command, bID, designation string, args []st
|
||||
|
||||
ctx := clues.Add(cmd.Context(), "delete_backup_id", bID)
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
@ -300,7 +300,7 @@ func genericDeleteCommand(cmd *cobra.Command, bID, designation string, args []st
|
||||
func genericListCommand(cmd *cobra.Command, bID string, service path.ServiceType, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ func createExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, acct, err := utils.GetAccountAndConnect(ctx)
|
||||
r, acct, err := utils.AccountConnectAndWriteRepoConfig(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
@ -262,7 +262,7 @@ func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
opts := utils.MakeExchangeOpts(cmd)
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ func createOneDriveCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, acct, err := utils.GetAccountAndConnect(ctx)
|
||||
r, acct, err := utils.AccountConnectAndWriteRepoConfig(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
@ -220,7 +220,7 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
opts := utils.MakeOneDriveOpts(cmd)
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, acct, err := utils.GetAccountAndConnect(ctx)
|
||||
r, acct, err := utils.AccountConnectAndWriteRepoConfig(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
@ -312,7 +312,7 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
opts := utils.MakeSharePointOpts(cmd)
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ func handleMaintenanceCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return print.Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/alcionai/corso/src/cli/options"
|
||||
. "github.com/alcionai/corso/src/cli/print"
|
||||
"github.com/alcionai/corso/src/cli/utils"
|
||||
"github.com/alcionai/corso/src/internal/events"
|
||||
"github.com/alcionai/corso/src/pkg/account"
|
||||
"github.com/alcionai/corso/src/pkg/repository"
|
||||
"github.com/alcionai/corso/src/pkg/storage"
|
||||
@ -193,7 +194,7 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
repoID := cfg.RepoID
|
||||
if len(repoID) == 0 {
|
||||
repoID = "not_found"
|
||||
repoID = events.RepoIDNotFound
|
||||
}
|
||||
|
||||
s3Cfg, err := cfg.Storage.S3Config()
|
||||
|
||||
@ -89,7 +89,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
r, _, err := utils.GetAccountAndConnect(ctx)
|
||||
r, _, _, err := utils.GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
return Only(ctx, err)
|
||||
}
|
||||
|
||||
@ -24,23 +24,53 @@ const (
|
||||
Wildcard = "*"
|
||||
)
|
||||
|
||||
func GetAccountAndConnect(ctx context.Context) (repository.Repository, *account.Account, error) {
|
||||
func GetAccountAndConnect(ctx context.Context) (repository.Repository, *storage.Storage, *account.Account, error) {
|
||||
cfg, err := config.GetConfigRepoDetails(ctx, true, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
repoID := cfg.RepoID
|
||||
if len(repoID) == 0 {
|
||||
repoID = "not_found"
|
||||
repoID = events.RepoIDNotFound
|
||||
}
|
||||
|
||||
r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, repoID, options.Control())
|
||||
if err != nil {
|
||||
return nil, nil, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")
|
||||
return nil, nil, nil, clues.Wrap(err, "connecting to the "+cfg.Storage.Provider.String()+" repository")
|
||||
}
|
||||
|
||||
return r, &cfg.Account, nil
|
||||
return r, &cfg.Storage, &cfg.Account, nil
|
||||
}
|
||||
|
||||
func AccountConnectAndWriteRepoConfig(ctx context.Context) (repository.Repository, *account.Account, error) {
|
||||
r, stg, acc, err := GetAccountAndConnect(ctx)
|
||||
if err != nil {
|
||||
logger.CtxErr(ctx, err).Info("getting and connecting account")
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
s3Config, err := stg.S3Config()
|
||||
if err != nil {
|
||||
logger.CtxErr(ctx, err).Info("getting storage configuration")
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
m365Config, err := acc.M365Config()
|
||||
if err != nil {
|
||||
logger.CtxErr(ctx, err).Info("getting m365 configuration")
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// repo config is already set while repo connect and init. This is just to confirm correct values.
|
||||
// So won't fail is the write fails
|
||||
err = config.WriteRepoConfig(ctx, s3Config, m365Config, r.GetID())
|
||||
if err != nil {
|
||||
logger.CtxErr(ctx, err).Info("writing to repository configuration")
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return r, acc, nil
|
||||
}
|
||||
|
||||
// CloseRepo handles closing a repo.
|
||||
|
||||
@ -52,7 +52,9 @@ const (
|
||||
Service = "service"
|
||||
StartTime = "start_time"
|
||||
Status = "status"
|
||||
RepoID = "not_found"
|
||||
|
||||
// default values for keys
|
||||
RepoIDNotFound = "not_found"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -230,6 +230,15 @@ func Connect(
|
||||
return nil, clues.Wrap(err, "constructing event bus")
|
||||
}
|
||||
|
||||
if repoid == events.RepoIDNotFound {
|
||||
rm, err := getRepoModel(ctx, ms)
|
||||
if err != nil {
|
||||
return nil, clues.New("retrieving repo info")
|
||||
}
|
||||
|
||||
repoid = string(rm.ID)
|
||||
}
|
||||
|
||||
// Do not query repo ID if metrics are disabled
|
||||
if !opts.DisableMetrics {
|
||||
bus.SetRepoID(repoid)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user