-
Notifications
You must be signed in to change notification settings - Fork 0
/
filteringrules.go
171 lines (130 loc) · 7.1 KB
/
filteringrules.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package filteringrules
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/SecurityGeekIO/zscaler-sdk-go/zia/services/common"
)
const (
firewallRulesEndpoint = "/firewallFilteringRules"
)
type FirewallFilteringRules struct {
// Unique identifier for the Firewall Filtering policy rule
ID int `json:"id,omitempty"`
// Name of the Firewall Filtering policy rule
Name string `json:"name,omitempty"`
// Rule order number of the Firewall Filtering policy rule
Order int `json:"order"`
// Admin rank of the Firewall Filtering policy rule
Rank int `json:"rank"`
AccessControl string `json:"accessControl,omitempty"`
EnableFullLogging bool `json:"enableFullLogging"`
// The action the Firewall Filtering policy rule takes when packets match the rule
Action string `json:"action,omitempty"`
// Determines whether the Firewall Filtering policy rule is enabled or disabled
State string `json:"state,omitempty"`
// Additional information about the rule
Description string `json:"description,omitempty"`
// Timestamp when the rule was last modified. Ignored if the request is POST or PUT. For GET, ignored if or the rule is current version.
LastModifiedTime int `json:"lastModifiedTime,omitempty"`
LastModifiedBy *common.IDNameExtensions `json:"lastModifiedBy,omitempty"`
// User-defined source IP addresses for which the rule is applicable. If not set, the rule is not restricted to a specific source IP address.
SrcIps []string `json:"srcIps,omitempty"`
// List of destination IP addresses for which the rule is applicable. CIDR notation can be used for destination IP addresses. If not set, the rule is not restricted to a specific destination addresses unless specified by destCountries, destIpGroups or destIpCategories.
DestAddresses []string `json:"destAddresses,omitempty"`
// IP address categories of destination for which the DNAT rule is applicable. If not set, the rule is not restricted to specific destination IP categories.
DestIpCategories []string `json:"destIpCategories,omitempty"`
// Destination countries for which the rule is applicable. If not set, the rule is not restricted to specific destination countries.
DestCountries []string `json:"destCountries,omitempty"`
// User-defined network service applications on which the rule is applied. If not set, the rule is not restricted to a specific network service application.
NwApplications []string `json:"nwApplications,omitempty"`
// If set to true, the default rule is applied
DefaultRule bool `json:"defaultRule"`
// If set to true, a predefined rule is applied
Predefined bool `json:"predefined"`
// The locations to which the Firewall Filtering policy rule applies
Locations []common.IDNameExtensions `json:"locations,omitempty"`
// The location groups to which the Firewall Filtering policy rule applies
LocationsGroups []common.IDNameExtensions `json:"locationGroups,omitempty"`
// The departments to which the Firewall Filtering policy rule applies
Departments []common.IDNameExtensions `json:"departments,omitempty"`
// The groups to which the Firewall Filtering policy rule applies
Groups []common.IDNameExtensions `json:"groups,omitempty"`
// The users to which the Firewall Filtering policy rule applies
Users []common.IDNameExtensions `json:"users,omitempty"`
// The time interval in which the Firewall Filtering policy rule applies
TimeWindows []common.IDNameExtensions `json:"timeWindows,omitempty"`
// User-defined network service application group on which the rule is applied. If not set, the rule is not restricted to a specific network service application group.
NwApplicationGroups []common.IDNameExtensions `json:"nwApplicationGroups,omitempty"`
// Application services on which this rule is applied
AppServices []common.IDNameExtensions `json:"appServices,omitempty"`
// Application service groups on which this rule is applied
AppServiceGroups []common.IDNameExtensions `json:"appServiceGroups,omitempty"`
// Labels that are applicable to the rule.
Labels []common.IDNameExtensions `json:"labels,omitempty"`
// User-defined destination IP address groups on which the rule is applied. If not set, the rule is not restricted to a specific destination IP address group.
// Note: For organizations that have enabled IPv6, the destIpv6Groups field lists the IPv6 source address groups for which the rule is applicable.
DestIpGroups []common.IDNameExtensions `json:"destIpGroups,omitempty"`
// User-defined network services on which the rule is applied. If not set, the rule is not restricted to a specific network service.
NwServices []common.IDNameExtensions `json:"nwServices,omitempty"`
// User-defined network service applications on which the rule is applied. If not set, the rule is not restricted to a specific network service application.
NwServiceGroups []common.IDNameExtensions `json:"nwServiceGroups,omitempty"`
// Source IP address groups for which the rule is applicable. If not set, the rule is not restricted to a specific source IP address group.
SrcIpGroups []common.IDNameExtensions `json:"srcIpGroups,omitempty"`
}
func (service *Service) Get(ruleID int) (*FirewallFilteringRules, error) {
var rule FirewallFilteringRules
err := service.Client.Read(fmt.Sprintf("%s/%d", firewallRulesEndpoint, ruleID), &rule)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning firewall rule from Get: %d", rule.ID)
return &rule, nil
}
func (service *Service) GetByName(ruleName string) (*FirewallFilteringRules, error) {
var rules []FirewallFilteringRules
err := common.ReadAllPagesWithFilters(service.Client, firewallRulesEndpoint, map[string]string{"search": ruleName}, &rules)
if err != nil {
return nil, err
}
for _, rule := range rules {
if strings.EqualFold(rule.Name, ruleName) {
return &rule, nil
}
}
return nil, fmt.Errorf("no firewall rule found with name: %s", ruleName)
}
func (service *Service) Create(rule *FirewallFilteringRules) (*FirewallFilteringRules, error) {
resp, err := service.Client.Create(firewallRulesEndpoint, *rule)
if err != nil {
return nil, err
}
createdRules, ok := resp.(*FirewallFilteringRules)
if !ok {
return nil, errors.New("object returned from api was not a rule Pointer")
}
service.Client.Logger.Printf("[DEBUG]returning rule from create: %d", createdRules.ID)
return createdRules, nil
}
func (service *Service) Update(ruleID int, rules *FirewallFilteringRules) (*FirewallFilteringRules, error) {
resp, err := service.Client.UpdateWithPut(fmt.Sprintf("%s/%d", firewallRulesEndpoint, ruleID), *rules)
if err != nil {
return nil, err
}
updatedRules, _ := resp.(*FirewallFilteringRules)
service.Client.Logger.Printf("[DEBUG]returning firewall rule from update: %d", updatedRules.ID)
return updatedRules, nil
}
func (service *Service) Delete(ruleID int) (*http.Response, error) {
err := service.Client.Delete(fmt.Sprintf("%s/%d", firewallRulesEndpoint, ruleID))
if err != nil {
return nil, err
}
return nil, nil
}
func (service *Service) GetAll() ([]FirewallFilteringRules, error) {
var rules []FirewallFilteringRules
err := common.ReadAllPages(service.Client, firewallRulesEndpoint, &rules)
return rules, err
}