-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from obadiaspelembe/release/1.0.0
feat: improve lint and check commands (#4)
- Loading branch information
Showing
20 changed files
with
374 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
$reportFileName = "report.json" | ||
|
||
$dockerImageName = "hello-world" | ||
|
||
$command = "docker scout cves $dockerImageName --format sarif --output $reportFileName" | ||
|
||
Invoke-Expression $command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$goExecutable = "go.exe" | ||
$goFile = "internal\main.go" | ||
|
||
$command = "$goExecutable run $goFile exec -r cves-report.example.json -p policy.example.yaml" | ||
|
||
Invoke-Expression $command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$goExecutable = "go.exe" | ||
$goFile = "internal\main.go" | ||
|
||
$command = "$goExecutable run $goFile lint -r cves-report.example.json -p policy.example.yaml" | ||
|
||
Invoke-Expression $command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"obadiaspelembe/cves-guard/utils" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var execCommand = &cobra.Command{ | ||
Use: "exec", | ||
Short: "exec policy check into cves-report", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if !utils.ExecPolicy(cmd.Flag("policy").Value.String(), cmd.Flag("cves-report").Value.String()) { | ||
os.Exit(1) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package tests | ||
package cmd | ||
|
||
import ( | ||
"obadiaspelembe/cves-guard/utils" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"obadiaspelembe/cves-guard/utils" | ||
) | ||
|
||
func TestApply(t *testing.T) { | ||
result := utils.ApplyPolicy("policy.example.yaml", "cves-report.example.json") | ||
func TestCheck(t *testing.T) { | ||
result := utils.ExecPolicy("policy.example.yaml", "cves-report.example.json") | ||
assert.Equal(t, true, result, "Should return true") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package tests | ||
package cmd | ||
|
||
import ( | ||
"obadiaspelembe/cves-guard/utils" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"obadiaspelembe/cves-guard/utils" | ||
) | ||
|
||
func TestLintValidate(t *testing.T) { | ||
result := utils.Validate("policy.example.yaml", "cves-report.example.json") | ||
assert.Equal(t, false, result, "Should return false") | ||
} | ||
assert.Equal(t, true, result, "Should return true") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ import ( | |
|
||
|
||
|
||
func main() { | ||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
--- | ||
version: v1.0.0 | ||
name: policy-name | ||
kind: Vulnerability | ||
version: v1.0.0 | ||
spec: | ||
config: | ||
critical: 2 | ||
high: 2 | ||
medium: 2 | ||
low: 2 | ||
vulnerability: | ||
critical: 1 | ||
high: 40 | ||
medium: 12 | ||
low: 10 | ||
packages: | ||
- name: stdlib | ||
action: deny | ||
severity: | ||
- critical | ||
- high | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package utils | ||
|
||
const ( | ||
SERVERITY_LOW = "LOW" | ||
SERVERITY_MEDIUM = "MEDIUM" | ||
SERVERITY_HIGH = "HIGH" | ||
SERVERITY_CRITICAL = "CRITICAL" | ||
SERVERITY_UNSPECIFIED = "UNSPECIFIED" | ||
|
||
VULNERABILITY_SEVERITY = "Severity" | ||
VULNERABILITY_PACKAGE = "Package" | ||
|
||
POLICY_PACKAGE_ACTIONS_DENY = "DENY" | ||
POLICY_PACKAGE_ACTIONS_ALLOW = "ALLOW" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func containerStringInList(list []string, target string) bool { | ||
for _, value := range list { | ||
if strings.ToUpper(value) == target { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func checkPackageAction(cvesPackage CVESData, pPackage Package) bool { | ||
|
||
packageAction := strings.ToUpper(*pPackage.Action) | ||
|
||
if packageAction == POLICY_PACKAGE_ACTIONS_DENY { | ||
pkgs := strings.Join(*pPackage.Severity, ", ") | ||
pkgs = strings.ToUpper(pkgs) | ||
fmt.Println("[", packageAction, "]:", " Package ", *pPackage.Name, pkgs, "severity") | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func logVulnerability(severity string, reportSeverity int, policySeverity int) { | ||
fmt.Println("[ DENY ]: ", severity, "unexpected: Found", reportSeverity, "/", policySeverity) | ||
} |
Oops, something went wrong.