pairMatcher returns a SecretMatcher for matching against key/value pairs
()
| 125 | |
| 126 | // pairMatcher returns a SecretMatcher for matching against key/value pairs |
| 127 | func (u *UserPattern) pairMatcher() SecretMatcher { |
| 128 | return SecretMatcher{"(pair) @matches", func(n *Node) *Secret { |
| 129 | |
| 130 | key := n.ChildByFieldName("key") |
| 131 | if key == nil || !u.MatchKey(key.RawString()) { |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | value := n.ChildByFieldName("value") |
| 136 | if value == nil || value.Type() != "string" { |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | if !u.MatchValue(value.RawString()) { |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | secret := &Secret{ |
| 145 | Kind: u.Name, |
| 146 | Data: map[string]string{ |
| 147 | "key": key.RawString(), |
| 148 | "value": value.RawString(), |
| 149 | }, |
| 150 | Severity: u.Severity, |
| 151 | } |
| 152 | |
| 153 | parent := n.Parent() |
| 154 | if parent == nil || parent.Type() != "object" { |
| 155 | return secret |
| 156 | } |
| 157 | |
| 158 | secret.Context = parent.AsObject().AsMap() |
| 159 | |
| 160 | return secret |
| 161 | |
| 162 | }} |
| 163 | } |
| 164 | |
| 165 | // stringMatcher returns a SecretMatcher for matching against string literals |
| 166 | func (u *UserPattern) stringMatcher() SecretMatcher { |
no test coverage detected