From 7693b3a5d4895c407347284ad635d91a06d51954 Mon Sep 17 00:00:00 2001 From: ryanfkeepers Date: Mon, 10 Apr 2023 13:00:03 -0600 Subject: [PATCH] comment cleanup --- src/internal/connector/graph_connector.go | 8 +++++--- src/pkg/filters/filters.go | 11 +++++------ src/pkg/filters/filters_test.go | 6 ++---- src/pkg/selectors/scopes.go | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 6ad563d14..c076ee5b0 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -236,8 +236,10 @@ type getOwnerIDAndNamer interface { // (PrincipalName for users, WebURL for sites). // // Consumers are allowed to pass in a path suffix (eg: /sites/foo) as a site -// owner, but only if they also pass in a nameToID map. A nil map will cascade -// to the fallback, which will fail for having a malformed id value. +// owner, but only if they also pass in a nameToID map. A nil map will fallback +// to a lookup by id using the suffix, which will fail for being malformed. +// Suffix matching follows filter PathSuffix rules: only complete elements match, +// case-independant, leading/tailing slashes are optional. func (r resourceClient) getOwnerIDAndNameFrom( ctx context.Context, discovery api.Client, @@ -261,7 +263,7 @@ func (r resourceClient) getOwnerIDAndNameFrom( // check if the provided owner is a suffix of a weburl in the lookup map if r.enum == Sites { - url, _, ok := filters.PathSuffix([]string{owner}).CompareAny(ins.Names()...) + url, ok := filters.PathSuffix([]string{owner}).CompareAny(ins.Names()...) if ok { id, _ := ins.IDOf(url) return id, url, nil diff --git a/src/pkg/filters/filters.go b/src/pkg/filters/filters.go index 36a8fd106..c5a9fa6fa 100644 --- a/src/pkg/filters/filters.go +++ b/src/pkg/filters/filters.go @@ -360,22 +360,21 @@ func newSliceFilter(c comparator, targets, normTargets []string, negate bool) Fi // CompareAny checks whether any one of all the provided // inputs passes the filter. If one passes, that value is -// returned, as well as its index in the input range. -// If nothing matches, returns ("", -1, false) +// returned. If nothing matches, returns ("", false) // // Note that, as a gotcha, CompareAny can resolve truthily // for both the standard and negated versions of a filter. // Ex: consider the input CompareAny(true, false), which // will return true for both Equals(true) and NotEquals(true), // because at least one element matches for both filters. -func (f Filter) CompareAny(inputs ...string) (string, int, bool) { - for i, in := range inputs { +func (f Filter) CompareAny(inputs ...string) (string, bool) { + for _, in := range inputs { if f.Compare(in) { - return in, i, true + return in, true } } - return "", -1, false + return "", false } // Compare checks whether the input passes the filter. diff --git a/src/pkg/filters/filters_test.go b/src/pkg/filters/filters_test.go index fdb691016..c94678ce5 100644 --- a/src/pkg/filters/filters_test.go +++ b/src/pkg/filters/filters_test.go @@ -79,14 +79,12 @@ func (suite *FiltersSuite) TestEquals_any() { suite.Run(test.name, func() { t := suite.T() - v, i, b := f.CompareAny(test.input...) + v, b := f.CompareAny(test.input...) test.expectF(t, b, "filter") - assert.Equal(t, test.expectFIdx, i, "index") assert.Equal(t, test.expectFVal, v, "value") - v, i, b = nf.CompareAny(test.input...) + v, b = nf.CompareAny(test.input...) test.expectNF(t, b, "neg-filter") - assert.Equal(t, test.expectNFIdx, i, "neg-index") assert.Equal(t, test.expectNFVal, v, "neg-value") }) } diff --git a/src/pkg/selectors/scopes.go b/src/pkg/selectors/scopes.go index 3446c4463..df438297e 100644 --- a/src/pkg/selectors/scopes.go +++ b/src/pkg/selectors/scopes.go @@ -223,7 +223,7 @@ func matchesAny[T scopeT, C categoryT](s T, cat C, inpts []string) bool { return false } - _, _, pass := s[cat.String()].CompareAny(inpts...) + _, pass := s[cat.String()].CompareAny(inpts...) return pass }