Skip to content

Commit

Permalink
resolved: SAAS-4861 add triggered by flag, and to each created scan (#74
Browse files Browse the repository at this point in the history
)

* resolved: SAAS-4861 add triggered by flag, and to each created scan

* resolved: SAAS-4861 to upper in main one time

* resolved: SAAS-4861 add err check
  • Loading branch information
tzurielweisberg authored Apr 18, 2022
1 parent 3781259 commit e849065
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 272 deletions.
27 changes: 16 additions & 11 deletions cmd/aqua/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func main() {
Usage: "Add this flag if you want test failed policy locally before sending PR",
EnvVars: []string{"TRIVY_SKIP_RESULT_UPLOAD"},
},
&cli.BoolFlag{
Name: "pr-scan",
Usage: "Add this flag if you want scan only PR diff",
EnvVars: []string{"TRIVY_PR_SCAN"},
},
&cli.BoolFlag{
Name: "skip-policy-exit-code",
Usage: "Add this flag if you want skip policies exit code",
Expand All @@ -65,6 +60,11 @@ func main() {
EnvVars: []string{"TRIVY_SECURITY_CHECKS"},
Hidden: true,
},
&cli.StringFlag{
Name: "triggered-by",
Usage: "Add this flag to determine where the scan is coming from (push, pr, offline)",
EnvVars: []string{"TRIGGERED_BY"},
},
)

fsCmd := commands.NewFilesystemCommand()
Expand All @@ -75,11 +75,6 @@ func main() {
Usage: "Add this flag if you want test failed policy locally before sending PR",
EnvVars: []string{"TRIVY_SKIP_RESULT_UPLOAD"},
},
&cli.BoolFlag{
Name: "pr-scan",
Usage: "Add this flag if you want scan only PR diff",
EnvVars: []string{"TRIVY_PR_SCAN"},
},
&cli.BoolFlag{
Name: "skip-policy-exit-code",
Usage: "Add this flag if you want skip policies exit code",
Expand All @@ -90,6 +85,11 @@ func main() {
Usage: "Add this flag if you want run in debug mode",
EnvVars: []string{"DEBUG"},
},
&cli.StringFlag{
Name: "triggered-by",
Usage: "Add this flag to determine where the scan is coming from (push, pr, offline)",
EnvVars: []string{"TRIGGERED_BY"},
},
)

imageCmd := commands.NewImageCommand()
Expand Down Expand Up @@ -131,6 +131,11 @@ func runScan(c *cli.Context) error {
return err
}
}
if c.String("triggered-by") != "" {
if err := c.Set("triggered-by", strings.ToUpper(c.String("triggered-by"))); err != nil {
return err
}
}

debug := c.Bool("debug")

Expand Down Expand Up @@ -169,7 +174,7 @@ func runScan(c *cli.Context) error {
return err
}

if c.Bool("pr-scan") {
if c.String("triggered-by") == "PR" {
results, err = processor.PrDiffResults(results)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions pkg/buildClient/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"net/http"

"github.com/aquasecurity/trivy-plugin-aqua/pkg/scanner"

"github.com/aquasecurity/trivy-plugin-aqua/pkg/metadata"
"github.com/aquasecurity/trivy-plugin-aqua/pkg/proto/buildsecurity"
)
Expand Down Expand Up @@ -33,6 +35,7 @@ func (bc *TwirpClient) Upload(results []*buildsecurity.Result, tags map[string]s
Commit: commitId,
System: buildSystem,
Tags: tags,
TriggeredBy: scanner.MatchTriggeredBy(bc.c.String("triggered-by")),
}

_, err = client.CreateScan(ctx, createScanReq)
Expand Down
8 changes: 8 additions & 0 deletions pkg/proto/buildsecurity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ message CreateScanReq {
string Commit = 5;
repeated Result Results = 7;
map<string, string> Tags = 8;
TriggeredByEnum TriggeredBy = 9;
}

enum TriggeredByEnum {
TRIGGERED_BY_UNKNOWN = 0;
TRIGGERED_BY_PUSH = 1;
TRIGGERED_BY_PR = 2;
TRIGGERED_BY_OFFLINE = 3;
}

message CreateScanResp {
Expand Down
Loading

0 comments on commit e849065

Please sign in to comment.