-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathippool.go
More file actions
44 lines (38 loc) · 1.01 KB
/
Copy pathippool.go
File metadata and controls
44 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package fortimgr
import (
"context"
"fmt"
)
type apiIPPool struct {
Name string `json:"name"`
Type any `json:"type"`
StartIP string `json:"startip"`
EndIP string `json:"endip"`
Comment string `json:"comments"`
}
// ListIPPools retrieves IP pools from an ADOM.
// Pagination is applied transparently; see WithPageSize / WithPageCallback.
func (c *Client) ListIPPools(ctx context.Context, adom string, opts ...ListOption) ([]IPPool, error) {
if !c.LoggedIn() {
return nil, ErrNotLoggedIn
}
if !validName(adom) {
return nil, fmt.Errorf("%w: %q", ErrInvalidName, adom)
}
apiURL := fmt.Sprintf("/pm/config/adom/%s/obj/firewall/ippool", adom)
items, err := getPaged[apiIPPool](ctx, c, apiURL, nil, buildListConfig(opts))
if err != nil {
return nil, err
}
pools := make([]IPPool, len(items))
for i, p := range items {
pools[i] = IPPool{
Name: p.Name,
Type: mapEnum(toString(p.Type), ippoolTypes),
StartIP: p.StartIP,
EndIP: p.EndIP,
Comment: p.Comment,
}
}
return pools, nil
}