@@ -35,6 +35,13 @@ var endpoints = map[string]string{
3535
3636var rateLimiter = time .Tick (time .Minute / 240 )
3737
38+ func addHeaders (request * http.Request , accessId string , accessKey string ) * http.Request {
39+ request .Header .Add ("Content-Type" , "application/json" )
40+ request .Header .Add ("User-Agent" , "SumoLogicTerraformProvider/2.0.0" )
41+ request .SetBasicAuth (accessId , accessKey )
42+ return request
43+ }
44+
3845func (s * Client ) PostWithCookies (urlPath string , payload interface {}) ([]byte , []* http.Cookie , error ) {
3946 relativeURL , err := url .Parse (urlPath )
4047 if err != nil {
@@ -53,8 +60,7 @@ func (s *Client) PostWithCookies(urlPath string, payload interface{}) ([]byte, [
5360 return nil , nil , err
5461 }
5562
56- req .Header .Add ("Content-Type" , "application/json" )
57- req .SetBasicAuth (s .AccessID , s .AccessKey )
63+ req = addHeaders (req , s .AccessID , s .AccessKey )
5864
5965 <- rateLimiter
6066 resp , err := s .httpClient .Do (req )
@@ -90,8 +96,7 @@ func (s *Client) GetWithCookies(urlPath string, cookies []*http.Cookie) ([]byte,
9096 return nil , "" , err
9197 }
9298
93- req .Header .Add ("Content-Type" , "application/json" )
94- req .SetBasicAuth (s .AccessID , s .AccessKey )
99+ req = addHeaders (req , s .AccessID , s .AccessKey )
95100
96101 for _ , cookie := range cookies {
97102 req .AddCookie (cookie )
@@ -124,8 +129,7 @@ func (s *Client) Post(urlPath string, payload interface{}) ([]byte, error) {
124129
125130 body , _ := json .Marshal (payload )
126131 req , _ := http .NewRequest (http .MethodPost , sumoURL .String (), bytes .NewBuffer (body ))
127- req .Header .Add ("Content-Type" , "application/json" )
128- req .SetBasicAuth (s .AccessID , s .AccessKey )
132+ req = addHeaders (req , s .AccessID , s .AccessKey )
129133
130134 <- rateLimiter
131135 resp , err := s .httpClient .Do (req )
@@ -150,8 +154,7 @@ func (s *Client) PostRawPayload(urlPath string, payload string) ([]byte, error)
150154 relativeURL , _ := url .Parse (urlPath )
151155 sumoURL := s .BaseURL .ResolveReference (relativeURL )
152156 req , _ := http .NewRequest (http .MethodPost , sumoURL .String (), bytes .NewBuffer ([]byte (payload )))
153- req .Header .Add ("Content-Type" , "application/json" )
154- req .SetBasicAuth (s .AccessID , s .AccessKey )
157+ req = addHeaders (req , s .AccessID , s .AccessKey )
155158
156159 <- rateLimiter
157160 resp , err := s .httpClient .Do (req )
@@ -180,11 +183,9 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
180183
181184 body , _ := json .Marshal (payload )
182185 req , _ := http .NewRequest (http .MethodPut , sumoURL .String (), bytes .NewBuffer (body ))
183- req . Header . Add ( "Content-Type" , "application/json" )
186+ req = addHeaders ( req , s . AccessID , s . AccessKey )
184187 req .Header .Add ("If-Match" , etag )
185188
186- req .SetBasicAuth (s .AccessID , s .AccessKey )
187-
188189 <- rateLimiter
189190 resp , err := s .httpClient .Do (req )
190191 if err != nil {
@@ -209,8 +210,7 @@ func (s *Client) Get(urlPath string) ([]byte, string, error) {
209210 sumoURL := s .BaseURL .ResolveReference (relativeURL )
210211
211212 req , _ := http .NewRequest (http .MethodGet , sumoURL .String (), nil )
212- req .Header .Add ("Content-Type" , "application/json" )
213- req .SetBasicAuth (s .AccessID , s .AccessKey )
213+ req = addHeaders (req , s .AccessID , s .AccessKey )
214214
215215 <- rateLimiter
216216 resp , err := s .httpClient .Do (req )
@@ -238,8 +238,7 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
238238 sumoURL := s .BaseURL .ResolveReference (relativeURL )
239239
240240 req , _ := http .NewRequest (http .MethodDelete , sumoURL .String (), nil )
241- req .Header .Add ("Content-Type" , "application/json" )
242- req .SetBasicAuth (s .AccessID , s .AccessKey )
241+ req = addHeaders (req , s .AccessID , s .AccessKey )
243242
244243 <- rateLimiter
245244 resp , err := s .httpClient .Do (req )
0 commit comments