11package v1
22
33import (
4+ "context"
45 "encoding/json"
56 "fmt"
7+ "io"
8+ "net/http"
9+ "net/url"
10+
611 "github.com/armosec/armoapi-go/armotypes"
712 "github.com/armosec/armoapi-go/identifiers"
8- httputils "github.com/armosec/utils-go/httputils"
913 v1 "github.com/kubescape/backend/pkg/server/v1"
1014 "github.com/kubescape/backend/pkg/utils"
11- "io"
12- "net/http"
13- "net/url"
1415)
1516
1617func constructCVEExceptionsURL (backendURL , customerGUID string , queryParams * url.Values ) (* url.URL , error ) {
@@ -40,13 +41,22 @@ func getCVEExceptionsURLByRawQuery(backendURL, customerGUID string, rawQuery *ur
4041 return constructCVEExceptionsURL (backendURL , customerGUID , rawQuery )
4142}
4243
43- func fetchCVEExceptions (url * url.URL , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
44+ func fetchCVEExceptions (ctx context. Context , url * url.URL , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
4445 var vulnerabilityExceptionPolicy []armotypes.VulnerabilityExceptionPolicy
4546
46- resp , err := httputils .HttpGet (http .DefaultClient , url .String (), headers )
47+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , url .String (), nil )
48+ if err != nil {
49+ return nil , err
50+ }
51+ for k , v := range headers {
52+ req .Header .Set (k , v )
53+ }
54+
55+ resp , err := http .DefaultClient .Do (req )
4756 if err != nil {
4857 return nil , err
4958 }
59+ defer resp .Body .Close ()
5060
5161 if resp .StatusCode < 200 || resp .StatusCode >= 300 {
5262 return nil , fmt .Errorf ("fetchCVEExceptions: resp.StatusCode %d" , resp .StatusCode )
@@ -65,20 +75,20 @@ func fetchCVEExceptions(url *url.URL, headers map[string]string) ([]armotypes.Vu
6575 return vulnerabilityExceptionPolicy , nil
6676}
6777
68- func GetCVEExceptionByDesignator (backendURL , customerGUID string , designators * identifiers.PortalDesignator , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
78+ func GetCVEExceptionByDesignator (ctx context. Context , backendURL , customerGUID string , designators * identifiers.PortalDesignator , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
6979 url , err := getCVEExceptionsURL (backendURL , customerGUID , designators )
7080 if err != nil {
7181 return nil , err
7282 }
73- return fetchCVEExceptions (url , headers )
83+ return fetchCVEExceptions (ctx , url , headers )
7484}
7585
76- func GetCVEExceptionByRawQuery (backendURL , customerGUID string , rawQuery * url.Values , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
86+ func GetCVEExceptionByRawQuery (ctx context. Context , backendURL , customerGUID string , rawQuery * url.Values , headers map [string ]string ) ([]armotypes.VulnerabilityExceptionPolicy , error ) {
7787 url , err := getCVEExceptionsURLByRawQuery (backendURL , customerGUID , rawQuery )
7888 if err != nil {
7989 return nil , err
8090 }
81- return fetchCVEExceptions (url , headers )
91+ return fetchCVEExceptions (ctx , url , headers )
8292}
8393
8494func GetVulnerabilitiesReportURL (eventReceiverUrl , customerGUID string ) (* url.URL , error ) {
0 commit comments