From 80bec05573cfcfe3b2ef16253dd5a8f4374768aa Mon Sep 17 00:00:00 2001 From: zhangchengguo Date: Tue, 8 Mar 2022 16:22:50 +0800 Subject: [PATCH 1/2] fix readme golang demo for v2.5.0 --- README.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d6c91e316..2507cc482 100644 --- a/README.md +++ b/README.md @@ -242,23 +242,16 @@ import ( ) func main() { - config := runner.ConfigFile{ - // Use the default list of resolvers by marshaling it to the config - Resolvers: resolve.DefaultResolvers, - // Use the default list of passive sources - Sources: passive.DefaultSources, - // Use the default list of all passive sources - AllSources: passive.DefaultAllSources, - // Use the default list of recursive sources - Recursive: passive.DefaultRecursiveSources, - } - runnerInstance, err := runner.NewRunner(&runner.Options{ Threads: 10, // Thread controls the number of threads to use for active enumerations Timeout: 30, // Timeout is the seconds to wait for sources to respond MaxEnumerationTime: 10, // MaxEnumerationTime is the maximum amount of time in mins to wait for enumeration - YAMLConfig: config, - }) + Resolvers: resolve.DefaultResolvers, // Use the default list of resolvers by marshaling it to the config + Sources: passive.DefaultSources, // Use the default list of passive sources + AllSources: passive.DefaultAllSources, // Use the default list of all passive sources + Recursive: passive.DefaultRecursiveSources, // Use the default list of recursive sources + Providers: &runner.Providers{}, // Use empty api keys for all providers + }) buf := bytes.Buffer{} err = runnerInstance.EnumerateSingleDomain(context.Background(), "projectdiscovery.io", []io.Writer{&buf}) From efae72c45bb817ab737bb24e91551b8acc067bd3 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 30 Mar 2022 02:04:22 +0100 Subject: [PATCH 2/2] Don't make missing providers-config fatal on first-run It's okay if we fall back to the default config which is in memory & will get saved out when done parsing. This is on top of the work in #526, but a slightly different issue. See: https://github.com/projectdiscovery/subfinder/pull/526 Signed-off-by: Sam James --- v2/pkg/runner/banners.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/v2/pkg/runner/banners.go b/v2/pkg/runner/banners.go index 7f11d2666..5749dff48 100644 --- a/v2/pkg/runner/banners.go +++ b/v2/pkg/runner/banners.go @@ -1,6 +1,9 @@ package runner import ( + "errors" + "os" + "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/subfinder/v2/pkg/passive" "github.com/projectdiscovery/subfinder/v2/pkg/resolve" @@ -44,7 +47,9 @@ func (options *Options) loadProvidersFrom(location string) { } options.Providers = &Providers{} - if err := options.Providers.UnmarshalFrom(location); isFatalErr(err) { + // We skip bailing out if file doesn't exist because we'll create it + // at the end of options parsing from default via goflags. + if err := options.Providers.UnmarshalFrom(location); isFatalErr(err) && !errors.Is(err, os.ErrNotExist) { gologger.Fatal().Msgf("Could not read providers from %s: %s\n", location, err) } }