get repoID from config for events (#3449)
<!-- PR description--> - Get repoID from config for events for uniformity across repo - Set a default value if repoID is nil/blank #### Does this PR need a docs update or release note? - [x] ⛔ 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 - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
d1a4c68fea
commit
8bb9df8e75
@ -191,6 +191,11 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, err)
|
return Only(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repoID := cfg.RepoID
|
||||||
|
if len(repoID) == 0 {
|
||||||
|
repoID = "not_found"
|
||||||
|
}
|
||||||
|
|
||||||
s3Cfg, err := cfg.Storage.S3Config()
|
s3Cfg, err := cfg.Storage.S3Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Only(ctx, clues.Wrap(err, "Retrieving s3 configuration"))
|
return Only(ctx, clues.Wrap(err, "Retrieving s3 configuration"))
|
||||||
@ -208,7 +213,7 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
return Only(ctx, clues.New(invalidEndpointErr))
|
return Only(ctx, clues.New(invalidEndpointErr))
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := repository.ConnectAndSendConnectEvent(ctx, cfg.Account, cfg.Storage, options.Control())
|
r, err := repository.ConnectAndSendConnectEvent(ctx, cfg.Account, cfg.Storage, repoID, options.Control())
|
||||||
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"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,12 @@ func GetAccountAndConnect(ctx context.Context) (repository.Repository, *account.
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, options.Control())
|
repoID := cfg.RepoID
|
||||||
|
if len(repoID) == 0 {
|
||||||
|
repoID = "not_found"
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, repoID, options.Control())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")
|
return nil, nil, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ const (
|
|||||||
Service = "service"
|
Service = "service"
|
||||||
StartTime = "start_time"
|
StartTime = "start_time"
|
||||||
Status = "status"
|
Status = "status"
|
||||||
|
RepoID = "not_found"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -184,6 +184,7 @@ func Connect(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
acct account.Account,
|
acct account.Account,
|
||||||
s storage.Storage,
|
s storage.Storage,
|
||||||
|
repoid string,
|
||||||
opts control.Options,
|
opts control.Options,
|
||||||
) (r Repository, err error) {
|
) (r Repository, err error) {
|
||||||
ctx = clues.Add(
|
ctx = clues.Add(
|
||||||
@ -229,23 +230,16 @@ func Connect(
|
|||||||
return nil, clues.Wrap(err, "constructing event bus")
|
return nil, clues.Wrap(err, "constructing event bus")
|
||||||
}
|
}
|
||||||
|
|
||||||
rm := &repositoryModel{}
|
|
||||||
|
|
||||||
// Do not query repo ID if metrics are disabled
|
// Do not query repo ID if metrics are disabled
|
||||||
if !opts.DisableMetrics {
|
if !opts.DisableMetrics {
|
||||||
rm, err = getRepoModel(ctx, ms)
|
bus.SetRepoID(repoid)
|
||||||
if err != nil {
|
|
||||||
return nil, clues.New("retrieving repo info")
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.SetRepoID(string(rm.ID))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete <- struct{}{}
|
complete <- struct{}{}
|
||||||
|
|
||||||
// todo: ID and CreatedAt should get retrieved from a stored kopia config.
|
// todo: ID and CreatedAt should get retrieved from a stored kopia config.
|
||||||
return &repository{
|
return &repository{
|
||||||
ID: string(rm.ID),
|
ID: repoid,
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Account: acct,
|
Account: acct,
|
||||||
Storage: s,
|
Storage: s,
|
||||||
@ -259,9 +253,10 @@ func Connect(
|
|||||||
func ConnectAndSendConnectEvent(ctx context.Context,
|
func ConnectAndSendConnectEvent(ctx context.Context,
|
||||||
acct account.Account,
|
acct account.Account,
|
||||||
s storage.Storage,
|
s storage.Storage,
|
||||||
|
repoid string,
|
||||||
opts control.Options,
|
opts control.Options,
|
||||||
) (Repository, error) {
|
) (Repository, error) {
|
||||||
repo, err := Connect(ctx, acct, s, opts)
|
repo, err := Connect(ctx, acct, s, repoid, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,7 @@ func (suite *RepositoryUnitSuite) TestConnect() {
|
|||||||
st, err := test.storage()
|
st, err := test.storage()
|
||||||
assert.NoError(t, err, clues.ToCore(err))
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
_, err = repository.Connect(ctx, test.account, st, control.Defaults())
|
_, err = repository.Connect(ctx, test.account, st, "not_found", control.Defaults())
|
||||||
test.errCheck(t, err, clues.ToCore(err))
|
test.errCheck(t, err, clues.ToCore(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -183,11 +183,11 @@ func (suite *RepositoryIntegrationSuite) TestConnect() {
|
|||||||
// need to initialize the repository before we can test connecting to it.
|
// need to initialize the repository before we can test connecting to it.
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
|
|
||||||
_, err := repository.Initialize(ctx, account.Account{}, st, control.Defaults())
|
repo, err := repository.Initialize(ctx, account.Account{}, st, control.Defaults())
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// now re-connect
|
// now re-connect
|
||||||
_, err = repository.Connect(ctx, account.Account{}, st, control.Defaults())
|
_, err = repository.Connect(ctx, account.Account{}, st, repo.GetID(), control.Defaults())
|
||||||
assert.NoError(t, err, clues.ToCore(err))
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ func (suite *RepositoryIntegrationSuite) TestConnect_sameID() {
|
|||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// now re-connect
|
// now re-connect
|
||||||
r, err = repository.Connect(ctx, account.Account{}, st, control.Defaults())
|
r, err = repository.Connect(ctx, account.Account{}, st, oldID, control.Defaults())
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
assert.Equal(t, oldID, r.GetID())
|
assert.Equal(t, oldID, r.GetID())
|
||||||
}
|
}
|
||||||
@ -283,12 +283,13 @@ func (suite *RepositoryIntegrationSuite) TestConnect_DisableMetrics() {
|
|||||||
// need to initialize the repository before we can test connecting to it.
|
// need to initialize the repository before we can test connecting to it.
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
|
|
||||||
_, err := repository.Initialize(ctx, account.Account{}, st, control.Defaults())
|
repo, err := repository.Initialize(ctx, account.Account{}, st, control.Defaults())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// now re-connect
|
// now re-connect
|
||||||
r, err := repository.Connect(ctx, account.Account{}, st, control.Options{DisableMetrics: true})
|
r, err := repository.Connect(ctx, account.Account{}, st, repo.GetID(), control.Options{DisableMetrics: true})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "", r.GetID())
|
// now we have repoID beforehand
|
||||||
|
assert.Equal(t, r.GetID(), r.GetID())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user