Repository: aquasecurity/starboard
Pull request #388 (2021-02-12 01:33:05)

Make kubehunter quick config param optional
This PR addresses a potential issue with the `kube-hunter.quick` configuration param. It doesn't make much sense for this parameter to be required, since it's a fairly specific setting that a significant portion of users may not care about.

(This PR was inspired by https://github.com/aquasecurity/starboard/discussions/386.)

codecov[bot]: # [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=h1) Report
> Merging [#388](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=desc) (b107e50) into [main](https://codecov.io/gh/aquasecurity/starboard/commit/d36f69e8890e178c444bb78e174e808e992405b9?el=desc) (d36f69e) will **decrease** coverage by `37.78%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/aquasecurity/starboard/pull/388/graphs/tree.svg?width=650&height=150&src=pr&token=qqTGKAJ0Wb)](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##             main     #388       +/-   ##
===========================================
- Coverage   68.47%   30.68%   -37.79%     
===========================================
  Files          58       57        -1     
  Lines        3061     2972       -89     
===========================================
- Hits         2096      912     -1184     
- Misses        709     1997     +1288     
+ Partials      256       63      -193     
```


| [Impacted Files](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/starboard/config.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL3N0YXJib2FyZC9jb25maWcuZ28=) | `71.07% <100.00%> (ø)` | |
| [pkg/cmd/get.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9nZXQuZ28=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/find.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9maW5kLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/root.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9yb290Lmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/scan.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9zY2FuLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/polaris.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9wb2xhcmlzLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/version.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC92ZXJzaW9uLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/kube\_bench.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9rdWJlX2JlbmNoLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/kube\_hunter.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9rdWJlX2h1bnRlci5nbw==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [pkg/cmd/find\_vulnerabilities.go](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree#diff-cGtnL2NtZC9maW5kX3Z1bG5lcmFiaWxpdGllcy5nbw==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| ... and [32 more](https://codecov.io/gh/aquasecurity/starboard/pull/388/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=footer). Last update [d3a3b00...fef249a](https://codecov.io/gh/aquasecurity/starboard/pull/388?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/starboard/config.go b/pkg/starboard/config.go
index 906e9f8..4a2d6e6 100644
--- a/pkg/starboard/config.go
+++ b/pkg/starboard/config.go
@@ -331,9 +331,9 @@ func (c ConfigData) GetKubeHunterImageRef() (string, error) {
 }
 
 func (c ConfigData) GetKubeHunterQuick() (bool, error) {
-	val, err := c.getRequiredProperty("kube-hunter.quick")
-	if err != nil {
-		return false, err
+	val, ok := c["kube-hunter.quick"]
+	if !ok {
+		return false, nil
 	}
 	if val != "false" && val != "true" {
 		return false, fmt.Errorf("property kube-hunter.quick must be either \"false\" or \"true\", got %q", val)


Test patch:
diff --git a/pkg/starboard/config_test.go b/pkg/starboard/config_test.go
index fb54915..82d9105 100644
--- a/pkg/starboard/config_test.go
+++ b/pkg/starboard/config_test.go
@@ -158,11 +158,11 @@ func TestConfigData_GetKubeHunterQuick(t *testing.T) {
 		expectedQuick bool
 	}{
 		{
-			name:          "Should return error",
+			name:          "Should return false when parameter is not set",
 			configData:    starboard.ConfigData{},
-			expectedError: "property kube-hunter.quick not set",
+			expectedQuick: false,
 		}, {
-			name: "Should return error when when quick is set to something other than \"false\" or \"true\" in config data",
+			name: "Should return error when quick is set to something other than \"false\" or \"true\" in config data",
 			configData: starboard.ConfigData{
 				"kube-hunter.quick": "not-a-boolean",
 			},