Skip to content

Commit 14b97aa

Browse files
committed
Enable admin mode in provider
1 parent afe6fc3 commit 14b97aa

34 files changed

+119
-106
lines changed

sumologic/data_source_sumologic_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func dataSourceSumologicRoleRead(d *schema.ResourceData, meta interface{}) error
8383
}
8484

8585
func (s *Client) GetRoleName(name string) (*Role, error) {
86-
data, _, err := s.Get(fmt.Sprintf("v1/roles?name=%s", url.QueryEscape(name)), false)
86+
data, _, err := s.Get(fmt.Sprintf("v1/roles?name=%s", url.QueryEscape(name)))
8787
if err != nil {
8888
return nil, err
8989
}

sumologic/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func Provider() terraform.ResourceProvider {
3636
Optional: true,
3737
Default: os.Getenv("SUMOLOGIC_BASE_URL"),
3838
},
39+
"admin": {
40+
Type: schema.TypeBool,
41+
Optional: true,
42+
Default: false,
43+
},
3944
},
4045
ResourcesMap: map[string]*schema.Resource{
4146
"sumologic_cse_network_block": resourceSumologicCSENetworkBlock(),
@@ -118,6 +123,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
118123
accessKey := d.Get("access_key").(string)
119124
environment := d.Get("environment").(string)
120125
baseUrl := d.Get("base_url").(string)
126+
isAdmin := d.Get("admin").(bool)
121127

122128
msg := ""
123129
if accessId == "" {
@@ -152,5 +158,6 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
152158
accessKey,
153159
environment,
154160
baseUrl,
161+
isAdmin,
155162
)
156163
}

sumologic/resource_sumologic_dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ func getTimeRangeBoundary(tfRangeBoundary map[string]interface{}) interface{} {
948948
}
949949

950950
func getTopologyLabel(tfTopologyLabel map[string]interface{}) *TopologyLabel {
951-
if items := tfTopologyLabel["data"].([]interface{}); len(items) == 1 {
951+
if items := tfTopologyLabel["data"].([]interface{}); len(items) > 0 {
952952
labelMap := make(map[string][]string)
953953
for _, item := range items {
954954
dataItem := item.(map[string]interface{})

sumologic/sumologic_client.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Client struct {
2121
AccessKey string
2222
Environment string
2323
BaseURL *url.URL
24+
IsAdmin bool
2425
httpClient HttpClient
2526
}
2627

@@ -128,7 +129,7 @@ func (s *Client) GetWithCookies(urlPath string, cookies []*http.Cookie) ([]byte,
128129
return d, resp.Header.Get("ETag"), nil
129130
}
130131

131-
func (s *Client) Post(urlPath string, payload interface{}, isAdminMode bool) ([]byte, error) {
132+
func (s *Client) Post(urlPath string, payload interface{}) ([]byte, error) {
132133
relativeURL, _ := url.Parse(urlPath)
133134
sumoURL := s.BaseURL.ResolveReference(relativeURL)
134135

@@ -138,7 +139,7 @@ func (s *Client) Post(urlPath string, payload interface{}, isAdminMode bool) ([]
138139
return nil, err
139140
}
140141

141-
if isAdminMode {
142+
if s.IsAdmin {
142143
req.Header.Add("isAdminMode", "true")
143144
}
144145

@@ -185,11 +186,11 @@ func (s *Client) PostRawPayload(urlPath string, payload string) ([]byte, error)
185186
return d, nil
186187
}
187188

188-
func (s *Client) Put(urlPath string, payload interface{}, isAdminMode bool) ([]byte, error) {
189+
func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
189190
relativeURL, _ := url.Parse(urlPath)
190191
sumoURL := s.BaseURL.ResolveReference(relativeURL)
191192

192-
_, etag, _ := s.Get(sumoURL.String(), false)
193+
_, etag, _ := s.Get(sumoURL.String())
193194

194195
body, _ := json.Marshal(payload)
195196
req, err := createNewRequest(http.MethodPut, sumoURL.String(), bytes.NewBuffer(body), s.AccessID, s.AccessKey)
@@ -198,7 +199,7 @@ func (s *Client) Put(urlPath string, payload interface{}, isAdminMode bool) ([]b
198199
}
199200
req.Header.Add("If-Match", etag)
200201

201-
if isAdminMode {
202+
if s.IsAdmin {
202203
req.Header.Add("isAdminMode", "true")
203204
}
204205

@@ -221,7 +222,7 @@ func (s *Client) Put(urlPath string, payload interface{}, isAdminMode bool) ([]b
221222
return d, nil
222223
}
223224

224-
func (s *Client) Get(urlPath string, isAdminMode bool) ([]byte, string, error) {
225+
func (s *Client) Get(urlPath string) ([]byte, string, error) {
225226
relativeURL, _ := url.Parse(urlPath)
226227
sumoURL := s.BaseURL.ResolveReference(relativeURL)
227228

@@ -230,7 +231,7 @@ func (s *Client) Get(urlPath string, isAdminMode bool) ([]byte, string, error) {
230231
return nil, "", err
231232
}
232233

233-
if isAdminMode {
234+
if s.IsAdmin {
234235
req.Header.Add("isAdminMode", "true")
235236
}
236237

@@ -264,6 +265,10 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
264265
return nil, err
265266
}
266267

268+
if s.IsAdmin {
269+
req.Header.Add("isAdminMode", "true")
270+
}
271+
267272
<-rateLimiter.C
268273
resp, err := s.httpClient.Do(req)
269274
if err != nil {
@@ -283,12 +288,13 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
283288
return d, nil
284289
}
285290

286-
func NewClient(accessID, accessKey, environment, base_url string) (*Client, error) {
291+
func NewClient(accessID, accessKey, environment, base_url string, admin bool) (*Client, error) {
287292
client := Client{
288293
AccessID: accessID,
289294
AccessKey: accessKey,
290295
httpClient: http.DefaultClient,
291296
Environment: environment,
297+
IsAdmin: admin,
292298
}
293299

294300
if base_url == "" {

sumologic/sumologic_cloud_to_cloud_source.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s *Client) CreateCloudToCloudSource(source CloudToCloudSource, collectorID
2828

2929
urlPath := fmt.Sprintf("v1/collectors/%d/sources", collectorID)
3030

31-
body, err := s.Post(urlPath, request, false)
31+
body, err := s.Post(urlPath, request)
3232

3333
if err != nil {
3434
return -1, err
@@ -46,7 +46,7 @@ func (s *Client) CreateCloudToCloudSource(source CloudToCloudSource, collectorID
4646

4747
func (s *Client) GetCloudToCloudSource(collectorID, sourceID int) (*CloudToCloudSource, error) {
4848
urlPath := fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, sourceID)
49-
body, _, err := s.Get(urlPath, false)
49+
body, _, err := s.Get(urlPath)
5050

5151
if err != nil {
5252
return nil, err
@@ -81,7 +81,7 @@ func (s *Client) UpdateCloudToCloudSource(source CloudToCloudSource, collectorID
8181
Source: source,
8282
}
8383

84-
_, err := s.Put(url, request, false)
84+
_, err := s.Put(url, request)
8585

8686
return err
8787
}

sumologic/sumologic_cloudsyslog_source.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *Client) CreateCloudsyslogSource(cloudSyslogSource CloudSyslogSource, co
2121
}
2222

2323
urlPath := fmt.Sprintf("v1/collectors/%d/sources", collectorID)
24-
body, err := s.Post(urlPath, request, false)
24+
body, err := s.Post(urlPath, request)
2525

2626
if err != nil {
2727
return -1, err
@@ -39,7 +39,7 @@ func (s *Client) CreateCloudsyslogSource(cloudSyslogSource CloudSyslogSource, co
3939

4040
func (s *Client) GetCloudSyslogSource(collectorID, sourceID int) (*CloudSyslogSource, error) {
4141

42-
body, _, err := s.Get(fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, sourceID), false)
42+
body, _, err := s.Get(fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, sourceID))
4343
if err != nil {
4444
return nil, err
4545
}
@@ -73,7 +73,7 @@ func (s *Client) UpdateCloudSyslogSource(source CloudSyslogSource, collectorID i
7373
}
7474

7575
urlPath := fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, source.ID)
76-
_, err := s.Put(urlPath, request, false)
76+
_, err := s.Put(urlPath, request)
7777

7878
return err
7979
}

sumologic/sumologic_collectors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func (s *Client) GetCollector(id int) (*Collector, error) {
9-
data, _, err := s.Get(fmt.Sprintf("v1/collectors/%d", id), false)
9+
data, _, err := s.Get(fmt.Sprintf("v1/collectors/%d", id))
1010
if err != nil {
1111
return nil, err
1212
}
@@ -25,7 +25,7 @@ func (s *Client) GetCollector(id int) (*Collector, error) {
2525
}
2626

2727
func (s *Client) GetCollectorName(name string) (*Collector, error) {
28-
data, _, err := s.Get(fmt.Sprintf("v1/collectors/name/%s", name), false)
28+
data, _, err := s.Get(fmt.Sprintf("v1/collectors/name/%s", name))
2929
if err != nil {
3030
return nil, err
3131
}
@@ -57,7 +57,7 @@ func (s *Client) CreateCollector(collector Collector) (int64, error) {
5757

5858
var response CollectorResponse
5959

60-
responseBody, err := s.Post("v1/collectors", request, false)
60+
responseBody, err := s.Post("v1/collectors", request)
6161
if err != nil {
6262
return -1, err
6363
}
@@ -78,7 +78,7 @@ func (s *Client) UpdateCollector(collector Collector) error {
7878
Collector: collector,
7979
}
8080

81-
_, err := s.Put(url, request, false)
81+
_, err := s.Put(url, request)
8282

8383
return err
8484
}

sumologic/sumologic_connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (s *Client) GetConnection(id string) (*Connection, error) {
1414
url := fmt.Sprintf("v1/connections/%s", id)
1515
log.Printf("connection read url: %s", url)
1616

17-
rawConnection, _, err := s.Get(url, false)
17+
rawConnection, _, err := s.Get(url)
1818
if err != nil {
1919
log.Printf("SSAIN: The err: %s", err.Error())
2020
if strings.Contains(err.Error(), "Connection with given ID does not exist.") {
@@ -60,7 +60,7 @@ func (s *Client) CreateConnection(connection Connection) (string, error) {
6060
log.Printf("Create connection url: %s", url)
6161

6262
connection.Type = convertConToDef(connection.Type)
63-
responseData, err := s.Post(url, connection, false)
63+
responseData, err := s.Post(url, connection)
6464
if err != nil {
6565
return "", err
6666
}
@@ -83,7 +83,7 @@ func (s *Client) UpdateConnection(connection Connection) error {
8383
log.Printf("Update connection job status url: %s", url)
8484

8585
connection.Type = convertConToDef(connection.Type)
86-
_, err := s.Put(url, connection, false)
86+
_, err := s.Put(url, connection)
8787

8888
log.Println("#### End connection update ####")
8989
return err

sumologic/sumologic_content.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (s *Client) GetContent(id string, timeout time.Duration) (*Content, error)
1616
log.Printf("[DEBUG] Exporting content with id: %s", id)
1717

1818
// Begin the content export job
19-
rawJID, err := s.Post(url, nil, false)
19+
rawJID, err := s.Post(url, nil)
2020
if err != nil {
2121
if strings.Contains(err.Error(), "Content with the given ID does not exist.") {
2222
return nil, nil
@@ -41,7 +41,7 @@ func (s *Client) GetContent(id string, timeout time.Duration) (*Content, error)
4141
// Request the results of the job
4242
var content Content
4343
url = fmt.Sprintf("v2/content/%s/export/%s/result", id, jid.ID)
44-
rawContent, _, err := s.Get(url, false)
44+
rawContent, _, err := s.Get(url)
4545
if err != nil {
4646
return nil, err
4747
}
@@ -115,7 +115,7 @@ func waitForJob(url string, timeout time.Duration, s *Client) (*Status, error) {
115115
},
116116
Refresh: func() (interface{}, string, error) {
117117
var status Status
118-
b, _, err := s.Get(url, false)
118+
b, _, err := s.Get(url)
119119
if err != nil {
120120
return nil, "", err
121121
}

sumologic/sumologic_dashboard.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func (s *Client) GetDashboard(id string) (*Dashboard, error) {
99
url := fmt.Sprintf("v2/dashboards/%s", id)
10-
data, _, err := s.Get(url, false)
10+
data, _, err := s.Get(url)
1111
if err != nil {
1212
return nil, err
1313
}
@@ -21,7 +21,7 @@ func (s *Client) GetDashboard(id string) (*Dashboard, error) {
2121
}
2222

2323
func (s *Client) CreateDashboard(dashboardReq Dashboard) (*Dashboard, error) {
24-
responseBody, err := s.Post("v2/dashboards", dashboardReq, false)
24+
responseBody, err := s.Post("v2/dashboards", dashboardReq)
2525
if err != nil {
2626
return nil, err
2727
}
@@ -42,7 +42,7 @@ func (s *Client) DeleteDashboard(id string) error {
4242

4343
func (s *Client) UpdateDashboard(dashboard Dashboard) error {
4444
url := fmt.Sprintf("v2/dashboards/%s", dashboard.ID)
45-
_, err := s.Put(url, dashboard, false)
45+
_, err := s.Put(url, dashboard)
4646
return err
4747
}
4848

0 commit comments

Comments
 (0)