Skip to content

Commit

Permalink
Validate that Xray URL exists when running Xray commands (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Oct 4, 2023
1 parent ed58d36 commit fbe1eb3
Showing 1 changed file with 11 additions and 9 deletions.
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

0 comments on commit fbe1eb3

Please sign in to comment.