Skip to content

Commit 471a188

Browse files
committed
Add data source sumologic_partition
1 parent e88522e commit 471a188

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

sumologic/sumologic_partition.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,47 @@ func (s *Client) UpdatePartition(spartition Partition) error {
6363
return err
6464
}
6565

66+
func (s *Client) ListPartitions() ([]Partition, error) {
67+
var listPartitionResp ListPartitionResp
68+
69+
data, err := s.Get("v1/partitions")
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
err = json.Unmarshal(data, &listPartitionResp)
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
spartitions := listPartitionResp.Data
80+
81+
for listPartitionResp.Next != "" {
82+
data, err = s.Get("v1/partitions?token=" + listPartitionResp.Next)
83+
if err != nil {
84+
return nil, err
85+
}
86+
87+
listPartitionResp.Reset()
88+
89+
err = json.Unmarshal(data, &listPartitionResp)
90+
if err != nil {
91+
return nil, err
92+
}
93+
94+
spartitions = append(spartitions, listPartitionResp.Data...)
95+
}
96+
97+
var activePartitions []Partition
98+
for _, partition := range spartitions {
99+
if partition.IsActive {
100+
activePartitions = append(activePartitions, partition)
101+
}
102+
}
103+
104+
return activePartitions, nil
105+
}
106+
66107
type Partition struct {
67108
ID string `json:"id,omitempty"`
68109
Name string `json:"name"`
@@ -77,3 +118,13 @@ type Partition struct {
77118
ReduceRetentionPeriodImmediately bool `json:"reduceRetentionPeriodImmediately,omitempty"`
78119
IsIncludedInDefaultSearch *bool `json:"isIncludedInDefaultSearch,omitempty"`
79120
}
121+
122+
type ListPartitionResp struct {
123+
Data []Partition `json:"data"`
124+
Next string `json:"next"`
125+
}
126+
127+
func (s *ListPartitionResp) Reset() {
128+
s.Data = nil
129+
s.Next = ""
130+
}

0 commit comments

Comments
 (0)