Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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, "")
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 19 additions & 12 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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"))
Expand Down