Skip to content

Commit

Permalink
Identify and print which sources need an API key / token when ls is used
Browse files Browse the repository at this point in the history
  • Loading branch information
vzamanillo authored and Víctor Zamanillo committed Jul 20, 2020
1 parent cfd9696 commit 1bbd4d3
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
"os"
"path"
"reflect"
"strings"

"github.com/projectdiscovery/gologger"
)
Expand Down Expand Up @@ -94,10 +96,7 @@ func ParseOptions() *Options {
}

if options.ListSources {
gologger.Infof("Current list of available sources. [%d]\n\n", len(options.YAMLConfig.Sources))
for _, source := range options.YAMLConfig.Sources {
gologger.Silentf("%s\n", source)
}
listSources(options)
os.Exit(0)
}

Expand All @@ -121,3 +120,28 @@ func hasStdin() bool {
}
return true
}

func listSources(options *Options) {
gologger.Infof("Current list of available sources. [%d]\n", len(options.YAMLConfig.Sources))
gologger.Infof("Sources marked with an * needs key or token in order to work.\n")
gologger.Infof("You can modify %s to configure your keys / tokens.\n\n", options.ConfigFile)

keys := options.YAMLConfig.GetKeys()
needsKey := make(map[string]interface{})
keysElem := reflect.ValueOf(&keys).Elem()
for i := 0; i < keysElem.NumField(); i++ {
needsKey[strings.ToLower(keysElem.Type().Field(i).Name)] = keysElem.Field(i).Interface()
}

for _, source := range options.YAMLConfig.Sources {
if key, ok := needsKey[source]; ok {
if key != "" {
gologger.Silentf("%s * %s\n", source, key)
} else {
gologger.Silentf("%s *\n", source)
}
} else {
gologger.Silentf("%s\n", source)
}
}
}

0 comments on commit 1bbd4d3

Please sign in to comment.