MCPcopy
hub / github.com/deepfence/SecretScanner / printColoredSecretJSONObject

Function printColoredSecretJSONObject

output/output.go:137–167  ·  view source on GitHub ↗

Function to print json object with the matches secret string in color

(secret SecretFound, isFirstSecret *bool)

Source from the content-addressed store, hash-verified

135
136// Function to print json object with the matches secret string in color
137func printColoredSecretJSONObject(secret SecretFound, isFirstSecret *bool) {
138 Indent3 := Indent + Indent + Indent
139
140 if *isFirstSecret {
141 fmt.Printf(Indent + Indent + "{\n")
142 } else {
143 fmt.Printf(",\n" + Indent + Indent + "{\n")
144 }
145
146 fmt.Printf(Indent3+"\"Image Layer ID\": %s,\n", jsonMarshal(secret.LayerID))
147 fmt.Printf(Indent3+"\"Matched Rule ID\": %d,\n", secret.RuleID)
148 fmt.Printf(Indent3+"\"Matched Rule Name\": %s,\n", jsonMarshal(secret.RuleName))
149 fmt.Printf(Indent3+"\"Matched Part\": %s,\n", jsonMarshal(secret.PartToMatch))
150 fmt.Printf(Indent3+"\"String to Match\": %s,\n", jsonMarshal(secret.Match))
151 fmt.Printf(Indent3+"\"Signature to Match\": %s,\n", jsonMarshal(secret.Regex))
152 fmt.Printf(Indent3+"\"Severity\": %s,\n", jsonMarshal(secret.Severity))
153 fmt.Printf(Indent3+"\"Severity Score\": %.2f,\n", secret.SeverityScore)
154 fmt.Printf(Indent3+"\"Starting Index of Match in Original Content\": %d,\n", secret.PrintBufferStartIndex)
155 fmt.Printf(Indent3+"\"Relative Starting Index of Match in Displayed Substring\": %d,\n", secret.MatchFromByte)
156 fmt.Printf(Indent3+"\"Relative Ending Index of Match in Displayed Substring\": %d,\n", secret.MatchToByte)
157 fmt.Printf(Indent3+"\"Full File Name\": %s,\n", jsonMarshal(secret.CompleteFilename))
158 match := secret.MatchedContents
159 from := secret.MatchFromByte
160 to := secret.MatchToByte
161 prefix := removeFirstLastChar(jsonMarshal(match[0:from]))
162 coloredMatch := color.RedString(removeFirstLastChar(jsonMarshal(string(match[from:to]))))
163 suffix := removeFirstLastChar(jsonMarshal(match[to:]))
164 fmt.Printf(Indent3+"\"Matched Contents\": \"%s%s%s\"\n", prefix, coloredMatch, suffix)
165
166 fmt.Printf(Indent + Indent + "}")
167}
168
169func jsonMarshal(input string) string {
170 output, _ := json.Marshal(input)

Callers 1

PrintColoredSecretsFunction · 0.85

Calls 2

jsonMarshalFunction · 0.85
removeFirstLastCharFunction · 0.85

Tested by

no test coverage detected