migrate deltaPaths to graph, add qp validator
Adds a queryParam validation step. Migrates the DeltaPaths struct into graph so that it can have centralized usage.
This commit is contained in:
parent
28ad304bb7
commit
873b404386
@ -30,44 +30,15 @@ func MetadataFileNames(cat path.CategoryType) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CatDeltaPaths map[path.CategoryType]DeltaPaths
|
|
||||||
|
|
||||||
type DeltaPaths map[string]DeltaPath
|
|
||||||
|
|
||||||
func (dps DeltaPaths) AddDelta(k, d string) {
|
|
||||||
dp, ok := dps[k]
|
|
||||||
if !ok {
|
|
||||||
dp = DeltaPath{}
|
|
||||||
}
|
|
||||||
|
|
||||||
dp.delta = d
|
|
||||||
dps[k] = dp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dps DeltaPaths) AddPath(k, p string) {
|
|
||||||
dp, ok := dps[k]
|
|
||||||
if !ok {
|
|
||||||
dp = DeltaPath{}
|
|
||||||
}
|
|
||||||
|
|
||||||
dp.path = p
|
|
||||||
dps[k] = dp
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeltaPath struct {
|
|
||||||
delta string
|
|
||||||
path string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseMetadataCollections produces a map of structs holding delta
|
// ParseMetadataCollections produces a map of structs holding delta
|
||||||
// and path lookup maps.
|
// and path lookup maps.
|
||||||
func parseMetadataCollections(
|
func parseMetadataCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
colls []data.RestoreCollection,
|
colls []data.RestoreCollection,
|
||||||
errs *fault.Errors,
|
errs *fault.Errors,
|
||||||
) (CatDeltaPaths, error) {
|
) (graph.CatDeltaPaths, error) {
|
||||||
// cdp stores metadata
|
// cdp stores metadata
|
||||||
cdp := CatDeltaPaths{
|
cdp := graph.CatDeltaPaths{
|
||||||
path.ContactsCategory: {},
|
path.ContactsCategory: {},
|
||||||
path.EmailCategory: {},
|
path.EmailCategory: {},
|
||||||
path.EventsCategory: {},
|
path.EventsCategory: {},
|
||||||
@ -147,7 +118,7 @@ func parseMetadataCollections(
|
|||||||
// complete backup on the next run.
|
// complete backup on the next run.
|
||||||
for _, dps := range cdp {
|
for _, dps := range cdp {
|
||||||
for k, dp := range dps {
|
for k, dp := range dps {
|
||||||
if len(dp.delta) == 0 || len(dp.path) == 0 {
|
if len(dp.Delta) == 0 || len(dp.Path) == 0 {
|
||||||
delete(dps, k)
|
delete(dps, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,7 +202,7 @@ func createCollections(
|
|||||||
creds account.M365Config,
|
creds account.M365Config,
|
||||||
user string,
|
user string,
|
||||||
scope selectors.ExchangeScope,
|
scope selectors.ExchangeScope,
|
||||||
dps DeltaPaths,
|
dps graph.DeltaPaths,
|
||||||
ctrlOpts control.Options,
|
ctrlOpts control.Options,
|
||||||
su support.StatusUpdater,
|
su support.StatusUpdater,
|
||||||
errs *fault.Errors,
|
errs *fault.Errors,
|
||||||
@ -256,6 +227,11 @@ func createCollections(
|
|||||||
Category: category,
|
Category: category,
|
||||||
ResourceOwner: user,
|
ResourceOwner: user,
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
|
DeltaPaths: dps,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := qp.Validate(); err != nil {
|
||||||
|
return nil, clues.Wrap(err, "validating collection parameters").WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
foldersComplete, closer := observe.MessageWithCompletion(ctx, observe.Bulletf(
|
foldersComplete, closer := observe.MessageWithCompletion(ctx, observe.Bulletf(
|
||||||
@ -278,7 +254,6 @@ func createCollections(
|
|||||||
su,
|
su,
|
||||||
resolver,
|
resolver,
|
||||||
scope,
|
scope,
|
||||||
dps,
|
|
||||||
ctrlOpts,
|
ctrlOpts,
|
||||||
errs)
|
errs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -41,7 +41,7 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
data []fileValues
|
data []fileValues
|
||||||
expect map[string]DeltaPath
|
expect map[string]graph.DeltaPath
|
||||||
expectError assert.ErrorAssertionFunc
|
expectError assert.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
data: []fileValues{
|
data: []fileValues{
|
||||||
{graph.DeltaURLsFileName, "delta-link"},
|
{graph.DeltaURLsFileName, "delta-link"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{},
|
expect: map[string]graph.DeltaPath{},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -65,7 +65,7 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
data: []fileValues{
|
data: []fileValues{
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{},
|
expect: map[string]graph.DeltaPath{},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -82,10 +82,10 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, "delta-link"},
|
{graph.DeltaURLsFileName, "delta-link"},
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{
|
expect: map[string]graph.DeltaPath{
|
||||||
"key": {
|
"key": {
|
||||||
delta: "delta-link",
|
Delta: "delta-link",
|
||||||
path: "prev-path",
|
Path: "prev-path",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
@ -96,7 +96,7 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, "delta-link"},
|
{graph.DeltaURLsFileName, "delta-link"},
|
||||||
{graph.PreviousPathFileName, ""},
|
{graph.PreviousPathFileName, ""},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{},
|
expect: map[string]graph.DeltaPath{},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, ""},
|
{graph.DeltaURLsFileName, ""},
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{},
|
expect: map[string]graph.DeltaPath{},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -114,10 +114,10 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, "`!@#$%^&*()_[]{}/\"\\"},
|
{graph.DeltaURLsFileName, "`!@#$%^&*()_[]{}/\"\\"},
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{
|
expect: map[string]graph.DeltaPath{
|
||||||
"key": {
|
"key": {
|
||||||
delta: "`!@#$%^&*()_[]{}/\"\\",
|
Delta: "`!@#$%^&*()_[]{}/\"\\",
|
||||||
path: "prev-path",
|
Path: "prev-path",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
@ -128,10 +128,10 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, `\n\r\t\b\f\v\0\\`},
|
{graph.DeltaURLsFileName, `\n\r\t\b\f\v\0\\`},
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{
|
expect: map[string]graph.DeltaPath{
|
||||||
"key": {
|
"key": {
|
||||||
delta: "\\n\\r\\t\\b\\f\\v\\0\\\\",
|
Delta: "\\n\\r\\t\\b\\f\\v\\0\\\\",
|
||||||
path: "prev-path",
|
Path: "prev-path",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
@ -145,10 +145,10 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
{graph.DeltaURLsFileName, string([]rune{rune(92), rune(110)})},
|
{graph.DeltaURLsFileName, string([]rune{rune(92), rune(110)})},
|
||||||
{graph.PreviousPathFileName, "prev-path"},
|
{graph.PreviousPathFileName, "prev-path"},
|
||||||
},
|
},
|
||||||
expect: map[string]DeltaPath{
|
expect: map[string]graph.DeltaPath{
|
||||||
"key": {
|
"key": {
|
||||||
delta: "\\n",
|
Delta: "\\n",
|
||||||
path: "prev-path",
|
Path: "prev-path",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectError: assert.NoError,
|
expectError: assert.NoError,
|
||||||
@ -186,8 +186,8 @@ func (suite *DataCollectionsUnitSuite) TestParseMetadataCollections() {
|
|||||||
assert.Len(t, emails, len(test.expect))
|
assert.Len(t, emails, len(test.expect))
|
||||||
|
|
||||||
for k, v := range emails {
|
for k, v := range emails {
|
||||||
assert.Equal(t, v.delta, emails[k].delta, "delta")
|
assert.Equal(t, v.Delta, emails[k].Delta, "delta")
|
||||||
assert.Equal(t, v.path, emails[k].path, "path")
|
assert.Equal(t, v.Path, emails[k].Path, "path")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ func (suite *DataCollectionsIntegrationSuite) TestMailFetch() {
|
|||||||
acct,
|
acct,
|
||||||
userID,
|
userID,
|
||||||
test.scope,
|
test.scope,
|
||||||
DeltaPaths{},
|
graph.DeltaPaths{},
|
||||||
control.Options{},
|
control.Options{},
|
||||||
func(status *support.ConnectorOperationStatus) {},
|
func(status *support.ConnectorOperationStatus) {},
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
@ -334,7 +334,7 @@ func (suite *DataCollectionsIntegrationSuite) TestDelta() {
|
|||||||
acct,
|
acct,
|
||||||
userID,
|
userID,
|
||||||
test.scope,
|
test.scope,
|
||||||
DeltaPaths{},
|
graph.DeltaPaths{},
|
||||||
control.Options{},
|
control.Options{},
|
||||||
func(status *support.ConnectorOperationStatus) {},
|
func(status *support.ConnectorOperationStatus) {},
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
@ -411,7 +411,7 @@ func (suite *DataCollectionsIntegrationSuite) TestMailSerializationRegression()
|
|||||||
acct,
|
acct,
|
||||||
suite.user,
|
suite.user,
|
||||||
sel.Scopes()[0],
|
sel.Scopes()[0],
|
||||||
DeltaPaths{},
|
graph.DeltaPaths{},
|
||||||
control.Options{},
|
control.Options{},
|
||||||
newStatusUpdater(t, &wg),
|
newStatusUpdater(t, &wg),
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
@ -479,7 +479,7 @@ func (suite *DataCollectionsIntegrationSuite) TestContactSerializationRegression
|
|||||||
acct,
|
acct,
|
||||||
suite.user,
|
suite.user,
|
||||||
test.scope,
|
test.scope,
|
||||||
DeltaPaths{},
|
graph.DeltaPaths{},
|
||||||
control.Options{},
|
control.Options{},
|
||||||
newStatusUpdater(t, &wg),
|
newStatusUpdater(t, &wg),
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
@ -587,7 +587,7 @@ func (suite *DataCollectionsIntegrationSuite) TestEventsSerializationRegression(
|
|||||||
acct,
|
acct,
|
||||||
suite.user,
|
suite.user,
|
||||||
test.scope,
|
test.scope,
|
||||||
DeltaPaths{},
|
graph.DeltaPaths{},
|
||||||
control.Options{},
|
control.Options{},
|
||||||
newStatusUpdater(t, &wg),
|
newStatusUpdater(t, &wg),
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
|
|||||||
@ -37,7 +37,6 @@ func filterContainersAndFillCollections(
|
|||||||
statusUpdater support.StatusUpdater,
|
statusUpdater support.StatusUpdater,
|
||||||
resolver graph.ContainerResolver,
|
resolver graph.ContainerResolver,
|
||||||
scope selectors.ExchangeScope,
|
scope selectors.ExchangeScope,
|
||||||
dps DeltaPaths,
|
|
||||||
ctrlOpts control.Options,
|
ctrlOpts control.Options,
|
||||||
errs *fault.Errors,
|
errs *fault.Errors,
|
||||||
) error {
|
) error {
|
||||||
@ -45,6 +44,7 @@ func filterContainersAndFillCollections(
|
|||||||
// folder ID -> delta url or folder path lookups
|
// folder ID -> delta url or folder path lookups
|
||||||
deltaURLs = map[string]string{}
|
deltaURLs = map[string]string{}
|
||||||
currPaths = map[string]string{}
|
currPaths = map[string]string{}
|
||||||
|
dps = qp.DeltaPaths
|
||||||
// copy of previousPaths. any folder found in the resolver get
|
// copy of previousPaths. any folder found in the resolver get
|
||||||
// deleted from this map, leaving only the deleted folders behind
|
// deleted from this map, leaving only the deleted folders behind
|
||||||
tombstones = makeTombstones(dps)
|
tombstones = makeTombstones(dps)
|
||||||
@ -79,8 +79,8 @@ func filterContainersAndFillCollections(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
dp = dps[cID]
|
dp = dps[cID]
|
||||||
prevDelta = dp.delta
|
prevDelta = dp.Delta
|
||||||
prevPathStr = dp.path
|
prevPathStr = dp.Path
|
||||||
prevPath path.Path
|
prevPath path.Path
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -209,11 +209,11 @@ func filterContainersAndFillCollections(
|
|||||||
// produces a set of id:path pairs from the deltapaths map.
|
// produces a set of id:path pairs from the deltapaths map.
|
||||||
// Each entry in the set will, if not removed, produce a collection
|
// Each entry in the set will, if not removed, produce a collection
|
||||||
// that will delete the tombstone by path.
|
// that will delete the tombstone by path.
|
||||||
func makeTombstones(dps DeltaPaths) map[string]string {
|
func makeTombstones(dps graph.DeltaPaths) map[string]string {
|
||||||
r := make(map[string]string, len(dps))
|
r := make(map[string]string, len(dps))
|
||||||
|
|
||||||
for id, v := range dps {
|
for id, v := range dps {
|
||||||
r[id] = v.path
|
r[id] = v.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
@ -121,10 +121,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections() {
|
|||||||
Category: path.EmailCategory, // doesn't matter which one we use.
|
Category: path.EmailCategory, // doesn't matter which one we use.
|
||||||
ResourceOwner: userID,
|
ResourceOwner: userID,
|
||||||
Credentials: suite.creds,
|
Credentials: suite.creds,
|
||||||
|
DeltaPaths: graph.DeltaPaths{}, // incrementals are tested separately
|
||||||
}
|
}
|
||||||
statusUpdater = func(*support.ConnectorOperationStatus) {}
|
statusUpdater = func(*support.ConnectorOperationStatus) {}
|
||||||
allScope = selectors.NewExchangeBackup(nil).MailFolders(selectors.Any())[0]
|
allScope = selectors.NewExchangeBackup(nil).MailFolders(selectors.Any())[0]
|
||||||
dps = DeltaPaths{} // incrementals are tested separately
|
|
||||||
commonResult = mockGetterResults{
|
commonResult = mockGetterResults{
|
||||||
added: []string{"a1", "a2", "a3"},
|
added: []string{"a1", "a2", "a3"},
|
||||||
removed: []string{"r1", "r2", "r3"},
|
removed: []string{"r1", "r2", "r3"},
|
||||||
@ -303,7 +303,6 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections() {
|
|||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
test.scope,
|
test.scope,
|
||||||
dps,
|
|
||||||
control.Options{FailFast: test.failFast},
|
control.Options{FailFast: test.failFast},
|
||||||
fault.New(test.failFast))
|
fault.New(test.failFast))
|
||||||
test.expectErr(t, err)
|
test.expectErr(t, err)
|
||||||
@ -434,10 +433,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_repea
|
|||||||
Category: path.EmailCategory, // doesn't matter which one we use.
|
Category: path.EmailCategory, // doesn't matter which one we use.
|
||||||
ResourceOwner: userID,
|
ResourceOwner: userID,
|
||||||
Credentials: suite.creds,
|
Credentials: suite.creds,
|
||||||
|
DeltaPaths: graph.DeltaPaths{}, // incrementals are tested separately
|
||||||
}
|
}
|
||||||
statusUpdater = func(*support.ConnectorOperationStatus) {}
|
statusUpdater = func(*support.ConnectorOperationStatus) {}
|
||||||
allScope = selectors.NewExchangeBackup(nil).MailFolders(selectors.Any())[0]
|
allScope = selectors.NewExchangeBackup(nil).MailFolders(selectors.Any())[0]
|
||||||
dps = DeltaPaths{} // incrementals are tested separately
|
|
||||||
container1 = mockContainer{
|
container1 = mockContainer{
|
||||||
id: strPtr("1"),
|
id: strPtr("1"),
|
||||||
displayName: strPtr("display_name_1"),
|
displayName: strPtr("display_name_1"),
|
||||||
@ -456,7 +455,6 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_repea
|
|||||||
statusUpdater,
|
statusUpdater,
|
||||||
resolver,
|
resolver,
|
||||||
allScope,
|
allScope,
|
||||||
dps,
|
|
||||||
control.Options{FailFast: true},
|
control.Options{FailFast: true},
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -548,7 +546,7 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
name string
|
name string
|
||||||
getter mockGetter
|
getter mockGetter
|
||||||
resolver graph.ContainerResolver
|
resolver graph.ContainerResolver
|
||||||
dps DeltaPaths
|
dps graph.DeltaPaths
|
||||||
expect map[string]endState
|
expect map[string]endState
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -561,7 +559,7 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("new"),
|
displayName: strPtr("new"),
|
||||||
p: path.Builder{}.Append("1", "new"),
|
p: path.Builder{}.Append("1", "new"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{},
|
dps: graph.DeltaPaths{},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
"1": {data.NewState, false},
|
"1": {data.NewState, false},
|
||||||
},
|
},
|
||||||
@ -576,10 +574,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("not_moved"),
|
displayName: strPtr("not_moved"),
|
||||||
p: path.Builder{}.Append("1", "not_moved"),
|
p: path.Builder{}.Append("1", "not_moved"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "not_moved").String(),
|
Path: prevPath(suite.T(), "1", "not_moved").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -596,10 +594,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("moved"),
|
displayName: strPtr("moved"),
|
||||||
p: path.Builder{}.Append("1", "moved"),
|
p: path.Builder{}.Append("1", "moved"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "prev").String(),
|
Path: prevPath(suite.T(), "1", "prev").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -610,10 +608,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
name: "deleted container",
|
name: "deleted container",
|
||||||
getter: map[string]mockGetterResults{},
|
getter: map[string]mockGetterResults{},
|
||||||
resolver: newMockResolver(),
|
resolver: newMockResolver(),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "deleted").String(),
|
Path: prevPath(suite.T(), "1", "deleted").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -630,10 +628,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("new"),
|
displayName: strPtr("new"),
|
||||||
p: path.Builder{}.Append("2", "new"),
|
p: path.Builder{}.Append("2", "new"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "deleted").String(),
|
Path: prevPath(suite.T(), "1", "deleted").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -651,10 +649,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("same"),
|
displayName: strPtr("same"),
|
||||||
p: path.Builder{}.Append("2", "same"),
|
p: path.Builder{}.Append("2", "same"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "same").String(),
|
Path: prevPath(suite.T(), "1", "same").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -680,10 +678,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
p: path.Builder{}.Append("2", "prev"),
|
p: path.Builder{}.Append("2", "prev"),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "prev").String(),
|
Path: prevPath(suite.T(), "1", "prev").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -701,14 +699,14 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("not_moved"),
|
displayName: strPtr("not_moved"),
|
||||||
p: path.Builder{}.Append("1", "not_moved"),
|
p: path.Builder{}.Append("1", "not_moved"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: "1/fnords/mc/smarfs",
|
Path: "1/fnords/mc/smarfs",
|
||||||
},
|
},
|
||||||
"2": DeltaPath{
|
"2": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: "2/fnords/mc/smarfs",
|
Path: "2/fnords/mc/smarfs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -725,10 +723,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
displayName: strPtr("same"),
|
displayName: strPtr("same"),
|
||||||
p: path.Builder{}.Append("1", "same"),
|
p: path.Builder{}.Append("1", "same"),
|
||||||
}),
|
}),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"1": DeltaPath{
|
"1": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "1", "same").String(),
|
Path: prevPath(suite.T(), "1", "same").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -766,22 +764,22 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
p: path.Builder{}.Append("4", "moved"),
|
p: path.Builder{}.Append("4", "moved"),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
dps: DeltaPaths{
|
dps: graph.DeltaPaths{
|
||||||
"2": DeltaPath{
|
"2": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "2", "not_moved").String(),
|
Path: prevPath(suite.T(), "2", "not_moved").String(),
|
||||||
},
|
},
|
||||||
"3": DeltaPath{
|
"3": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "3", "prev").String(),
|
Path: prevPath(suite.T(), "3", "prev").String(),
|
||||||
},
|
},
|
||||||
"4": DeltaPath{
|
"4": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "4", "prev").String(),
|
Path: prevPath(suite.T(), "4", "prev").String(),
|
||||||
},
|
},
|
||||||
"5": DeltaPath{
|
"5": graph.DeltaPath{
|
||||||
delta: "old_delta_url",
|
Delta: "old_delta_url",
|
||||||
path: prevPath(suite.T(), "5", "deleted").String(),
|
Path: prevPath(suite.T(), "5", "deleted").String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: map[string]endState{
|
expect: map[string]endState{
|
||||||
@ -799,6 +797,7 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections := map[string]data.BackupCollection{}
|
||||||
|
qp.DeltaPaths = test.dps
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
err := filterContainersAndFillCollections(
|
||||||
ctx,
|
ctx,
|
||||||
@ -808,7 +807,6 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
allScope,
|
allScope,
|
||||||
test.dps,
|
|
||||||
control.Options{},
|
control.Options{},
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
66
src/internal/connector/graph/query_params.go
Normal file
66
src/internal/connector/graph/query_params.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// query parameter aggregation
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type QueryParams struct {
|
||||||
|
Category path.CategoryType
|
||||||
|
ResourceOwner string
|
||||||
|
Credentials account.M365Config
|
||||||
|
DeltaPaths DeltaPaths
|
||||||
|
}
|
||||||
|
|
||||||
|
func (qp QueryParams) Validate() error {
|
||||||
|
if qp.Category == path.UnknownCategory {
|
||||||
|
return clues.New("unknown category")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(qp.ResourceOwner) == 0 {
|
||||||
|
return clues.New("missing resource owner")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// delta path aggregation
|
||||||
|
//
|
||||||
|
// TODO: probably needs to be owned somewhere besides graph, but for now
|
||||||
|
// this allows the struct to be centralized and re-used through GC.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type CatDeltaPaths map[path.CategoryType]DeltaPaths
|
||||||
|
|
||||||
|
type DeltaPaths map[string]DeltaPath
|
||||||
|
|
||||||
|
func (dps DeltaPaths) AddDelta(k, d string) {
|
||||||
|
dp, ok := dps[k]
|
||||||
|
if !ok {
|
||||||
|
dp = DeltaPath{}
|
||||||
|
}
|
||||||
|
|
||||||
|
dp.Delta = d
|
||||||
|
dps[k] = dp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dps DeltaPaths) AddPath(k, p string) {
|
||||||
|
dp, ok := dps[k]
|
||||||
|
if !ok {
|
||||||
|
dp = DeltaPath{}
|
||||||
|
}
|
||||||
|
|
||||||
|
dp.Path = p
|
||||||
|
dps[k] = dp
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeltaPath struct {
|
||||||
|
Delta string
|
||||||
|
Path string
|
||||||
|
}
|
||||||
@ -16,9 +16,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -37,12 +35,6 @@ func AllMetadataFileNames() []string {
|
|||||||
return []string{DeltaURLsFileName, PreviousPathFileName}
|
return []string{DeltaURLsFileName, PreviousPathFileName}
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryParams struct {
|
|
||||||
Category path.CategoryType
|
|
||||||
ResourceOwner string
|
|
||||||
Credentials account.M365Config
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Service Handler
|
// Service Handler
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user