From bdc854c1da82d2847f97695c2ff1f8568abd9ac5 Mon Sep 17 00:00:00 2001 From: Keepers Date: Tue, 21 Mar 2023 00:51:14 -0600 Subject: [PATCH] scopes typing rename, filter -> info (#2842) Renames a lot of the names in scopes that contain the word "filter" with the word "info". The basis here is to reduce confusion in the libraries. Filter as a term is overloaded. It currently means: 1/ the set of scopes that comparisons _must_ pass to succeed; 2/ the pkg and struct that handles comparison logic; and 3/ the set of scopes that compare values in details.ItemInfo instead of in the item's storage or logical path. The third category is the primary overload here, and is better off with a different name. --- #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :broom: Tech Debt/Cleanup #### Test Plan - [x] :zap: Unit test --- src/cli/utils/exchange.go | 24 ++--- src/cli/utils/sharepoint.go | 14 +-- src/pkg/selectors/exchange.go | 135 +++++++++++++-------------- src/pkg/selectors/exchange_test.go | 20 ++-- src/pkg/selectors/helpers_test.go | 2 +- src/pkg/selectors/onedrive.go | 59 ++++++------ src/pkg/selectors/onedrive_test.go | 10 +- src/pkg/selectors/scopes.go | 28 +++--- src/pkg/selectors/selectors.go | 8 +- src/pkg/selectors/sharepoint.go | 74 +++++++-------- src/pkg/selectors/sharepoint_test.go | 2 +- 11 files changed, 188 insertions(+), 188 deletions(-) diff --git a/src/cli/utils/exchange.go b/src/cli/utils/exchange.go index bbc360dfb..f209a719b 100644 --- a/src/cli/utils/exchange.go +++ b/src/cli/utils/exchange.go @@ -79,9 +79,9 @@ func AddExchangeInclude( } } -// AddExchangeFilter adds the scope of the provided values to the selector's +// AddExchangeInfo adds the scope of the provided values to the selector's // filter set -func AddExchangeFilter( +func AddExchangeInfo( sel *selectors.ExchangeRestore, v string, f func(string) []selectors.ExchangeScope, @@ -156,14 +156,14 @@ func FilterExchangeRestoreInfoSelectors( sel *selectors.ExchangeRestore, opts ExchangeOpts, ) { - AddExchangeFilter(sel, opts.ContactName, sel.ContactName) - AddExchangeFilter(sel, opts.EmailReceivedAfter, sel.MailReceivedAfter) - AddExchangeFilter(sel, opts.EmailReceivedBefore, sel.MailReceivedBefore) - AddExchangeFilter(sel, opts.EmailSender, sel.MailSender) - AddExchangeFilter(sel, opts.EmailSubject, sel.MailSubject) - AddExchangeFilter(sel, opts.EventOrganizer, sel.EventOrganizer) - AddExchangeFilter(sel, opts.EventRecurs, sel.EventRecurs) - AddExchangeFilter(sel, opts.EventStartsAfter, sel.EventStartsAfter) - AddExchangeFilter(sel, opts.EventStartsBefore, sel.EventStartsBefore) - AddExchangeFilter(sel, opts.EventSubject, sel.EventSubject) + AddExchangeInfo(sel, opts.ContactName, sel.ContactName) + AddExchangeInfo(sel, opts.EmailReceivedAfter, sel.MailReceivedAfter) + AddExchangeInfo(sel, opts.EmailReceivedBefore, sel.MailReceivedBefore) + AddExchangeInfo(sel, opts.EmailSender, sel.MailSender) + AddExchangeInfo(sel, opts.EmailSubject, sel.MailSubject) + AddExchangeInfo(sel, opts.EventOrganizer, sel.EventOrganizer) + AddExchangeInfo(sel, opts.EventRecurs, sel.EventRecurs) + AddExchangeInfo(sel, opts.EventStartsAfter, sel.EventStartsAfter) + AddExchangeInfo(sel, opts.EventStartsBefore, sel.EventStartsBefore) + AddExchangeInfo(sel, opts.EventSubject, sel.EventSubject) } diff --git a/src/cli/utils/sharepoint.go b/src/cli/utils/sharepoint.go index 83cfc0a1a..f31cff7e9 100644 --- a/src/cli/utils/sharepoint.go +++ b/src/cli/utils/sharepoint.go @@ -58,9 +58,9 @@ func ValidateSharePointRestoreFlags(backupID string, opts SharePointOpts) error return nil } -// AddSharePointFilter adds the scope of the provided values to the selector's +// AddSharePointInfo adds the scope of the provided values to the selector's // filter set -func AddSharePointFilter( +func AddSharePointInfo( sel *selectors.SharePointRestore, v string, f func(string) []selectors.SharePointScope, @@ -165,9 +165,9 @@ func FilterSharePointRestoreInfoSelectors( sel *selectors.SharePointRestore, opts SharePointOpts, ) { - AddSharePointFilter(sel, opts.Library, sel.Library) - AddSharePointFilter(sel, opts.FileCreatedAfter, sel.CreatedAfter) - AddSharePointFilter(sel, opts.FileCreatedBefore, sel.CreatedBefore) - AddSharePointFilter(sel, opts.FileModifiedAfter, sel.ModifiedAfter) - AddSharePointFilter(sel, opts.FileModifiedBefore, sel.ModifiedBefore) + AddSharePointInfo(sel, opts.Library, sel.Library) + AddSharePointInfo(sel, opts.FileCreatedAfter, sel.CreatedAfter) + AddSharePointInfo(sel, opts.FileCreatedBefore, sel.CreatedBefore) + AddSharePointInfo(sel, opts.FileModifiedAfter, sel.ModifiedAfter) + AddSharePointInfo(sel, opts.FileModifiedBefore, sel.ModifiedBefore) } diff --git a/src/pkg/selectors/exchange.go b/src/pkg/selectors/exchange.go index 3eda3acac..06cad9456 100644 --- a/src/pkg/selectors/exchange.go +++ b/src/pkg/selectors/exchange.go @@ -323,149 +323,149 @@ func (s *exchange) AllData() []ExchangeScope { } // ------------------- -// Filter Factories +// Info Factories -// ContactName produces one or more exchange contact name filter scopes. +// ContactName produces one or more exchange contact name info scopes. // Matches any contact whose name contains the provided string. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) ContactName(senderID string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeContact, - ExchangeFilterContactName, + ExchangeInfoContactName, []string{senderID}, wrapSliceFilter(filters.In)), } } -// EventSubject produces one or more exchange event subject filter scopes. +// EventSubject produces one or more exchange event subject info scopes. // Matches any event where the event subject contains one of the provided strings. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) EventOrganizer(organizer string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeEvent, - ExchangeFilterEventOrganizer, + ExchangeInfoEventOrganizer, []string{organizer}, wrapSliceFilter(filters.In)), } } -// EventRecurs produces one or more exchange event recurrence filter scopes. +// EventRecurs produces one or more exchange event recurrence info scopes. // Matches any event if the comparator flag matches the event recurrence flag. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) EventRecurs(recurs string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeEvent, - ExchangeFilterEventRecurs, + ExchangeInfoEventRecurs, []string{recurs}, wrapFilter(filters.Equal)), } } -// EventStartsAfter produces an exchange event starts-after filter scope. +// EventStartsAfter produces an exchange event starts-after info scope. // Matches any event where the start time is after the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (sr *ExchangeRestore) EventStartsAfter(timeStrings string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeEvent, - ExchangeFilterEventStartsAfter, + ExchangeInfoEventStartsAfter, []string{timeStrings}, wrapFilter(filters.Less)), } } -// EventStartsBefore produces an exchange event starts-before filter scope. +// EventStartsBefore produces an exchange event starts-before info scope. // Matches any event where the start time is before the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (sr *ExchangeRestore) EventStartsBefore(timeStrings string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeEvent, - ExchangeFilterEventStartsBefore, + ExchangeInfoEventStartsBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } } -// EventSubject produces one or more exchange event subject filter scopes. +// EventSubject produces one or more exchange event subject info scopes. // Matches any event where the event subject contains one of the provided strings. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) EventSubject(subject string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeEvent, - ExchangeFilterEventSubject, + ExchangeInfoEventSubject, []string{subject}, wrapSliceFilter(filters.In)), } } -// MailReceivedAfter produces an exchange mail received-after filter scope. +// MailReceivedAfter produces an exchange mail received-after info scope. // Matches any mail which was received after the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (sr *ExchangeRestore) MailReceivedAfter(timeStrings string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeMail, - ExchangeFilterMailReceivedAfter, + ExchangeInfoMailReceivedAfter, []string{timeStrings}, wrapFilter(filters.Less)), } } -// MailReceivedBefore produces an exchange mail received-before filter scope. +// MailReceivedBefore produces an exchange mail received-before info scope. // Matches any mail which was received before the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (sr *ExchangeRestore) MailReceivedBefore(timeStrings string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeMail, - ExchangeFilterMailReceivedBefore, + ExchangeInfoMailReceivedBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } } -// MailSender produces one or more exchange mail sender filter scopes. +// MailSender produces one or more exchange mail sender info scopes. // Matches any mail whose sender contains one of the provided strings. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) MailSender(sender string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeMail, - ExchangeFilterMailSender, + ExchangeInfoMailSender, []string{sender}, wrapSliceFilter(filters.In)), } } -// MailSubject produces one or more exchange mail subject line filter scopes. +// MailSubject produces one or more exchange mail subject line info scopes. // Matches any mail whose subject contains one of the provided strings. // If any slice contains selectors.Any, that slice is reduced to [selectors.Any] // If any slice contains selectors.None, that slice is reduced to [selectors.None] // If any slice is empty, it defaults to [selectors.None] func (sr *ExchangeRestore) MailSubject(subject string) []ExchangeScope { return []ExchangeScope{ - makeFilterScope[ExchangeScope]( + makeInfoScope[ExchangeScope]( ExchangeMail, - ExchangeFilterMailSubject, + ExchangeInfoMailSubject, []string{subject}, wrapSliceFilter(filters.In)), } @@ -484,6 +484,7 @@ var _ categorizer = ExchangeCategoryUnknown const ( ExchangeCategoryUnknown exchangeCategory = "" + // types of data identified by exchange ExchangeContact exchangeCategory = "ExchangeContact" ExchangeContactFolder exchangeCategory = "ExchangeContactFolder" @@ -492,20 +493,18 @@ const ( ExchangeMail exchangeCategory = "ExchangeMail" ExchangeMailFolder exchangeCategory = "ExchangeMailFolder" ExchangeUser exchangeCategory = "ExchangeUser" - // append new data cats here - // filterable topics identified by exchange - ExchangeFilterMailSender exchangeCategory = "ExchangeFilterMailSender" - ExchangeFilterMailSubject exchangeCategory = "ExchangeFilterMailSubject" - ExchangeFilterMailReceivedAfter exchangeCategory = "ExchangeFilterMailReceivedAfter" - ExchangeFilterMailReceivedBefore exchangeCategory = "ExchangeFilterMailReceivedBefore" - ExchangeFilterContactName exchangeCategory = "ExchangeFilterContactName" - ExchangeFilterEventOrganizer exchangeCategory = "ExchangeFilterEventOrganizer" - ExchangeFilterEventRecurs exchangeCategory = "ExchangeFilterEventRecurs" - ExchangeFilterEventStartsAfter exchangeCategory = "ExchangeFilterEventStartsAfter" - ExchangeFilterEventStartsBefore exchangeCategory = "ExchangeFilterEventStartsBefore" - ExchangeFilterEventSubject exchangeCategory = "ExchangeFilterEventSubject" - // append new filter cats here + // data contained within details.ItemInfo + ExchangeInfoMailSender exchangeCategory = "ExchangeInfoMailSender" + ExchangeInfoMailSubject exchangeCategory = "ExchangeInfoMailSubject" + ExchangeInfoMailReceivedAfter exchangeCategory = "ExchangeInfoMailReceivedAfter" + ExchangeInfoMailReceivedBefore exchangeCategory = "ExchangeInfoMailReceivedBefore" + ExchangeInfoContactName exchangeCategory = "ExchangeInfoContactName" + ExchangeInfoEventOrganizer exchangeCategory = "ExchangeInfoEventOrganizer" + ExchangeInfoEventRecurs exchangeCategory = "ExchangeInfoEventRecurs" + ExchangeInfoEventStartsAfter exchangeCategory = "ExchangeInfoEventStartsAfter" + ExchangeInfoEventStartsBefore exchangeCategory = "ExchangeInfoEventStartsBefore" + ExchangeInfoEventSubject exchangeCategory = "ExchangeInfoEventSubject" ) // exchangeLeafProperties describes common metadata of the leaf categories @@ -535,22 +534,22 @@ func (ec exchangeCategory) String() string { // leafCat returns the leaf category of the receiver. // If the receiver category has multiple leaves (ex: User) or no leaves, // (ex: Unknown), the receiver itself is returned. -// If the receiver category is a filter type (ex: ExchangeFilterMailSubject), -// returns the category covered by the filter. +// If the receiver category is an info type (ex: ExchangeInfoMailSubject), +// returns the category covered by the info. // Ex: ExchangeContactFolder.leafCat() => ExchangeContact // Ex: ExchangeEvent.leafCat() => ExchangeEvent // Ex: ExchangeUser.leafCat() => ExchangeUser func (ec exchangeCategory) leafCat() categorizer { switch ec { - case ExchangeContact, ExchangeContactFolder, ExchangeFilterContactName: + case ExchangeContact, ExchangeContactFolder, ExchangeInfoContactName: return ExchangeContact - case ExchangeEvent, ExchangeEventCalendar, ExchangeFilterEventOrganizer, ExchangeFilterEventRecurs, - ExchangeFilterEventStartsAfter, ExchangeFilterEventStartsBefore, ExchangeFilterEventSubject: + case ExchangeEvent, ExchangeEventCalendar, ExchangeInfoEventOrganizer, ExchangeInfoEventRecurs, + ExchangeInfoEventStartsAfter, ExchangeInfoEventStartsBefore, ExchangeInfoEventSubject: return ExchangeEvent - case ExchangeMail, ExchangeMailFolder, ExchangeFilterMailReceivedAfter, - ExchangeFilterMailReceivedBefore, ExchangeFilterMailSender, ExchangeFilterMailSubject: + case ExchangeMail, ExchangeMailFolder, ExchangeInfoMailReceivedAfter, + ExchangeInfoMailReceivedBefore, ExchangeInfoMailSender, ExchangeInfoMailSubject: return ExchangeMail } @@ -652,10 +651,10 @@ func (s ExchangeScope) Matches(cat exchangeCategory, target string) bool { return matches(s, cat, target) } -// FilterCategory returns the category enum of the scope filter. -// If the scope is not a filter type, returns ExchangeUnknownCategory. -func (s ExchangeScope) FilterCategory() exchangeCategory { - return exchangeCategory(getFilterCategory(s)) +// InfoCategory returns the category enum of the scope info. +// If the scope is not an info type, returns ExchangeUnknownCategory. +func (s ExchangeScope) InfoCategory() exchangeCategory { + return exchangeCategory(getInfoCategory(s)) } // IncludeCategory checks whether the scope includes a certain category of data. @@ -733,7 +732,7 @@ func (s exchange) Reduce( errs) } -// matchesInfo handles the standard behavior when comparing a scope and an ExchangeFilter +// matchesInfo handles the standard behavior when comparing a scope and an ExchangeInfo // returns true if the scope and info match for the provided category. func (s ExchangeScope) matchesInfo(dii details.ItemInfo) bool { info := dii.Exchange @@ -741,35 +740,35 @@ func (s ExchangeScope) matchesInfo(dii details.ItemInfo) bool { return false } - filterCat := s.FilterCategory() + infoCat := s.InfoCategory() cfpc := categoryFromItemType(info.ItemType) - if !typeAndCategoryMatches(filterCat, cfpc) { + if !typeAndCategoryMatches(infoCat, cfpc) { return false } i := "" - switch filterCat { - case ExchangeFilterContactName: + switch infoCat { + case ExchangeInfoContactName: i = info.ContactName - case ExchangeFilterEventOrganizer: + case ExchangeInfoEventOrganizer: i = info.Organizer - case ExchangeFilterEventRecurs: + case ExchangeInfoEventRecurs: i = strconv.FormatBool(info.EventRecurs) - case ExchangeFilterEventStartsAfter, ExchangeFilterEventStartsBefore: + case ExchangeInfoEventStartsAfter, ExchangeInfoEventStartsBefore: i = common.FormatTime(info.EventStart) - case ExchangeFilterEventSubject: + case ExchangeInfoEventSubject: i = info.Subject - case ExchangeFilterMailSender: + case ExchangeInfoMailSender: i = info.Sender - case ExchangeFilterMailSubject: + case ExchangeInfoMailSubject: i = info.Subject - case ExchangeFilterMailReceivedAfter, ExchangeFilterMailReceivedBefore: + case ExchangeInfoMailReceivedAfter, ExchangeInfoMailReceivedBefore: i = common.FormatTime(info.Received) } - return s.Matches(filterCat, i) + return s.Matches(infoCat, i) } // categoryFromItemType interprets the category represented by the ExchangeInfo diff --git a/src/pkg/selectors/exchange_test.go b/src/pkg/selectors/exchange_test.go index d58dff980..b9b95b253 100644 --- a/src/pkg/selectors/exchange_test.go +++ b/src/pkg/selectors/exchange_test.go @@ -1572,16 +1572,16 @@ func (suite *ExchangeSelectorSuite) TestCategory_PathType() { {ExchangeMail, path.EmailCategory}, {ExchangeMailFolder, path.EmailCategory}, {ExchangeUser, path.UnknownCategory}, - {ExchangeFilterMailSender, path.EmailCategory}, - {ExchangeFilterMailSubject, path.EmailCategory}, - {ExchangeFilterMailReceivedAfter, path.EmailCategory}, - {ExchangeFilterMailReceivedBefore, path.EmailCategory}, - {ExchangeFilterContactName, path.ContactsCategory}, - {ExchangeFilterEventOrganizer, path.EventsCategory}, - {ExchangeFilterEventRecurs, path.EventsCategory}, - {ExchangeFilterEventStartsAfter, path.EventsCategory}, - {ExchangeFilterEventStartsBefore, path.EventsCategory}, - {ExchangeFilterEventSubject, path.EventsCategory}, + {ExchangeInfoMailSender, path.EmailCategory}, + {ExchangeInfoMailSubject, path.EmailCategory}, + {ExchangeInfoMailReceivedAfter, path.EmailCategory}, + {ExchangeInfoMailReceivedBefore, path.EmailCategory}, + {ExchangeInfoContactName, path.ContactsCategory}, + {ExchangeInfoEventOrganizer, path.EventsCategory}, + {ExchangeInfoEventRecurs, path.EventsCategory}, + {ExchangeInfoEventStartsAfter, path.EventsCategory}, + {ExchangeInfoEventStartsBefore, path.EventsCategory}, + {ExchangeInfoEventSubject, path.EventsCategory}, } for _, test := range table { suite.T().Run(test.cat.String(), func(t *testing.T) { diff --git a/src/pkg/selectors/helpers_test.go b/src/pkg/selectors/helpers_test.go index 3b5be9517..39add6fb9 100644 --- a/src/pkg/selectors/helpers_test.go +++ b/src/pkg/selectors/helpers_test.go @@ -139,7 +139,7 @@ func stubScope(match string) mockScope { func stubInfoScope(match string) mockScope { sc := stubScope(match) - sc[scopeKeyInfoFilter] = filters.Identity("true") + sc[scopeKeyInfoCategory] = filters.Identity("true") return sc } diff --git a/src/pkg/selectors/onedrive.go b/src/pkg/selectors/onedrive.go index e7d4c590a..fd7e2e680 100644 --- a/src/pkg/selectors/onedrive.go +++ b/src/pkg/selectors/onedrive.go @@ -239,57 +239,57 @@ func (s *oneDrive) Items(folders, items []string, opts ...option) []OneDriveScop // ------------------- // Filter Factories -// CreatedAfter produces a OneDrive item created-after filter scope. +// CreatedAfter produces a OneDrive item created-after info scope. // Matches any item where the created time is after the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (s *oneDrive) CreatedAfter(timeStrings string) []OneDriveScope { return []OneDriveScope{ - makeFilterScope[OneDriveScope]( + makeInfoScope[OneDriveScope]( OneDriveItem, - FileFilterCreatedAfter, + FileInfoCreatedAfter, []string{timeStrings}, wrapFilter(filters.Less)), } } -// CreatedBefore produces a OneDrive item created-before filter scope. +// CreatedBefore produces a OneDrive item created-before info scope. // Matches any item where the created time is before the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (s *oneDrive) CreatedBefore(timeStrings string) []OneDriveScope { return []OneDriveScope{ - makeFilterScope[OneDriveScope]( + makeInfoScope[OneDriveScope]( OneDriveItem, - FileFilterCreatedBefore, + FileInfoCreatedBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } } -// ModifiedAfter produces a OneDrive item modified-after filter scope. +// ModifiedAfter produces a OneDrive item modified-after info scope. // Matches any item where the modified time is after the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (s *oneDrive) ModifiedAfter(timeStrings string) []OneDriveScope { return []OneDriveScope{ - makeFilterScope[OneDriveScope]( + makeInfoScope[OneDriveScope]( OneDriveItem, - FileFilterModifiedAfter, + FileInfoModifiedAfter, []string{timeStrings}, wrapFilter(filters.Less)), } } -// ModifiedBefore produces a OneDrive item modified-before filter scope. +// ModifiedBefore produces a OneDrive item modified-before info scope. // Matches any item where the modified time is before the timestring. // If the input equals selectors.Any, the scope will match all times. // If the input is empty or selectors.None, the scope will always fail comparisons. func (s *oneDrive) ModifiedBefore(timeStrings string) []OneDriveScope { return []OneDriveScope{ - makeFilterScope[OneDriveScope]( + makeInfoScope[OneDriveScope]( OneDriveItem, - FileFilterModifiedBefore, + FileInfoModifiedBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } @@ -308,16 +308,17 @@ var _ categorizer = OneDriveCategoryUnknown const ( OneDriveCategoryUnknown oneDriveCategory = "" - // types of data identified by OneDrive + + // types of data in OneDrive OneDriveUser oneDriveCategory = "OneDriveUser" OneDriveItem oneDriveCategory = "OneDriveItem" OneDriveFolder oneDriveCategory = "OneDriveFolder" - // filterable topics identified by OneDrive - FileFilterCreatedAfter oneDriveCategory = "FileFilterCreatedAfter" - FileFilterCreatedBefore oneDriveCategory = "FileFilterCreatedBefore" - FileFilterModifiedAfter oneDriveCategory = "FileFilterModifiedAfter" - FileFilterModifiedBefore oneDriveCategory = "FileFilterModifiedBefore" + // details.ItemInfo comparables + FileInfoCreatedAfter oneDriveCategory = "FileInfoCreatedAfter" + FileInfoCreatedBefore oneDriveCategory = "FileInfoCreatedBefore" + FileInfoModifiedAfter oneDriveCategory = "FileInfoModifiedAfter" + FileInfoModifiedBefore oneDriveCategory = "FileInfoModifiedBefore" ) // oneDriveLeafProperties describes common metadata of the leaf categories @@ -344,8 +345,8 @@ func (c oneDriveCategory) String() string { func (c oneDriveCategory) leafCat() categorizer { switch c { case OneDriveFolder, OneDriveItem, - FileFilterCreatedAfter, FileFilterCreatedBefore, - FileFilterModifiedAfter, FileFilterModifiedBefore: + FileInfoCreatedAfter, FileInfoCreatedBefore, + FileInfoModifiedAfter, FileInfoModifiedBefore: return OneDriveItem } @@ -433,10 +434,10 @@ func (s OneDriveScope) categorizer() categorizer { return s.Category() } -// FilterCategory returns the category enum of the scope filter. -// If the scope is not a filter type, returns OneDriveUnknownCategory. -func (s OneDriveScope) FilterCategory() oneDriveCategory { - return oneDriveCategory(getFilterCategory(s)) +// InfoCategory returns the category enum of the scope info. +// If the scope is not an info type, returns OneDriveUnknownCategory. +func (s OneDriveScope) InfoCategory() oneDriveCategory { + return oneDriveCategory(getInfoCategory(s)) } // IncludeCategory checks whether the scope includes a @@ -522,16 +523,16 @@ func (s OneDriveScope) matchesInfo(dii details.ItemInfo) bool { return false } - filterCat := s.FilterCategory() + infoCat := s.InfoCategory() i := "" - switch filterCat { - case FileFilterCreatedAfter, FileFilterCreatedBefore: + switch infoCat { + case FileInfoCreatedAfter, FileInfoCreatedBefore: i = common.FormatTime(info.Created) - case FileFilterModifiedAfter, FileFilterModifiedBefore: + case FileInfoModifiedAfter, FileInfoModifiedBefore: i = common.FormatTime(info.Modified) } - return s.Matches(filterCat, i) + return s.Matches(infoCat, i) } diff --git a/src/pkg/selectors/onedrive_test.go b/src/pkg/selectors/onedrive_test.go index a1c25bf8c..a0f188886 100644 --- a/src/pkg/selectors/onedrive_test.go +++ b/src/pkg/selectors/onedrive_test.go @@ -63,7 +63,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveSelector_AllData() { }{ {"Include Scopes", sel.Includes}, {"Exclude Scopes", sel.Excludes}, - {"Filter Scopes", sel.Filters}, + {"info scopes", sel.Filters}, } for _, test := range table { suite.Run(test.name, func() { @@ -348,10 +348,10 @@ func (suite *OneDriveSelectorSuite) TestCategory_PathType() { {OneDriveUser, path.UnknownCategory}, {OneDriveItem, path.FilesCategory}, {OneDriveFolder, path.FilesCategory}, - {FileFilterCreatedAfter, path.FilesCategory}, - {FileFilterCreatedBefore, path.FilesCategory}, - {FileFilterModifiedAfter, path.FilesCategory}, - {FileFilterModifiedBefore, path.FilesCategory}, + {FileInfoCreatedAfter, path.FilesCategory}, + {FileInfoCreatedBefore, path.FilesCategory}, + {FileInfoModifiedAfter, path.FilesCategory}, + {FileInfoModifiedBefore, path.FilesCategory}, } for _, test := range table { suite.T().Run(test.cat.String(), func(t *testing.T) { diff --git a/src/pkg/selectors/scopes.go b/src/pkg/selectors/scopes.go index 44166c4ce..8739924fa 100644 --- a/src/pkg/selectors/scopes.go +++ b/src/pkg/selectors/scopes.go @@ -140,7 +140,7 @@ type ( categorizer() categorizer // matchesInfo is used to determine if the scope values match a specific DetailsEntry - // ItemInfo filter. Unlike path filtering, the entry comparison requires service-specific + // ItemInfo value. Unlike path comparison, the entry comparison requires service-specific // context in order for the scope to extract the correct serviceInfo in the entry. // // Params: @@ -178,18 +178,18 @@ func makeScope[T scopeT]( return s } -// makeFilterScope produces a well formatted, typed scope, with properties specifically oriented +// makeInfoScope produces a well formatted, typed scope, with properties specifically oriented // towards identifying filter-type scopes, that ensures all base values are populated. -func makeFilterScope[T scopeT]( - cat, filterCat categorizer, +func makeInfoScope[T scopeT]( + cat, infoCat categorizer, vs []string, f func([]string) filters.Filter, ) T { return T{ - scopeKeyCategory: filters.Identity(cat.String()), - scopeKeyDataType: filters.Identity(cat.leafCat().String()), - scopeKeyInfoFilter: filters.Identity(filterCat.String()), - filterCat.String(): f(clean(vs)), + scopeKeyCategory: filters.Identity(cat.String()), + scopeKeyDataType: filters.Identity(cat.leafCat().String()), + scopeKeyInfoCategory: filters.Identity(infoCat.String()), + infoCat.String(): f(clean(vs)), } } @@ -227,14 +227,14 @@ func matchesAny[T scopeT, C categoryT](s T, cat C, inpts []string) bool { } // getCategory returns the scope's category value. -// if s is a filter-type scope, returns the filter category. +// if s is an info-type scope, returns the info category. func getCategory[T scopeT](s T) string { return s[scopeKeyCategory].Target } -// getFilterCategory returns the scope's infoFilter category value. -func getFilterCategory[T scopeT](s T) string { - return s[scopeKeyInfoFilter].Target +// getInfoCategory returns the scope's infoFilter category value. +func getInfoCategory[T scopeT](s T) string { + return s[scopeKeyInfoCategory].Target } // getCatValue takes the value of s[cat], split it by the standard @@ -456,8 +456,8 @@ func matchesEntry[T scopeT, C categoryT]( pathValues map[categorizer][]string, entry details.DetailsEntry, ) bool { - // filterCategory requires matching against service-specific info values - if len(getFilterCategory(sc)) > 0 { + // InfoCategory requires matching against service-specific info values + if len(getInfoCategory(sc)) > 0 { return sc.matchesInfo(entry.ItemInfo) } diff --git a/src/pkg/selectors/selectors.go b/src/pkg/selectors/selectors.go index 21be47d37..692491b08 100644 --- a/src/pkg/selectors/selectors.go +++ b/src/pkg/selectors/selectors.go @@ -38,9 +38,9 @@ var ( ) const ( - scopeKeyCategory = "category" - scopeKeyInfoFilter = "info_filter" - scopeKeyDataType = "type" + scopeKeyCategory = "category" + scopeKeyInfoCategory = "details_info_category" + scopeKeyDataType = "type" ) // The granularity exprerssed by the scope. Groups imply non-item granularity, @@ -116,7 +116,7 @@ type Selector struct { // A slice of exclusion scopes. Exclusions apply globally to all // inclusions/filters, with any-match behavior. Excludes []scope `json:"exclusions,omitempty"` - // A slice of filter scopes. All inclusions must also match ALL filters. + // A slice of info scopes. All inclusions must also match ALL filters. Filters []scope `json:"filters,omitempty"` // A slice of inclusion scopes. Comparators must match either one of these, // or all filters, to be included. diff --git a/src/pkg/selectors/sharepoint.go b/src/pkg/selectors/sharepoint.go index 143fd39e2..d9b634bbb 100644 --- a/src/pkg/selectors/sharepoint.go +++ b/src/pkg/selectors/sharepoint.go @@ -197,17 +197,17 @@ func (s *SharePointRestore) WebURL(urlSuffixes []string, opts ...option) []Share scopes = append( scopes, - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, SharePointWebURL, urlSuffixes, pathFilterFactory(opts...)), - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointListItem, SharePointWebURL, urlSuffixes, pathFilterFactory(opts...)), - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointPage, SharePointWebURL, urlSuffixes, @@ -276,9 +276,9 @@ func (s *sharePoint) ListItems(lists, items []string, opts ...option) []SharePoi // If any slice is empty, it defaults to [selectors.None] func (s *sharePoint) Library(library string) []SharePointScope { return []SharePointScope{ - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, - SharePointFilterLibraryDrive, + SharePointInfoLibraryDrive, []string{library}, wrapFilter(filters.Equal)), } @@ -352,13 +352,13 @@ func (s *sharePoint) PageItems(pages, items []string, opts ...option) []SharePoi } // ------------------- -// Filter Factories +// ItemInfo Factories func (s *sharePoint) CreatedAfter(timeStrings string) []SharePointScope { return []SharePointScope{ - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, - SharePointFilterCreatedAfter, + SharePointInfoCreatedAfter, []string{timeStrings}, wrapFilter(filters.Less)), } @@ -366,9 +366,9 @@ func (s *sharePoint) CreatedAfter(timeStrings string) []SharePointScope { func (s *sharePoint) CreatedBefore(timeStrings string) []SharePointScope { return []SharePointScope{ - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, - SharePointFilterCreatedBefore, + SharePointInfoCreatedBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } @@ -376,9 +376,9 @@ func (s *sharePoint) CreatedBefore(timeStrings string) []SharePointScope { func (s *sharePoint) ModifiedAfter(timeStrings string) []SharePointScope { return []SharePointScope{ - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, - SharePointFilterModifiedAfter, + SharePointInfoModifiedAfter, []string{timeStrings}, wrapFilter(filters.Less)), } @@ -386,9 +386,9 @@ func (s *sharePoint) ModifiedAfter(timeStrings string) []SharePointScope { func (s *sharePoint) ModifiedBefore(timeStrings string) []SharePointScope { return []SharePointScope{ - makeFilterScope[SharePointScope]( + makeInfoScope[SharePointScope]( SharePointLibraryItem, - SharePointFilterModifiedBefore, + SharePointInfoModifiedBefore, []string{timeStrings}, wrapFilter(filters.Greater)), } @@ -408,7 +408,7 @@ var _ categorizer = SharePointCategoryUnknown const ( SharePointCategoryUnknown sharePointCategory = "" - // types of data identified by SharePoint + // types of data in SharePoint SharePointWebURL sharePointCategory = "SharePointWebURL" SharePointSite sharePointCategory = "SharePointSite" SharePointList sharePointCategory = "SharePointList" @@ -418,14 +418,14 @@ const ( SharePointPageFolder sharePointCategory = "SharePointPageFolder" SharePointPage sharePointCategory = "SharePointPage" - // filterable topics identified by SharePoint - SharePointFilterCreatedAfter sharePointCategory = "SharePointFilterCreatedAfter" - SharePointFilterCreatedBefore sharePointCategory = "SharePointFilterCreatedBefore" - SharePointFilterModifiedAfter sharePointCategory = "SharePointFilterModifiedAfter" - SharePointFilterModifiedBefore sharePointCategory = "SharePointFilterModifiedBefore" + // details.itemInfo comparables + SharePointInfoCreatedAfter sharePointCategory = "SharePointInfoCreatedAfter" + SharePointInfoCreatedBefore sharePointCategory = "SharePointInfoCreatedBefore" + SharePointInfoModifiedAfter sharePointCategory = "SharePointInfoModifiedAfter" + SharePointInfoModifiedBefore sharePointCategory = "SharePointInfoModifiedBefore" // library drive selection - SharePointFilterLibraryDrive sharePointCategory = "SharePointFilterLibraryDrive" + SharePointInfoLibraryDrive sharePointCategory = "SharePointInfoLibraryDrive" ) // sharePointLeafProperties describes common metadata of the leaf categories @@ -459,9 +459,9 @@ func (c sharePointCategory) String() string { // Ex: ServiceUser.leafCat() => ServiceUser func (c sharePointCategory) leafCat() categorizer { switch c { - case SharePointLibraryFolder, SharePointLibraryItem, SharePointFilterLibraryDrive, - SharePointFilterCreatedAfter, SharePointFilterCreatedBefore, - SharePointFilterModifiedAfter, SharePointFilterModifiedBefore: + case SharePointLibraryFolder, SharePointLibraryItem, SharePointInfoLibraryDrive, + SharePointInfoCreatedAfter, SharePointInfoCreatedBefore, + SharePointInfoModifiedAfter, SharePointInfoModifiedBefore: return SharePointLibraryItem case SharePointList, SharePointListItem: return SharePointListItem @@ -576,10 +576,10 @@ func (s SharePointScope) Matches(cat sharePointCategory, target string) bool { return matches(s, cat, target) } -// FilterCategory returns the category enum of the scope filter. -// If the scope is not a filter type, returns SharePointUnknownCategory. -func (s SharePointScope) FilterCategory() sharePointCategory { - return sharePointCategory(getFilterCategory(s)) +// InfoCategory returns the category enum of the scope info. +// If the scope is not an info type, returns SharePointUnknownCategory. +func (s SharePointScope) InfoCategory() sharePointCategory { + return sharePointCategory(getInfoCategory(s)) } // IncludeCategory checks whether the scope includes a @@ -667,23 +667,23 @@ func (s sharePoint) Reduce( // returns true if the scope and info match for the provided category. func (s SharePointScope) matchesInfo(dii details.ItemInfo) bool { var ( - filterCat = s.FilterCategory() - i = "" - info = dii.SharePoint + infoCat = s.InfoCategory() + i = "" + info = dii.SharePoint ) if info == nil { return false } - switch filterCat { + switch infoCat { case SharePointWebURL: i = info.WebURL - case SharePointFilterCreatedAfter, SharePointFilterCreatedBefore: + case SharePointInfoCreatedAfter, SharePointInfoCreatedBefore: i = common.FormatTime(info.Created) - case SharePointFilterModifiedAfter, SharePointFilterModifiedBefore: + case SharePointInfoModifiedAfter, SharePointInfoModifiedBefore: i = common.FormatTime(info.Modified) - case SharePointFilterLibraryDrive: + case SharePointInfoLibraryDrive: ds := []string{} if len(info.DriveName) > 0 { @@ -694,8 +694,8 @@ func (s SharePointScope) matchesInfo(dii details.ItemInfo) bool { ds = append(ds, info.DriveID) } - return matchesAny(s, SharePointFilterLibraryDrive, ds) + return matchesAny(s, SharePointInfoLibraryDrive, ds) } - return s.Matches(filterCat, i) + return s.Matches(infoCat, i) } diff --git a/src/pkg/selectors/sharepoint_test.go b/src/pkg/selectors/sharepoint_test.go index cdae179cd..8624c40a1 100644 --- a/src/pkg/selectors/sharepoint_test.go +++ b/src/pkg/selectors/sharepoint_test.go @@ -62,7 +62,7 @@ func (suite *SharePointSelectorSuite) TestSharePointSelector_AllData() { }{ {"Include Scopes", sel.Includes}, {"Exclude Scopes", sel.Excludes}, - {"Filter Scopes", sel.Filters}, + {"info scopes", sel.Filters}, } for _, test := range table { require.Len(t, test.scopesToCheck, 3)