Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Feb 12, 2024
2 parents 406e72a + f5a4068 commit 455b718
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
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
30 changes: 20 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 @@ -154,6 +154,25 @@ func ParseOptions() *Options {
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 @@ -194,15 +213,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

0 comments on commit 455b718

Please sign in to comment.