Skip to content

Commit 5b062de

Browse files
RinaO1234rinao12
andauthored
SUB-4890 - [KYOS] As a User I want to be able to accept the risk of C… (#26)
* SUB-4890 - [KYOS] As a User I want to be able to accept the risk of CVE/Resource for all Cluster, Namespace, Workload, Container Signed-off-by: rinao12 <[email protected]> * fixed test Signed-off-by: rinao12 <[email protected]> --------- Signed-off-by: rinao12 <[email protected]> Co-authored-by: rinao12 <[email protected]>
1 parent f2fc733 commit 5b062de

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

pkg/client/v1/vulnerabilities.go

+28-20
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ package v1
33
import (
44
"encoding/json"
55
"fmt"
6-
"io"
7-
"net/http"
8-
"net/url"
9-
106
"github.com/armosec/armoapi-go/armotypes"
117
"github.com/armosec/armoapi-go/identifiers"
128
httputils "github.com/armosec/utils-go/httputils"
139
v1 "github.com/kubescape/backend/pkg/server/v1"
1410
"github.com/kubescape/backend/pkg/utils"
11+
"io"
12+
"net/http"
13+
"net/url"
1514
)
1615

17-
func getCVEExceptionsURL(backendURL, customerGUID string, designators *identifiers.PortalDesignator) (*url.URL, error) {
16+
func constructCVEExceptionsURL(backendURL, customerGUID string, queryParams *url.Values) (*url.URL, error) {
1817
scheme, host, err := utils.ParseHost(backendURL)
1918
if err != nil {
2019
return nil, err
@@ -24,32 +23,33 @@ func getCVEExceptionsURL(backendURL, customerGUID string, designators *identifie
2423
Scheme: scheme,
2524
Path: v1.ApiServerVulnerabilitiesExceptionsPathOld,
2625
}
27-
qValues := expURL.Query()
26+
queryParams.Add(v1.QueryParamCustomerGUID, customerGUID)
27+
expURL.RawQuery = queryParams.Encode()
28+
return expURL, nil
29+
}
30+
31+
func getCVEExceptionsURL(backendURL, customerGUID string, designators *identifiers.PortalDesignator) (*url.URL, error) {
32+
qValues := url.Values{}
2833
for k, v := range designators.Attributes {
2934
qValues.Add(k, v)
3035
}
31-
qValues.Add(v1.QueryParamCustomerGUID, customerGUID)
32-
33-
expURL.RawQuery = qValues.Encode()
34-
return expURL, nil
36+
return constructCVEExceptionsURL(backendURL, customerGUID, &qValues)
3537
}
3638

37-
func getCVEExceptionByDEsignator(backendURL, customerGUID string, designators *identifiers.PortalDesignator, headers map[string]string) ([]armotypes.VulnerabilityExceptionPolicy, error) {
39+
func getCVEExceptionsURLByRawQuery(backendURL, customerGUID string, rawQuery *url.Values) (*url.URL, error) {
40+
return constructCVEExceptionsURL(backendURL, customerGUID, rawQuery)
41+
}
3842

43+
func fetchCVEExceptions(url *url.URL, headers map[string]string) ([]armotypes.VulnerabilityExceptionPolicy, error) {
3944
var vulnerabilityExceptionPolicy []armotypes.VulnerabilityExceptionPolicy
4045

41-
url, err := getCVEExceptionsURL(backendURL, customerGUID, designators)
42-
if err != nil {
43-
return nil, err
44-
}
45-
4646
resp, err := httputils.HttpGet(http.DefaultClient, url.String(), headers)
4747
if err != nil {
4848
return nil, err
4949
}
5050

5151
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
52-
return nil, fmt.Errorf("getCVEExceptionByDEsignator: resp.StatusCode %d", resp.StatusCode)
52+
return nil, fmt.Errorf("fetchCVEExceptions: resp.StatusCode %d", resp.StatusCode)
5353
}
5454

5555
bodyBytes, err := io.ReadAll(resp.Body)
@@ -65,12 +65,20 @@ func getCVEExceptionByDEsignator(backendURL, customerGUID string, designators *i
6565
return vulnerabilityExceptionPolicy, nil
6666
}
6767

68-
func GetCVEExceptionByDesignator(baseURL, customerGUID string, designators *identifiers.PortalDesignator, headers map[string]string) ([]armotypes.VulnerabilityExceptionPolicy, error) {
69-
vulnerabilityExceptionPolicyList, err := getCVEExceptionByDEsignator(baseURL, customerGUID, designators, headers)
68+
func GetCVEExceptionByDesignator(backendURL, customerGUID string, designators *identifiers.PortalDesignator, headers map[string]string) ([]armotypes.VulnerabilityExceptionPolicy, error) {
69+
url, err := getCVEExceptionsURL(backendURL, customerGUID, designators)
70+
if err != nil {
71+
return nil, err
72+
}
73+
return fetchCVEExceptions(url, headers)
74+
}
75+
76+
func GetCVEExceptionByRawQuery(backendURL, customerGUID string, rawQuery *url.Values, headers map[string]string) ([]armotypes.VulnerabilityExceptionPolicy, error) {
77+
url, err := getCVEExceptionsURLByRawQuery(backendURL, customerGUID, rawQuery)
7078
if err != nil {
7179
return nil, err
7280
}
73-
return vulnerabilityExceptionPolicyList, nil
81+
return fetchCVEExceptions(url, headers)
7482
}
7583

7684
func GetVulnerabilitiesReportURL(eventReceiverUrl, customerGUID string) (*url.URL, error) {

pkg/client/v1/vulnerabilities_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package v1
22

33
import (
4+
url2 "net/url"
45
"testing"
56

67
"github.com/armosec/armoapi-go/identifiers"
78
"github.com/stretchr/testify/assert"
89
)
910

11+
func Test_getCVEExceptionsURLByRawQuery(t *testing.T) {
12+
url, err := getCVEExceptionsURLByRawQuery("http://localhost:8080", "abc", &url2.Values{
13+
"scope.namespace": []string{"kube-system", "*/*"},
14+
"scope.cluster": []string{"c1", "c2"},
15+
"scope.name": []string{"n1", "*/*"},
16+
"scope.kind": []string{"deployment"},
17+
"scope.other": []string{""},
18+
})
19+
assert.NoError(t, err)
20+
assert.Equal(t, "http://localhost:8080/api/v1/armoVulnerabilityExceptions?customerGUID=abc&scope.cluster=c1&scope.cluster=c2&scope.kind=deployment&scope.name=n1&scope.name=%2A%2F%2A&scope.namespace=kube-system&scope.namespace=%2A%2F%2A&scope.other=", url.String())
21+
}
22+
1023
func Test_getCVEExceptionsURL(t *testing.T) {
1124
url, err := getCVEExceptionsURL("http://localhost:8080", "abc", &identifiers.PortalDesignator{
1225
Attributes: map[string]string{

pkg/versioncheck/versioncheck_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestVersionCheckHandler_getLatestVersion(t *testing.T) {
8787
},
8888
want: &VersionCheckResponse{
8989
Client: "kubescape",
90-
ClientUpdate: "v3.0.0",
90+
ClientUpdate: "v3.0.9",
9191
},
9292
wantErr: false,
9393
},

0 commit comments

Comments
 (0)