From 6b6821b84aeae0b6c7fe2a4bf1a1504a139b1645 Mon Sep 17 00:00:00 2001 From: Tom Hudson Date: Wed, 14 Dec 2022 14:50:51 +0000 Subject: [PATCH] Switches context to Secret struct instead of in Secret.Data --- secret-aws.go | 7 +++---- secret-gcp.go | 6 ++---- secret-github.go | 6 ++---- secret-matchers.go | 15 +++++++-------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/secret-aws.go b/secret-aws.go index 2822a5e..d587c05 100644 --- a/secret-aws.go +++ b/secret-aws.go @@ -35,9 +35,8 @@ func awsMatcher() SecretMatcher { } data := struct { - Key string `json:"key"` - Secret string `json:"secret,omitempty"` - Context map[string]string `json:"context,omitempty"` + Key string `json:"key"` + Secret string `json:"secret,omitempty"` }{ Key: str, } @@ -62,7 +61,6 @@ func awsMatcher() SecretMatcher { } o := grandparent.AsObject() - data.Context = o.asMap() for _, k := range o.getKeys() { k = strings.ToLower(k) @@ -78,6 +76,7 @@ func awsMatcher() SecretMatcher { Kind: "AWSAccessKey", LeadWorthy: data.Secret != "", Data: data, + Context: o.asMap(), } }} diff --git a/secret-gcp.go b/secret-gcp.go index d8b5be5..8553e0d 100644 --- a/secret-gcp.go +++ b/secret-gcp.go @@ -22,8 +22,7 @@ func gcpKeyMatcher() SecretMatcher { } data := struct { - Key string `json:"key"` - Context map[string]string `json:"context,omitempty"` + Key string `json:"key"` }{ Key: str, } @@ -45,8 +44,7 @@ func gcpKeyMatcher() SecretMatcher { return match } - data.Context = grandparent.AsObject().asMap() - match.Data = data + match.Context = grandparent.AsObject().asMap() return match }} diff --git a/secret-github.go b/secret-github.go index f43fd7e..16248aa 100644 --- a/secret-github.go +++ b/secret-github.go @@ -15,8 +15,7 @@ func githubKeyMatcher() SecretMatcher { } data := struct { - Key string `json:"key"` - Context map[string]string `json:"context,omitempty"` + Key string `json:"key"` }{ Key: str, } @@ -38,8 +37,7 @@ func githubKeyMatcher() SecretMatcher { return match } - data.Context = grandparent.AsObject().asMap() - match.Data = data + match.Context = grandparent.AsObject().asMap() return match }} diff --git a/secret-matchers.go b/secret-matchers.go index 40334de..8882e79 100644 --- a/secret-matchers.go +++ b/secret-matchers.go @@ -8,10 +8,11 @@ import ( // data found within a JavaScript file. E.g. an AWS access key and // secret. type Secret struct { - Kind string `json:"kind"` - Data any `json:"data"` - Filename string `json:"filename,omitempty"` - LeadWorthy bool `json:"leadWorthy"` + Kind string `json:"kind"` + Data any `json:"data"` + Filename string `json:"filename,omitempty"` + LeadWorthy bool `json:"leadWorthy"` + Context map[string]string `json:"context"` } // GetSecrets uses the parse tree and a set of Matchers (those provided @@ -113,8 +114,7 @@ func AllSecretMatchers() []SecretMatcher { } data := struct { - Key string `json:"key"` - Context map[string]string `json:"context,omitempty"` + Key string `json:"key"` }{ Key: value.RawString(), } @@ -129,8 +129,7 @@ func AllSecretMatchers() []SecretMatcher { return match } - data.Context = parent.AsObject().asMap() - match.Data = data + match.Context = parent.AsObject().asMap() return match }},