forked from go-auth0/auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule.go
48 lines (36 loc) · 1.27 KB
/
rule.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
package management
type Rule struct {
// The rule's identifier.
ID string `json:"id,omitempty"`
// The name of the rule. Can only contain alphanumeric characters, spaces
// and '-'. Can neither start nor end with '-' or spaces.
Name string `json:"name,omitempty"`
// A script that contains the rule's code.
Script string `json:"script,omitempty"`
// The rule's order in relation to other rules. A rule with a lower order
// than another rule executes first. If no order is provided it will
// automatically be one greater than the current maximum.
Order int `json:"order,omitempty"`
// Enabled should be set to true if the rule is enabled, false otherwise.
Enabled bool `json:"enabled,omitempty"`
}
type RuleManager struct {
m *Management
}
func NewRuleManager(m *Management) *RuleManager {
return &RuleManager{m}
}
func (rm *RuleManager) Create(r *Rule) error {
return rm.m.post(rm.m.uri("rules"), r)
}
func (rm *RuleManager) Read(id string, opts ...Option) (*Rule, error) {
r := new(Rule)
err := rm.m.get(rm.m.uri("rules", id)+rm.m.q(opts), r)
return r, err
}
func (rm *RuleManager) Update(id string, r *Rule) (err error) {
return rm.m.patch(rm.m.uri("rules", id), r)
}
func (rm *RuleManager) Delete(id string) (err error) {
return rm.m.delete(rm.m.uri("rules", id))
}