diff --git a/helper/helper.go b/helper/helper.go index d612300..05c4346 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -35,15 +35,15 @@ func SetEnumerationPipeline(services, speed *string) { } } -func DumpInfo(services_dump *string, print_apicalls *bool, filter *string, errors_dump *bool) { +func DumpInfo(services_dump *string, print_apicalls *bool, filter *string, errors_dump *bool, clear_empty *bool) { if *services_dump == "all" { for _, service := range utils.ServiceNames() { - utils.AnalyseService(service, *print_apicalls, *filter, *errors_dump) + utils.AnalyseService(service, *print_apicalls, *filter, *errors_dump, *clear_empty) } fmt.Println() } else { for _, service := range utils.ProcessServiceArgument(*services_dump) { - utils.AnalyseService(service, *print_apicalls, *filter, *errors_dump) + utils.AnalyseService(service, *print_apicalls, *filter, *errors_dump, *clear_empty) } fmt.Println() } @@ -94,6 +94,7 @@ Flags: -filter Retrieve only wanted API Call Names by filtering the name. Additional flag. (Filters by first specified chars) -print Print data for a specified service API Calls Get the list of accessible apicalls. Additional flag. -errors Analyse errors returned by AWS API for a specific service. Additional flag. + -clear-empty Hide services with empty results ({}). Suppresses "No entries in provided service" output. Example: #1 @@ -107,6 +108,7 @@ Example: ./aws-enumerator dump -services all -filter Get ./aws-enumerator dump -services all -filter Get -print ./aws-enumerator dump -services all -filter Get -print -errors + ./aws-enumerator dump -services all -filter Get -print -clear-empty ` // Command line flags: @@ -126,3 +128,4 @@ var Services_dump *string = Dump.String("services", "all", "") var Errors_dump *bool = Dump.Bool("errors", false, "") var Print *bool = Dump.Bool("print", false, "") var Filter *string = Dump.String("filter", "", "") +var Clear_empty *bool = Dump.Bool("clear-empty", false, "") diff --git a/main.go b/main.go index 93c0418..215a4b8 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,7 @@ func main() { case "dump": helper.Dump.Parse(os.Args[2:]) - helper.DumpInfo(helper.Services_dump, helper.Print, helper.Filter, helper.Errors_dump) + helper.DumpInfo(helper.Services_dump, helper.Print, helper.Filter, helper.Errors_dump, helper.Clear_empty) default: fmt.Println(helper.Cloudrider_help) diff --git a/utils/utils.go b/utils/utils.go index 6224ea1..eacdb05 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -122,12 +122,14 @@ func CheckEnvFileExistance() bool { return true } -func CheckFileExistance(path string) bool { +func CheckFileExistance(path string, clear_empty bool) bool { if _, err := os.Stat(path); err != nil { if os.IsNotExist(err) { - fmt.Println(Red("Error:"), Yellow("File"), Yellow(path), Yellow("does not exist")) - fmt.Println(Green("Fix:"), Yellow("DB does not exist, skip this service")) - //fmt.Println(Red("Trace:"), Yellow(err)) + if !clear_empty { + fmt.Println(Red("Error:"), Yellow("File"), Yellow(path), Yellow("does not exist")) + fmt.Println(Green("Fix:"), Yellow("DB does not exist, skip this service")) + //fmt.Println(Red("Trace:"), Yellow(err)) + } return false } } @@ -192,7 +194,7 @@ func GetJsonFromFile(filepath string) (result map[string]interface{}) { return result } -func AnalyseService(service string, print bool, filter string, errors_dump bool) { +func AnalyseService(service string, print bool, filter string, errors_dump bool, clear_empty bool) { // Error or result analyse var filepath string @@ -201,17 +203,22 @@ func AnalyseService(service string, print bool, filter string, errors_dump bool) } else { filepath = ERROR_FILEPATH + service + "_errors.json" } - - // Display - PrintDividedLine(strings.ToUpper(service)) - fmt.Println("") - + // Check the file existance - if CheckFileExistance(filepath) { - + if CheckFileExistance(filepath, clear_empty) { + // dump service db_file result := GetJsonFromFile(filepath) + // // Skip display if empty and clear-empty flag is enabled + if len(result) == 0 && clear_empty { + return + } + + // Display service + PrintDividedLine(strings.ToUpper(service)) + fmt.Println("") + // check whether any info was stored if len(result) == 0 { fmt.Println(Red("Error:"), Yellow("No entries in provided service"))