@@ -4,10 +4,10 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7- "net/http"
8-
97 "github.com/pkg/errors"
108 "github.com/spf13/viper"
9+ "net/http"
10+ "time"
1111
1212 errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
1313 commonParams "github.com/checkmarx/ast-cli/internal/params"
@@ -30,7 +30,10 @@ func (p *ProjectsHTTPWrapper) Create(model *Project) (*ProjectResponseModel, *Er
3030 return nil , nil , err
3131 }
3232
33- resp , err := SendHTTPRequest (http .MethodPost , p .path , bytes .NewBuffer (jsonBytes ), true , clientTimeout )
33+ fn := func () (* http.Response , error ) {
34+ return SendHTTPRequest (http .MethodPost , p .path , bytes .NewBuffer (jsonBytes ), true , clientTimeout )
35+ }
36+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
3437 if err != nil {
3538 return nil , nil , err
3639 }
@@ -49,7 +52,10 @@ func (p *ProjectsHTTPWrapper) Update(projectID string, model *Project) error {
4952 return nil
5053 }
5154
52- resp , err := SendHTTPRequest (http .MethodPut , fmt .Sprintf ("%s/%s" , p .path , projectID ), bytes .NewBuffer (jsonBytes ), true , clientTimeout )
55+ fn := func () (* http.Response , error ) {
56+ return SendHTTPRequest (http .MethodPut , fmt .Sprintf ("%s/%s" , p .path , projectID ), bytes .NewBuffer (jsonBytes ), true , clientTimeout )
57+ }
58+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
5359 if err != nil {
5460 return err
5561 }
@@ -79,7 +85,10 @@ func (p *ProjectsHTTPWrapper) UpdateConfiguration(projectID string, configuratio
7985 commonParams .ProjectIDFlag : projectID ,
8086 }
8187
82- resp , err := SendHTTPRequestWithQueryParams (http .MethodPatch , "api/configuration/project" , params , bytes .NewBuffer (jsonBytes ), clientTimeout )
88+ fn := func () (* http.Response , error ) {
89+ return SendHTTPRequestWithQueryParams (http .MethodPatch , "api/configuration/project" , params , bytes .NewBuffer (jsonBytes ), clientTimeout )
90+ }
91+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
8392 if err != nil {
8493 return nil , err
8594 }
@@ -100,7 +109,10 @@ func (p *ProjectsHTTPWrapper) Get(params map[string]string) (
100109 params [limit ] = limitValue
101110 }
102111
103- resp , err := SendHTTPRequestWithQueryParams (http .MethodGet , p .path , params , nil , clientTimeout )
112+ fn := func () (* http.Response , error ) {
113+ return SendHTTPRequestWithQueryParams (http .MethodGet , p .path , params , nil , clientTimeout )
114+ }
115+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
104116 if err != nil {
105117 return nil , nil , err
106118 }
@@ -137,7 +149,11 @@ func (p *ProjectsHTTPWrapper) GetByID(projectID string) (
137149 * ErrorModel ,
138150 error ) {
139151 clientTimeout := viper .GetUint (commonParams .ClientTimeoutKey )
140- resp , err := SendHTTPRequest (http .MethodGet , p .path + "/" + projectID , http .NoBody , true , clientTimeout )
152+
153+ fn := func () (* http.Response , error ) {
154+ return SendHTTPRequest (http .MethodGet , p .path + "/" + projectID , http .NoBody , true , clientTimeout )
155+ }
156+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
141157 if err != nil {
142158 return nil , nil , err
143159 }
@@ -180,7 +196,11 @@ func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[strin
180196 var request = "/branches?project-id=" + projectID
181197
182198 params ["limit" ] = limitValue
183- resp , err := SendHTTPRequestWithQueryParams (http .MethodGet , p .path + request , params , nil , clientTimeout )
199+
200+ fn := func () (* http.Response , error ) {
201+ return SendHTTPRequestWithQueryParams (http .MethodGet , p .path + request , params , nil , clientTimeout )
202+ }
203+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
184204 if err != nil {
185205 return nil , nil , err
186206 }
@@ -215,7 +235,10 @@ func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[strin
215235
216236func (p * ProjectsHTTPWrapper ) Delete (projectID string ) (* ErrorModel , error ) {
217237 clientTimeout := viper .GetUint (commonParams .ClientTimeoutKey )
218- resp , err := SendHTTPRequest (http .MethodDelete , p .path + "/" + projectID , http .NoBody , true , clientTimeout )
238+ fn := func () (* http.Response , error ) {
239+ return SendHTTPRequest (http .MethodDelete , p .path + "/" + projectID , http .NoBody , true , clientTimeout )
240+ }
241+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
219242 if err != nil {
220243 return nil , err
221244 }
@@ -232,7 +255,11 @@ func (p *ProjectsHTTPWrapper) Tags() (
232255 * ErrorModel ,
233256 error ) {
234257 clientTimeout := viper .GetUint (commonParams .ClientTimeoutKey )
235- resp , err := SendHTTPRequest (http .MethodGet , p .path + "/tags" , http .NoBody , true , clientTimeout )
258+
259+ fn := func () (* http.Response , error ) {
260+ return SendHTTPRequest (http .MethodGet , p .path + "/tags" , http .NoBody , true , clientTimeout )
261+ }
262+ resp , err := retryHTTPRequest (fn , retryAttempts , retryDelay * time .Millisecond )
236263 if err != nil {
237264 return nil , nil , err
238265 }
0 commit comments