Return interface values instead of concrete type (#1696)
## Description Having a map of interface values instead of concrete structs allows adding collection implementations via different structs. This will be useful to inject a new collection that contains metadata information like delta links. Also refactors the code for creating collections in Exchange so that it follows golang patterns of exiting early a bit better. ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [x] 🐹 Trivial/Minor ## Issue(s) * #1685 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
7e2fbbea4f
commit
55a03af95f
@ -109,16 +109,16 @@ func verifyBackupInputs(sels selectors.Selector, userPNs, siteIDs []string) erro
|
|||||||
func (gc *GraphConnector) createExchangeCollections(
|
func (gc *GraphConnector) createExchangeCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
scope selectors.ExchangeScope,
|
scope selectors.ExchangeScope,
|
||||||
) ([]*exchange.Collection, error) {
|
) ([]data.Collection, error) {
|
||||||
var (
|
var (
|
||||||
errs *multierror.Error
|
errs *multierror.Error
|
||||||
users = scope.Get(selectors.ExchangeUser)
|
users = scope.Get(selectors.ExchangeUser)
|
||||||
allCollections = make([]*exchange.Collection, 0)
|
allCollections = make([]data.Collection, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create collection of ExchangeDataCollection
|
// Create collection of ExchangeDataCollection
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
collections := make(map[string]*exchange.Collection)
|
collections := make(map[string]data.Collection)
|
||||||
|
|
||||||
qp := graph.QueryParams{
|
qp := graph.QueryParams{
|
||||||
Category: scope.Category().PathType(),
|
Category: scope.Category().PathType(),
|
||||||
@ -188,9 +188,7 @@ func (gc *GraphConnector) ExchangeDataCollection(
|
|||||||
return nil, support.WrapAndAppend(user[0], err, errs)
|
return nil, support.WrapAndAppend(user[0], err, errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, collection := range dcs {
|
collections = append(collections, dcs...)
|
||||||
collections = append(collections, collection)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return collections, errs
|
return collections, errs
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/connector/exchange"
|
"github.com/alcionai/corso/src/internal/connector/exchange"
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
)
|
)
|
||||||
@ -336,11 +337,11 @@ func (suite *ConnectorCreateExchangeCollectionIntegrationSuite) TestContactSeria
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
getCollection func(t *testing.T) []*exchange.Collection
|
getCollection func(t *testing.T) []data.Collection
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Default Contact Folder",
|
name: "Default Contact Folder",
|
||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []data.Collection {
|
||||||
scope := selectors.
|
scope := selectors.
|
||||||
NewExchangeBackup().
|
NewExchangeBackup().
|
||||||
ContactFolders([]string{suite.user}, []string{exchange.DefaultContactFolder}, selectors.PrefixMatch())[0]
|
ContactFolders([]string{suite.user}, []string{exchange.DefaultContactFolder}, selectors.PrefixMatch())[0]
|
||||||
@ -389,12 +390,12 @@ func (suite *ConnectorCreateExchangeCollectionIntegrationSuite) TestEventsSerial
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name, expected string
|
name, expected string
|
||||||
getCollection func(t *testing.T) []*exchange.Collection
|
getCollection func(t *testing.T) []data.Collection
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Default Event Calendar",
|
name: "Default Event Calendar",
|
||||||
expected: exchange.DefaultCalendar,
|
expected: exchange.DefaultCalendar,
|
||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []data.Collection {
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.EventCalendars([]string{suite.user}, []string{exchange.DefaultCalendar}, selectors.PrefixMatch()))
|
sel.Include(sel.EventCalendars([]string{suite.user}, []string{exchange.DefaultCalendar}, selectors.PrefixMatch()))
|
||||||
collections, err := connector.createExchangeCollections(ctx, sel.Scopes()[0])
|
collections, err := connector.createExchangeCollections(ctx, sel.Scopes()[0])
|
||||||
@ -406,7 +407,7 @@ func (suite *ConnectorCreateExchangeCollectionIntegrationSuite) TestEventsSerial
|
|||||||
{
|
{
|
||||||
name: "Birthday Calendar",
|
name: "Birthday Calendar",
|
||||||
expected: "Birthdays",
|
expected: "Birthdays",
|
||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []data.Collection {
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.EventCalendars([]string{suite.user}, []string{"Birthdays"}, selectors.PrefixMatch()))
|
sel.Include(sel.EventCalendars([]string{suite.user}, []string{"Birthdays"}, selectors.PrefixMatch()))
|
||||||
collections, err := connector.createExchangeCollections(ctx, sel.Scopes()[0])
|
collections, err := connector.createExchangeCollections(ctx, sel.Scopes()[0])
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
)
|
)
|
||||||
@ -24,9 +25,9 @@ const nextLinkKey = "@odata.nextLink"
|
|||||||
// the value is not in the map returns an empty string.
|
// the value is not in the map returns an empty string.
|
||||||
func getAdditionalDataString(
|
func getAdditionalDataString(
|
||||||
key string,
|
key string,
|
||||||
data map[string]any,
|
addtlData map[string]any,
|
||||||
) string {
|
) string {
|
||||||
iface := data[key]
|
iface := addtlData[key]
|
||||||
if iface == nil {
|
if iface == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -47,45 +48,45 @@ func getAdditionalDataString(
|
|||||||
func FilterContainersAndFillCollections(
|
func FilterContainersAndFillCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
qp graph.QueryParams,
|
qp graph.QueryParams,
|
||||||
collections map[string]*Collection,
|
collections map[string]data.Collection,
|
||||||
statusUpdater support.StatusUpdater,
|
statusUpdater support.StatusUpdater,
|
||||||
resolver graph.ContainerResolver,
|
resolver graph.ContainerResolver,
|
||||||
scope selectors.ExchangeScope,
|
scope selectors.ExchangeScope,
|
||||||
) error {
|
) error {
|
||||||
var (
|
var (
|
||||||
collectionType = CategoryToOptionIdentifier(scope.Category().PathType())
|
|
||||||
errs error
|
errs error
|
||||||
|
collectionType = CategoryToOptionIdentifier(qp.Category)
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, c := range resolver.Items() {
|
for _, c := range resolver.Items() {
|
||||||
dirPath, ok := pathAndMatch(qp, c, scope)
|
dirPath, ok := pathAndMatch(qp, c, scope)
|
||||||
if ok {
|
if !ok {
|
||||||
// Create only those that match
|
continue
|
||||||
service, err := createService(qp.Credentials, qp.FailFast)
|
|
||||||
if err != nil {
|
|
||||||
errs = support.WrapAndAppend(
|
|
||||||
qp.ResourceOwner+" FilterContainerAndFillCollection",
|
|
||||||
err,
|
|
||||||
errs)
|
|
||||||
|
|
||||||
if qp.FailFast {
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
edc := NewCollection(
|
|
||||||
qp.ResourceOwner,
|
|
||||||
dirPath,
|
|
||||||
collectionType,
|
|
||||||
service,
|
|
||||||
statusUpdater,
|
|
||||||
)
|
|
||||||
collections[*c.GetId()] = &edc
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for directoryID, col := range collections {
|
// Create only those that match
|
||||||
fetchFunc, err := getFetchIDFunc(scope.Category().PathType())
|
service, err := createService(qp.Credentials, qp.FailFast)
|
||||||
|
if err != nil {
|
||||||
|
errs = support.WrapAndAppend(
|
||||||
|
qp.ResourceOwner+" FilterContainerAndFillCollection",
|
||||||
|
err,
|
||||||
|
errs)
|
||||||
|
|
||||||
|
if qp.FailFast {
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edc := NewCollection(
|
||||||
|
qp.ResourceOwner,
|
||||||
|
dirPath,
|
||||||
|
collectionType,
|
||||||
|
service,
|
||||||
|
statusUpdater,
|
||||||
|
)
|
||||||
|
collections[*c.GetId()] = &edc
|
||||||
|
|
||||||
|
fetchFunc, err := getFetchIDFunc(qp.Category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = support.WrapAndAppend(
|
errs = support.WrapAndAppend(
|
||||||
qp.ResourceOwner,
|
qp.ResourceOwner,
|
||||||
@ -99,7 +100,7 @@ func FilterContainersAndFillCollections(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
jobs, err := fetchFunc(ctx, col.service, qp.ResourceOwner, directoryID)
|
jobs, err := fetchFunc(ctx, edc.service, qp.ResourceOwner, *c.GetId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = support.WrapAndAppend(
|
errs = support.WrapAndAppend(
|
||||||
qp.ResourceOwner,
|
qp.ResourceOwner,
|
||||||
@ -108,7 +109,7 @@ func FilterContainersAndFillCollections(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
col.jobs = append(col.jobs, jobs...)
|
edc.jobs = append(edc.jobs, jobs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user