engine, lang: core: Match exported resources properly

I inverted the logic for complex setups and forgot to handle the zero
cases. I also didn't notice my loop continue error. This cleans all this
up so that we can have proper exported resource matching.
This commit is contained in:
James Shubin
2025-05-08 22:29:03 -04:00
parent ad0dd44130
commit fddebb2474
3 changed files with 25 additions and 5 deletions

View File

@@ -181,6 +181,19 @@ func (obj *ResFilter) Match(kind, name, host string) error {
return nil // match!
}
// MatchFilters is a simple helper function to avoid duplicating this loop here.
// If any filter matches, it returns nil. Otherwise we error.
func MatchFilters(filters []*ResFilter, kind, name, host string) error {
// TODO: I'd love to avoid this O(N^2) matching if possible...
for _, filter := range filters {
if err := filter.Match(kind, name, host); err == nil {
return nil
}
}
return fmt.Errorf("not matches found") // did not match
}
// ResOutput represents a record of exported resource data which we have read
// out from the world storage system. The Data field contains an encoded version
// of the resource, and even though decoding it will get you a Kind and Name, we