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

Validate that Xray URL exists when running Xray commands #2238

Merged
merged 3 commits into from
Oct 4, 2023
Merged
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
20 changes: 11 additions & 9 deletions scan/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ func CurationCmd(c *cli.Context) error {

func createAuditCmd(c *cli.Context) (*audit.AuditCommand, error) {
auditCmd := audit.NewGenericAuditCommand()
err := validateXrayContext(c)
serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return nil, err
}
serverDetails, err := createServerDetailsWithConfigOffer(c)
err = validateXrayContext(c, serverDetails)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -282,11 +282,11 @@ func ScanCmd(c *cli.Context) error {
if c.NArg() == 0 && !c.IsSet("spec") {
return cliutils.PrintHelpAndReturnError("providing either a <source pattern> argument or the 'spec' option is mandatory", c)
}
err := validateXrayContext(c)
serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
}
serverDetails, err := createServerDetailsWithConfigOffer(c)
err = validateXrayContext(c, serverDetails)
if err != nil {
return err
}
Expand Down Expand Up @@ -344,12 +344,11 @@ func BuildScan(c *cli.Context) error {
if err := buildConfiguration.ValidateBuildParams(); err != nil {
return err
}

serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
}
err = validateXrayContext(c)
err = validateXrayContext(c, serverDetails)
if err != nil {
return err
}
Expand Down Expand Up @@ -378,11 +377,11 @@ func DockerScan(c *cli.Context, image string) error {
if image == "" {
return cli.ShowCommandHelp(c, "dockerscanhelp")
}
err := validateXrayContext(c)
serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
}
serverDetails, err := createServerDetailsWithConfigOffer(c)
err = validateXrayContext(c, serverDetails)
if err != nil {
return err
}
Expand Down Expand Up @@ -443,7 +442,10 @@ func shouldIncludeVulnerabilities(c *cli.Context) bool {
return c.String("watches") == "" && !isProjectProvided(c) && c.String("repo-path") == ""
}

func validateXrayContext(c *cli.Context) error {
func validateXrayContext(c *cli.Context, serverDetails *coreconfig.ServerDetails) error {
if serverDetails.XrayUrl == "" {
return errorutils.CheckErrorf("JFrog Xray URL must be provided in order run this command. Use the 'jf c add' command to set the Xray server details.")
}
contextFlag := 0
if c.String("watches") != "" {
contextFlag++
Expand Down
Loading