stringMatcher returns a SecretMatcher for matching against string literals
()
| 164 | |
| 165 | // stringMatcher returns a SecretMatcher for matching against string literals |
| 166 | func (u *UserPattern) stringMatcher() SecretMatcher { |
| 167 | return SecretMatcher{"(string) @matches", func(n *Node) *Secret { |
| 168 | in := n.RawString() |
| 169 | if !u.MatchValue(in) { |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | secret := &Secret{ |
| 174 | Kind: u.Name, |
| 175 | Data: map[string]string{"match": in}, |
| 176 | Severity: u.Severity, |
| 177 | } |
| 178 | |
| 179 | parent := n.Parent() |
| 180 | if parent == nil || parent.Type() != "pair" { |
| 181 | return secret |
| 182 | } |
| 183 | |
| 184 | grandParent := parent.Parent() |
| 185 | if grandParent == nil || grandParent.Type() != "object" { |
| 186 | return secret |
| 187 | } |
| 188 | |
| 189 | secret.Context = grandParent.AsObject().AsMap() |
| 190 | |
| 191 | return secret |
| 192 | }} |
| 193 | } |
| 194 | |
| 195 | // UserPatterns is an alias for a slice of *UserPattern |
| 196 | type UserPatterns []*UserPattern |
no test coverage detected