-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipdestinationgroups.go
106 lines (84 loc) · 3.68 KB
/
ipdestinationgroups.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ipdestinationgroups
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/common"
)
const (
ipDestinationGroupsEndpoint = "/ipDestinationGroups"
)
type IPDestinationGroups struct {
// Unique identifer for the destination IP group
ID int `json:"id"`
// Destination IP group name
Name string `json:"name,omitempty"`
// Additional information about the destination IP group
Description string `json:"description,omitempty"`
// Destination IP group type (i.e., the group can contain destination IP addresses or FQDNs)
Type string `json:"type,omitempty"`
// Destination IP addresses, FQDNs, or wildcard FQDNs added to the group.
Addresses []string `json:"addresses,omitempty"`
// Destination IP address URL categories. You can identify destinations based on the URL category of the domain.
IPCategories []string `json:"ipCategories,omitempty"`
// Destination IP address countries. You can identify destinations based on the location of a server.
Countries []string `json:"countries,omitempty"`
// If set to true, the destination IP address group is non-editable. This field is applicable only to predefined IP address groups, which cannot be modified.
IsNonEditable bool `json:"isNonEditable,omitempty"`
}
func (service *Service) Get(ipGroupID int) (*IPDestinationGroups, error) {
var ipDestinationGroups IPDestinationGroups
err := service.Client.Read(fmt.Sprintf("%s/%d", ipDestinationGroupsEndpoint, ipGroupID), &ipDestinationGroups)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning ip destination group from Get: %d", ipDestinationGroups.ID)
return &ipDestinationGroups, nil
}
func (service *Service) GetByName(ipDestinationGroupsName string) (*IPDestinationGroups, error) {
var ipDestinationGroups []IPDestinationGroups
err := common.ReadAllPages(service.Client, ipDestinationGroupsEndpoint, &ipDestinationGroups)
if err != nil {
return nil, err
}
for _, ipDestinationGroup := range ipDestinationGroups {
if strings.EqualFold(ipDestinationGroup.Name, ipDestinationGroupsName) {
return &ipDestinationGroup, nil
}
}
return nil, fmt.Errorf("no ip destination group found with name: %s", ipDestinationGroupsName)
}
func (service *Service) Create(ipGroupID *IPDestinationGroups) (*IPDestinationGroups, error) {
resp, err := service.Client.Create(ipDestinationGroupsEndpoint, *ipGroupID)
if err != nil {
return nil, err
}
createdIPDestinationGroups, ok := resp.(*IPDestinationGroups)
if !ok {
return nil, errors.New("object returned from api was not an ip destination group pointer")
}
service.Client.Logger.Printf("[DEBUG]returning ip destination group from create: %d", createdIPDestinationGroups.ID)
return createdIPDestinationGroups, nil
}
func (service *Service) Update(ipGroupID int, ipGroup *IPDestinationGroups) (*IPDestinationGroups, *http.Response, error) {
resp, err := service.Client.UpdateWithPut(fmt.Sprintf("%s/%d", ipDestinationGroupsEndpoint, ipGroupID), *ipGroup)
if err != nil {
return nil, nil, err
}
updatedIPDestinationGroups, _ := resp.(*IPDestinationGroups)
service.Client.Logger.Printf("[DEBUG]returning ip destination group from update: %d", updatedIPDestinationGroups.ID)
return updatedIPDestinationGroups, nil, nil
}
func (service *Service) Delete(ipGroupID int) (*http.Response, error) {
err := service.Client.Delete(fmt.Sprintf("%s/%d", ipDestinationGroupsEndpoint, ipGroupID))
if err != nil {
return nil, err
}
return nil, nil
}
func (service *Service) GetAll() ([]IPDestinationGroups, error) {
var ipDestinationGroups []IPDestinationGroups
err := common.ReadAllPages(service.Client, ipDestinationGroupsEndpoint, &ipDestinationGroups)
return ipDestinationGroups, err
}