From 77d6557eee975e96f52d731020def03c4d6ef117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Gro=C3=9Fmann?= Date: Wed, 27 Aug 2025 15:29:42 +0200 Subject: [PATCH] feat: any ID also is a pattern that matches exactly any other equal ID --- x/secrets/identifiers.go | 16 ++++++---------- x/secrets/identifiers_test.go | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/x/secrets/identifiers.go b/x/secrets/identifiers.go index b15ca3db..c19df4e0 100644 --- a/x/secrets/identifiers.go +++ b/x/secrets/identifiers.go @@ -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 { diff --git a/x/secrets/identifiers_test.go b/x/secrets/identifiers_test.go index 7924eb15..f43cfb74 100644 --- a/x/secrets/identifiers_test.go +++ b/x/secrets/identifiers_test.go @@ -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) } }) }