Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix provider config file not used in library mode #864

Merged
merged 7 commits into from
Jun 5, 2023

Conversation

nth347
Copy link
Contributor

@nth347 nth347 commented Jun 1, 2023

Proposed Changes

Refer to the issue #854

The problem is Subfinder unable to load provider-config.yaml file. The pull request added ParseUserOptions function to provide library users to parse their own Options. Example:

func main() {
	// Parse the command line flags and read config files
	options := &runner.Options{
		ProviderConfig: "C:\\Users\\nth347\\.config\\subfinder\\provider-config.yaml", // Does not take effect if you don't use ParseUserOptions
		Output:         os.Stdout,
		Domain:         []string{"target.com"},
	}
	//options.loadProvidersFrom("C:\\Users\\nth347\\.config\\subfinder\\provider-config.yaml")
	parsedOptions := runner.ParseUserOptions(options)

	newRunner, err := runner.NewRunner(parsedOptions)
	if err != nil {
		gologger.Fatal().Msgf("Could not create runner: %s\n", err)
	}

	err = newRunner.RunEnumeration()
	if err != nil {
		gologger.Fatal().Msgf("Could not run enumeration: %s\n", err)
	}
}

@nth347 nth347 changed the title Give library user the ability to parse their own Options Give library users the ability to parse their own Options Jun 1, 2023
@nth347
Copy link
Contributor Author

nth347 commented Jun 1, 2023

Hi @ehsandeep , please review my pull request

@nth347
Copy link
Contributor Author

nth347 commented Jun 1, 2023

Hi @tarunKoyalwar and @dogancanbakir,

To allow library users to load their own provider-config.yaml file, we need to make the func (options *Options) loadProvidersFrom(location string) function public. However, currently, Subfinder does not have an API for loading config.yaml. In order to address this, I have decided to introduce a new function called func ParseUserOptions(options *Options) *Options. This new function performs nearly the same operations as the existing func ParseOptions() *Options function, with the difference being that it returns the Options object for further usage & customization by library users.

Copy link
Member

@dogancanbakir dogancanbakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @nth347. I just left some comments for you.

v2/pkg/runner/options.go Outdated Show resolved Hide resolved
v2/pkg/runner/options.go Outdated Show resolved Hide resolved
@nth347
Copy link
Contributor Author

nth347 commented Jun 2, 2023

Hi @dogancanbakir after spending some time debugging, it turns out that the new Init function is essentially the same as the ParseOptions function. However, I did make a change on line 406. If library users specify their config.yaml location, it would be beneficial to merge it into the current Options. For now, library users only need to do something like the following:

func main() {
	options := &runner.Options{
		ResultCallback: func(s *resolve.HostEntry) { // Callback function to execute for available host
			log.Println(s.Host, s.Source)
		},
		ProviderConfig: "/path/to/provider-config.yaml", // Will take effect if you call runner.Init
		Config:         "/path/to/config.yaml", // Will take effect if you call runner.Init
		Domain:         []string{"tesla.com"},
	}

	parsedOptions := runner.Init(options)

	newRunner, err := runner.NewRunner(parsedOptions)
	if err != nil {
		gologger.Fatal().Msgf("Could not create runner: %s\n", err)
	}

	err = newRunner.RunEnumeration()
	if err != nil {
		gologger.Fatal().Msgf("Could not run enumeration: %s\n", err)
	}
}

nth347 added a commit to nth347/subfinder that referenced this pull request Jun 2, 2023
@tarunKoyalwar tarunKoyalwar changed the title Give library users the ability to parse their own Options fix provider config file not used in library mode Jun 5, 2023
Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nth347 thanks for flagging the issue and creating PR to fix that

I simplified the logic so there is no need to invoke another function like Init() and the updated example for using subfinder as library is available at https://github.com/nth347/subfinder/blob/02f520a0b1926224b8fbf57501a8112d1a7112ee/v2/examples/main.go#L12-L50

@tarunKoyalwar tarunKoyalwar self-assigned this Jun 5, 2023
@nth347
Copy link
Contributor Author

nth347 commented Jun 5, 2023

Hi @tarunKoyalwar, thank you for your fix! I noticed the problem, but I'm still working on improving my coding skills to address it. Your solution is greatly appreciated, and you did an excellent job!

@tarunKoyalwar
Copy link
Member

tarunKoyalwar commented Jun 5, 2023

@nth347 , no worries also don't hesitate to raise PR thinking about coding skills / being up to the mark . pd-team will help you with PRs as much as we can , just create a draft PR and tag anyone from pdteam

@ehsandeep ehsandeep merged commit 94b8115 into projectdiscovery:dev Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add example file for library usage provider config not used/loaded in library mode
4 participants