Skip to content

Commit 687fe0f

Browse files
authored
Merge pull request #215 from SumoLogic/karthich-admin-recommended
Karthich admin recommended
2 parents 7605aa9 + 2523a09 commit 687fe0f

34 files changed

+226
-118
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package sumologic
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"time"
6+
)
7+
8+
func dataSourceSumologicAdminRecommendedFolder() *schema.Resource {
9+
return &schema.Resource{
10+
Read: dataSourceSumologicAdminRecommendedFolderRead,
11+
12+
Schema: map[string]*schema.Schema{
13+
"id": {
14+
Type: schema.TypeString,
15+
Optional: true,
16+
Computed: true,
17+
},
18+
"name": {
19+
Type: schema.TypeString,
20+
Optional: true,
21+
Computed: true,
22+
},
23+
"description": {
24+
Type: schema.TypeString,
25+
Optional: true,
26+
Computed: true,
27+
},
28+
},
29+
Timeouts: &schema.ResourceTimeout{
30+
Read: schema.DefaultTimeout(1 * time.Minute),
31+
},
32+
}
33+
}
34+
35+
func dataSourceSumologicAdminRecommendedFolderRead(d *schema.ResourceData, meta interface{}) error {
36+
c := meta.(*Client)
37+
38+
adminRecommendedFolder, err := c.getAdminRecommendedFolder(d.Timeout(schema.TimeoutRead))
39+
40+
if err != nil {
41+
return err
42+
}
43+
44+
d.SetId(adminRecommendedFolder.ID)
45+
d.Set("name", adminRecommendedFolder.Name)
46+
d.Set("description", adminRecommendedFolder.Description)
47+
48+
return nil
49+
}

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)))
86+
data, _, err := s.Get(fmt.Sprintf("v1/roles?name=%s", url.QueryEscape(name)), false)
8787
if err != nil {
8888
return nil, err
8989
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package sumologic

sumologic/provider.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ func Provider() terraform.ResourceProvider {
7777
"sumologic_token": resourceSumologicToken(),
7878
},
7979
DataSourcesMap: map[string]*schema.Resource{
80-
"sumologic_caller_identity": dataSourceSumologicCallerIdentity(),
81-
"sumologic_collector": dataSourceSumologicCollector(),
82-
"sumologic_http_source": dataSourceSumologicHTTPSource(),
83-
"sumologic_personal_folder": dataSourceSumologicPersonalFolder(),
84-
"sumologic_my_user_id": dataSourceSumologicMyUserId(),
85-
"sumologic_role": dataSourceSumologicRole(),
80+
"sumologic_admin_recommended_folder": dataSourceSumologicAdminRecommendedFolder(),
81+
"sumologic_caller_identity": dataSourceSumologicCallerIdentity(),
82+
"sumologic_collector": dataSourceSumologicCollector(),
83+
"sumologic_http_source": dataSourceSumologicHTTPSource(),
84+
"sumologic_personal_folder": dataSourceSumologicPersonalFolder(),
85+
"sumologic_my_user_id": dataSourceSumologicMyUserId(),
86+
"sumologic_role": dataSourceSumologicRole(),
8687
},
8788
ConfigureFunc: providerConfigure,
8889
}

sumologic/resource_sumologic_saml_configuration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func testAccCheckSamlConfigurationExists(name string) resource.TestCheckFunc {
214214
}
215215
assertion_consumer_url := rs.Primary.Attributes["assertion_consumer_url"]
216216
if strings.EqualFold(assertion_consumer_url, "") {
217-
return fmt.Errorf("Assertion Consumer URL not found for Saml Configuration (id=%s)", id)
217+
return fmt.Errorf("Assertion Consumer URL not found for Saml Configuration (id=%s)", id)
218218
}
219219
return nil
220220
}

sumologic/sumologic_client.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *Client) GetWithCookies(urlPath string, cookies []*http.Cookie) ([]byte,
128128
return d, resp.Header.Get("ETag"), nil
129129
}
130130

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

@@ -138,6 +138,10 @@ func (s *Client) Post(urlPath string, payload interface{}) ([]byte, error) {
138138
return nil, err
139139
}
140140

141+
if isAdminMode {
142+
req.Header.Add("isAdminMode", "true")
143+
}
144+
141145
<-rateLimiter.C
142146
resp, err := s.httpClient.Do(req)
143147
if err != nil {
@@ -181,14 +185,14 @@ func (s *Client) PostRawPayload(urlPath string, payload string) ([]byte, error)
181185
return d, nil
182186
}
183187

184-
func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
188+
func (s *Client) Put(urlPath string, payload interface{}, isAdminMode bool) ([]byte, error) {
185189
SumoMutexKV.Lock(urlPath)
186190
defer SumoMutexKV.Unlock(urlPath)
187191

188192
relativeURL, _ := url.Parse(urlPath)
189193
sumoURL := s.BaseURL.ResolveReference(relativeURL)
190194

191-
_, etag, _ := s.Get(sumoURL.String())
195+
_, etag, _ := s.Get(sumoURL.String(), false)
192196

193197
body, _ := json.Marshal(payload)
194198
req, err := createNewRequest(http.MethodPut, sumoURL.String(), bytes.NewBuffer(body), s.AccessID, s.AccessKey)
@@ -197,6 +201,10 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
197201
}
198202
req.Header.Add("If-Match", etag)
199203

204+
if isAdminMode {
205+
req.Header.Add("isAdminMode", "true")
206+
}
207+
200208
<-rateLimiter.C
201209
resp, err := s.httpClient.Do(req)
202210
if err != nil {
@@ -216,7 +224,7 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
216224
return d, nil
217225
}
218226

219-
func (s *Client) Get(urlPath string) ([]byte, string, error) {
227+
func (s *Client) Get(urlPath string, isAdminMode bool) ([]byte, string, error) {
220228
relativeURL, _ := url.Parse(urlPath)
221229
sumoURL := s.BaseURL.ResolveReference(relativeURL)
222230

@@ -225,6 +233,10 @@ func (s *Client) Get(urlPath string) ([]byte, string, error) {
225233
return nil, "", err
226234
}
227235

236+
if isAdminMode {
237+
req.Header.Add("isAdminMode", "true")
238+
}
239+
228240
<-rateLimiter.C
229241
resp, err := s.httpClient.Do(req)
230242
if err != nil {

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)
31+
body, err := s.Post(urlPath, request, false)
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)
49+
body, _, err := s.Get(urlPath, false)
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)
84+
_, err := s.Put(url, request, false)
8585

8686
return err
8787
}

sumologic/sumologic_cloudsyslog_source.go

Lines changed: 3 additions & 5 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)
24+
body, err := s.Post(urlPath, request, false)
2525

2626
if err != nil {
2727
return -1, err
@@ -39,9 +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(
43-
fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, sourceID),
44-
)
42+
body, _, err := s.Get(fmt.Sprintf("v1/collectors/%d/sources/%d", collectorID, sourceID), false)
4543
if err != nil {
4644
return nil, err
4745
}
@@ -75,7 +73,7 @@ func (s *Client) UpdateCloudSyslogSource(source CloudSyslogSource, collectorID i
7573
}
7674

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

8078
return err
8179
}

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))
9+
data, _, err := s.Get(fmt.Sprintf("v1/collectors/%d", id), false)
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))
28+
data, _, err := s.Get(fmt.Sprintf("v1/collectors/name/%s", name), false)
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)
60+
responseBody, err := s.Post("v1/collectors", request, false)
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)
81+
_, err := s.Put(url, request, false)
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)
17+
rawConnection, _, err := s.Get(url, false)
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)
63+
responseData, err := s.Post(url, connection, false)
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)
86+
_, err := s.Put(url, connection, false)
8787

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

0 commit comments

Comments
 (0)