Skip to content

Commit

Permalink
xds: add RBAC Engine (#4471)
Browse files Browse the repository at this point in the history
* Added RBAC Engine
  • Loading branch information
zasweq committed May 26, 2021
1 parent 194dcc9 commit 34bd6fb
Show file tree
Hide file tree
Showing 4 changed files with 1,103 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/xds/matcher/matcher_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ func (hsm *HeaderSuffixMatcher) String() string {
return fmt.Sprintf("headerSuffix:%v:%v", hsm.key, hsm.suffix)
}

// HeaderContainsMatcher matches on whether the header value contains the
// value passed into this struct.
type HeaderContainsMatcher struct {
key string
contains string
}

// NewHeaderContainsMatcher returns a new HeaderContainsMatcher. key is the HTTP
// Header key to match on, and contains is the value that the header should
// should contain for a successful match. An empty contains string does not
// work, use HeaderPresentMatcher in that case.
func NewHeaderContainsMatcher(key string, contains string) *HeaderContainsMatcher {
return &HeaderContainsMatcher{key: key, contains: contains}
}

// Match returns whether the passed in HTTP Headers match according to the
// HeaderContainsMatcher.
func (hcm *HeaderContainsMatcher) Match(md metadata.MD) bool {
v, ok := mdValuesFromOutgoingCtx(md, hcm.key)
if !ok {
return false
}
return strings.Contains(v, hcm.contains)
}

func (hcm *HeaderContainsMatcher) String() string {
return fmt.Sprintf("headerContains:%v%v", hcm.key, hcm.contains)
}

// InvertMatcher inverts the match result of the underlying header matcher.
type InvertMatcher struct {
m HeaderMatcherInterface
Expand Down

0 comments on commit 34bd6fb

Please sign in to comment.