Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions x/secrets/identifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,20 @@ func valid(id string) error {
// For storage, we don't really differentiate much about the ID format but
// by convention we do simple, slash-separated management, providing a
// groupable access control system for management across plugins.
// Any ID also is a Pattern that matches exactly any other equal ID.
type ID interface {
// String formats the [IDNew] as a string
String() string
// Match the [IDNew] against a [PatternNew]
// It checks if a given identifier matches the pattern.
// - "*" matches a single component
// - "**" matches zero or more components
// - "/" is the separator
Match(pattern Pattern) bool
}

type id string

func (i id) Match(pattern Pattern) bool {
pathParts := split(string(i))
patternParts := split(pattern.String())
func (i id) Match(id ID) bool {
return id == i
}

return match(patternParts, pathParts)
func (i id) Includes(other Pattern) bool {
return i.String() == other.String()
}

func (i id) String() string {
Expand Down
2 changes: 1 addition & 1 deletion x/secrets/identifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestMatchNew(t *testing.T) {
assert.NoError(t, err)
pattern, err := ParsePattern(tc.pattern)
assert.NoError(t, err)
assert.Equalf(t, tc.expected, id.Match(pattern), "unexpected match for id `%q` to and pattern `%q`", m, tc.pattern)
assert.Equalf(t, tc.expected, pattern.Match(id), "unexpected match for id `%q` to and pattern `%q`", m, tc.pattern)
}
})
}
Expand Down
Loading