-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualip.go
More file actions
54 lines (48 loc) · 1.51 KB
/
Copy pathvirtualip.go
File metadata and controls
54 lines (48 loc) · 1.51 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
45
46
47
48
49
50
51
52
53
54
package fortimgr
import (
"context"
"fmt"
)
type apiVirtualIP struct {
Name string `json:"name"`
ExtIP any `json:"extip"`
MappedIP any `json:"mappedip"`
ExtIntf any `json:"extintf"`
PortForward any `json:"portforward"`
Protocol any `json:"protocol"`
ExtPort any `json:"extport"`
MappedPort any `json:"mappedport"`
Comment string `json:"comment"`
Color int `json:"color"`
}
// ListVirtualIPs retrieves Virtual IPs from an ADOM.
// Pagination is applied transparently; see WithPageSize / WithPageCallback.
func (c *Client) ListVirtualIPs(ctx context.Context, adom string, opts ...ListOption) ([]VirtualIP, 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/vip", adom)
items, err := getPaged[apiVirtualIP](ctx, c, apiURL, nil, buildListConfig(opts))
if err != nil {
return nil, err
}
virtualIPs := make([]VirtualIP, len(items))
for i, v := range items {
virtualIPs[i] = VirtualIP{
Name: v.Name,
ExtIP: toString(v.ExtIP),
MappedIP: formatMappedIP(v.MappedIP),
ExtIntf: toString(v.ExtIntf),
PortForward: mapEnum(toString(v.PortForward), enableDisable),
Protocol: mapEnum(toString(v.Protocol), vipProtocols),
ExtPort: toString(v.ExtPort),
MappedPort: toString(v.MappedPort),
Comment: v.Comment,
Color: v.Color,
}
}
return virtualIPs, nil
}