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

Allow auth option to parse string input as api key #80

Merged
merged 2 commits into from
Feb 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package runner
import "github.com/projectdiscovery/goflags"

type Options struct {
PdcpAuth bool
PdcpAuth string
CveIds goflags.StringSlice
CweIds goflags.StringSlice
Vendor goflags.StringSlice
Expand Down
32 changes: 22 additions & 10 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func ParseOptions() *Options {
flagset.SetDescription(`Navigate the CVE jungle with ease.`)

flagset.CreateGroup("config", "Config",
flagset.BoolVar(&options.PdcpAuth, "auth", false, "configure projectdiscovery cloud (pdcp) api key"),
flagset.DynamicVar(&options.PdcpAuth, "auth", "true", "configure projectdiscovery cloud (pdcp) api key"),
)

flagset.CreateGroup("OPTIONS", "options",
Expand Down Expand Up @@ -152,6 +152,27 @@ func ParseOptions() *Options {
gologger.Fatal().Msgf("Error parsing flags: %s\n", err)
}
options.Debug = env.GetEnvOrDefault("DEBUG", false)
if !options.Debug {
options.Debug = env.GetEnvOrDefault("DEBUG", false)
}
if options.Version {
gologger.Info().Msgf("Current Version: %s\n", Version)
os.Exit(0)
}

// api key hierarchy: cli flag > env var > .pdcp/credential file
if options.PdcpAuth == "true" {
AuthWithPDCP()
} else if len(options.PdcpAuth) == 36 {
PDCPApiKey = options.PdcpAuth
ph := pdcp.PDCPCredHandler{}
if _, err := ph.GetCreds(); err == pdcp.ErrNoCreds {
apiServer := env.GetEnvOrDefault("PDCP_API_SERVER", pdcp.DefaultApiServer)
if validatedCreds, err := ph.ValidateAPIKey(PDCPApiKey, apiServer, "cvemap"); err == nil {
_ = ph.SaveCreds(validatedCreds)
}
}
}

if options.Limit > maxLimit {
options.Limit = maxLimit
Expand Down Expand Up @@ -193,15 +214,6 @@ func New(options *Options) *Runner {
}

func (r *Runner) Run() {
if r.Options.Version {
gologger.Info().Msgf("Current Version: %s\n", Version)
os.Exit(0)
}

if r.Options.PdcpAuth {
AuthWithPDCP()
}

if r.Options.Silent {
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
} else if r.Options.Verbose {
Expand Down
Loading