-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated logs, outputs, and write to file
- Loading branch information
1 parent
bf6b6b6
commit cb8cb4e
Showing
6 changed files
with
83 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package outputs | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// function for s3 output | ||
func S3Output(lambdaResponse interface{}) { | ||
if strings.Contains(lambdaResponse.(string), "No findings") { | ||
log.Println("Scan completed with no findings") | ||
return | ||
} | ||
log.Println("Saved results in", lambdaResponse) | ||
} | ||
|
||
// function for cmd output | ||
func CmdOutput(lambdaResponse interface{}) { | ||
// convert lambdaResponse to string | ||
lambdaResponseString := lambdaResponse.(string) | ||
// convert response from base64 to colorized terminal output | ||
decodedBytes, _ := base64.StdEncoding.DecodeString(lambdaResponseString) | ||
// if decodedBytes is empty then return | ||
if len(decodedBytes) == 0 { | ||
log.Println("Scan completed with no output") | ||
return | ||
} | ||
log.Println("Scan complete with output:") | ||
fmt.Println(string(decodedBytes)) | ||
} | ||
|
||
// function for json output | ||
func JsonOutput(lambdaResponse interface{}) { | ||
// if lambdaResponse contains the string "No findings" then return | ||
if strings.Contains(lambdaResponse.(string), "No findings") { | ||
log.Println("Scan completed with no findings") | ||
return | ||
} | ||
// pretty print json in lambdaResponse indented by 4 spaces | ||
var prettyJSON bytes.Buffer | ||
error := json.Indent(&prettyJSON, []byte(lambdaResponse.(string)), "", " ") | ||
if error != nil { | ||
log.Println("JSON parse error: ", error) | ||
return | ||
} | ||
// if results.json exists, append to it | ||
if _, err := os.Stat("results.json"); err == nil { | ||
f, err := os.OpenFile("results.json", os.O_APPEND|os.O_WRONLY, 0600) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
_, err = f.Write(prettyJSON.Bytes()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Println("Appended results in results.json") | ||
return | ||
} | ||
// write prettyJSON to file | ||
f, err := os.Create("results.json") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
_, err = f.Write(prettyJSON.Bytes()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Println("Saved results in results.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters