@@ -3,18 +3,17 @@ package v1
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
- "io"
7
- "net/http"
8
- "net/url"
9
-
10
6
"github.com/armosec/armoapi-go/armotypes"
11
7
"github.com/armosec/armoapi-go/identifiers"
12
8
httputils "github.com/armosec/utils-go/httputils"
13
9
v1 "github.com/kubescape/backend/pkg/server/v1"
14
10
"github.com/kubescape/backend/pkg/utils"
11
+ "io"
12
+ "net/http"
13
+ "net/url"
15
14
)
16
15
17
- func getCVEExceptionsURL (backendURL , customerGUID string , designators * identifiers. PortalDesignator ) (* url.URL , error ) {
16
+ func constructCVEExceptionsURL (backendURL , customerGUID string , queryParams * url. Values ) (* url.URL , error ) {
18
17
scheme , host , err := utils .ParseHost (backendURL )
19
18
if err != nil {
20
19
return nil , err
@@ -24,32 +23,33 @@ func getCVEExceptionsURL(backendURL, customerGUID string, designators *identifie
24
23
Scheme : scheme ,
25
24
Path : v1 .ApiServerVulnerabilitiesExceptionsPathOld ,
26
25
}
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 {}
28
33
for k , v := range designators .Attributes {
29
34
qValues .Add (k , v )
30
35
}
31
- qValues .Add (v1 .QueryParamCustomerGUID , customerGUID )
32
-
33
- expURL .RawQuery = qValues .Encode ()
34
- return expURL , nil
36
+ return constructCVEExceptionsURL (backendURL , customerGUID , & qValues )
35
37
}
36
38
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
+ }
38
42
43
+ func fetchCVEExceptions (url * url.URL , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
39
44
var vulnerabilityExceptionPolicy []armotypes.VulnerabilityExceptionPolicy
40
45
41
- url , err := getCVEExceptionsURL (backendURL , customerGUID , designators )
42
- if err != nil {
43
- return nil , err
44
- }
45
-
46
46
resp , err := httputils .HttpGet (http .DefaultClient , url .String (), headers )
47
47
if err != nil {
48
48
return nil , err
49
49
}
50
50
51
51
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 )
53
53
}
54
54
55
55
bodyBytes , err := io .ReadAll (resp .Body )
@@ -65,12 +65,20 @@ func getCVEExceptionByDEsignator(backendURL, customerGUID string, designators *i
65
65
return vulnerabilityExceptionPolicy , nil
66
66
}
67
67
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 )
70
78
if err != nil {
71
79
return nil , err
72
80
}
73
- return vulnerabilityExceptionPolicyList , nil
81
+ return fetchCVEExceptions ( url , headers )
74
82
}
75
83
76
84
func GetVulnerabilitiesReportURL (eventReceiverUrl , customerGUID string ) (* url.URL , error ) {
0 commit comments