mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
vendor: github.com/moby/buildkit v0.12.1-0.20230717122532-faa0cc7da353
full diff: - https://github.com/moby/buildkit/compare/20230620112432...v0.12.0 - https://github.com/moby/buildkit/compare/v0.12.0...faa0cc7da3536923d85b74b2bb2d13c12a6ecc99 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
58
vendor/github.com/moby/buildkit/sourcepolicy/matcher.go
generated
vendored
Normal file
58
vendor/github.com/moby/buildkit/sourcepolicy/matcher.go
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
package sourcepolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
|
||||
spb "github.com/moby/buildkit/sourcepolicy/pb"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func match(ctx context.Context, src *selectorCache, ref string, attrs map[string]string) (bool, error) {
|
||||
for _, c := range src.Constraints {
|
||||
switch c.Condition {
|
||||
case spb.AttrMatch_EQUAL:
|
||||
if attrs[c.Key] != c.Value {
|
||||
return false, nil
|
||||
}
|
||||
case spb.AttrMatch_NOTEQUAL:
|
||||
if attrs[c.Key] == c.Value {
|
||||
return false, nil
|
||||
}
|
||||
case spb.AttrMatch_MATCHES:
|
||||
// TODO: Cache the compiled regex
|
||||
matches, err := regexp.MatchString(c.Value, attrs[c.Key])
|
||||
if err != nil {
|
||||
return false, errors.Errorf("invalid regex %q: %v", c.Value, err)
|
||||
}
|
||||
if !matches {
|
||||
return false, nil
|
||||
}
|
||||
default:
|
||||
return false, errors.Errorf("unknown attr condition: %s", c.Condition)
|
||||
}
|
||||
}
|
||||
|
||||
if src.Identifier == ref {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
switch src.MatchType {
|
||||
case spb.MatchType_EXACT:
|
||||
return false, nil
|
||||
case spb.MatchType_REGEX:
|
||||
re, err := src.regex()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return re.MatchString(ref), nil
|
||||
case spb.MatchType_WILDCARD:
|
||||
w, err := src.wildcard()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return w.Match(ref) != nil, nil
|
||||
default:
|
||||
return false, errors.Errorf("unknown match type: %s", src.MatchType)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user