-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(sdk): mirror -config, -report-config, -dashboard for SDK callers #7393
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f3308fa
feat(sdk): mirror -config, -report-config, -dashboard for SDK callers
ShubhamRasal db15637
refactor(sdk): dedupe config loaders, drop threadSafePerScan mode
ShubhamRasal 44c63a8
docs(sdk): trim PR comments, fix two review nits
ShubhamRasal 642887e
fix(runner): restore nolint on deprecated ZTLS flag binding
ShubhamRasal d5d9eed
test(sdk): drop DisableUpdateCheck() from new lib/config_test.go
ShubhamRasal f2c95ef
fix(runner): suppress redundant "upload disabled" warning on default …
ShubhamRasal 0fc90a6
docs(runner): tighten SetupPDCPUpload disabled-branch comment to one …
ShubhamRasal fbf7d00
Merge branch 'dev' into sdk-upload
ShubhamRasal f783605
revert(sdk): keep CLI untouched, restore original PDCP disabled message
ShubhamRasal 609cf3d
refactor(sdk): replace goflags overlay with RuntimeConfig struct
ShubhamRasal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package nuclei | ||
|
|
||
| import ( | ||
| "os" | ||
| "reflect" | ||
|
|
||
| "github.com/projectdiscovery/goflags" | ||
| "github.com/projectdiscovery/nuclei/v3/internal/runner" | ||
| pkgtypes "github.com/projectdiscovery/nuclei/v3/pkg/types" | ||
| "github.com/projectdiscovery/utils/errkit" | ||
| ) | ||
|
|
||
| // loadReportingConfigFromPath reads + parses a -report-config YAML at path | ||
| // and stores the result on e. | ||
| func loadReportingConfigFromPath(e *NucleiEngine, path string) error { | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| return errkit.Wrap(err, "could not open reporting config file") | ||
| } | ||
| ropts, err := runner.LoadReportingOptionsFromBytes(data) | ||
| if err != nil { | ||
| return errkit.Wrap(err, "could not parse reporting config file") | ||
| } | ||
| e.reportingOpts = ropts | ||
| return nil | ||
| } | ||
|
|
||
| // loadImplicitReportingConfig loads the reporting YAML pointed at by | ||
| // opts.ReportingConfig, matching the CLI's `report-config:` behaviour. Skipped | ||
| // when an explicit WithReportingConfig* already set reportingOpts. | ||
| func loadImplicitReportingConfig(e *NucleiEngine) error { | ||
| if e.opts.ReportingConfig == "" || e.reportingOpts != nil { | ||
| return nil | ||
| } | ||
| return loadReportingConfigFromPath(e, e.opts.ReportingConfig) | ||
| } | ||
|
|
||
| // newConfigFlagSet binds the shared flag inventory to opts. Used to build the | ||
| // baseline and overlay structs for the reflection-based YAML diff. | ||
| func newConfigFlagSet(opts *pkgtypes.Options) *goflags.FlagSet { | ||
| fs := goflags.NewFlagSet() | ||
| fs.CaseSensitive = true | ||
| runner.BindOptionFlags(fs, opts) | ||
| return fs | ||
| } | ||
|
|
||
| // overlayConfigFromFile applies only YAML-set fields from path into dst. | ||
| // | ||
| // goflags writes flag defaults into the bound pointer at registration, so | ||
| // binding directly to dst would clobber existing values. We diff a baseline | ||
| // (flag-defaults only) against an overlay (flag-defaults + YAML); fields that | ||
| // differ are the ones the YAML touched and get copied into dst. | ||
| func overlayConfigFromFile(dst *pkgtypes.Options, path string) error { | ||
| baseline := &pkgtypes.Options{} | ||
| _ = newConfigFlagSet(baseline) | ||
|
|
||
| overlay := &pkgtypes.Options{} | ||
| fs := newConfigFlagSet(overlay) | ||
| if err := fs.MergeConfigFile(path); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| applyOverlay(dst, baseline, overlay) | ||
| return nil | ||
| } | ||
|
|
||
| // applyOverlay copies any field from overlay into dst where overlay differs | ||
| // from baseline. Unexported / non-settable fields are skipped. | ||
| func applyOverlay(dst, baseline, overlay *pkgtypes.Options) { | ||
| dstV := reflect.ValueOf(dst).Elem() | ||
| baseV := reflect.ValueOf(baseline).Elem() | ||
| overV := reflect.ValueOf(overlay).Elem() | ||
|
|
||
| for i := 0; i < dstV.NumField(); i++ { | ||
| df := dstV.Field(i) | ||
| if !df.CanSet() { | ||
| continue | ||
| } | ||
| bf := baseV.Field(i) | ||
| of := overV.Field(i) | ||
| if reflect.DeepEqual(bf.Interface(), of.Interface()) { | ||
| continue | ||
| } | ||
| df.Set(of) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.