@@ -5,12 +5,13 @@ import (
55 "crypto/x509"
66 "encoding/json"
77 "fmt"
8+ "log"
9+ neturl "net/url"
10+
811 "github.com/aquasecurity/terraform-provider-aquasec/consts"
912 "github.com/parnurzeal/gorequest"
1013 "golang.org/x/net/http/httpproxy"
1114 "golang.org/x/time/rate"
12- "log"
13- neturl "net/url"
1415)
1516
1617// Client - API client
@@ -30,6 +31,10 @@ const Csp string = "csp"
3031const Saas = "saas"
3132const SaasDev = "saasDev"
3233
34+ const UserAgentBase = "terraform-provider-aquasec"
35+
36+ var version string
37+
3338// NewClient - initialize and return the Client
3439func NewClient (url , user , password string , verifyTLS bool , caCertByte []byte ) * Client {
3540 tlsConfig := & tls.Config {
@@ -47,11 +52,13 @@ func NewClient(url, user, password string, verifyTLS bool, caCertByte []byte) *C
4752 }
4853 }
4954
55+ request := gorequest .New ().TLSClientConfig (tlsConfig )
56+
5057 c := & Client {
5158 url : url ,
5259 user : user ,
5360 password : password ,
54- gorequest : gorequest . New (). TLSClientConfig ( tlsConfig ) ,
61+ gorequest : request ,
5562 // we are setting rate limit for 10 connection per second
5663 limiter : rate .NewLimiter (10 , 3 ),
5764 }
@@ -121,7 +128,7 @@ func (cli *Client) GetAuthToken() (string, string, error) {
121128
122129// GetAuthToken - Connect to Aqua and return a JWT bearerToken (string)
123130func (cli * Client ) GetCspAuthToken () (string , error ) {
124- resp , body , errs := cli .gorequest .Post (cli .url + "/api/v1/login" ).
131+ resp , body , errs := cli .makeRequest () .Post (cli .url + "/api/v1/login" ).
125132 Send (`{"id":"` + cli .user + `", "password":"` + cli .password + `"}` ).End ()
126133 if errs != nil {
127134 return "" , getMergedError (errs )
@@ -164,7 +171,7 @@ func (cli *Client) GetUSEAuthToken() (string, string, error) {
164171 return "" , "" , fmt .Errorf (fmt .Sprintf ("%v URL is not allowed USE url" , cli .url ))
165172 }
166173
167- resp , body , errs := cli .gorequest .Post (cli .tokenUrl + "/v2/signin" ).
174+ resp , body , errs := cli .makeRequest () .Post (cli .tokenUrl + "/v2/signin" ).
168175 Send (`{"email":"` + cli .user + `", "password":"` + cli .password + `"}` ).End ()
169176 if errs != nil {
170177 return "" , "" , getMergedError (errs )
@@ -198,3 +205,8 @@ func (cli *Client) GetUSEAuthToken() (string, string, error) {
198205
199206 return "" , "" , fmt .Errorf ("request failed. status: %s, response: %s" , resp .Status , body )
200207}
208+
209+ func (cli * Client ) makeRequest () * gorequest.SuperAgent {
210+ userAgent := fmt .Sprintf ("%s/%s" , UserAgentBase , version )
211+ return cli .gorequest .Clone ().Set ("User-Agent" , userAgent )
212+ }
0 commit comments