forked from go-auth0/auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule_config.go
44 lines (36 loc) · 966 Bytes
/
rule_config.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
package management
type RuleConfig struct {
// The key for a RuleConfigs config
Key string `json:"key,omitempty"`
// The value for the rules config
Value string `json:"value,omitempty"`
}
type RuleConfigManager struct {
m *Management
}
func NewRuleConfigManager(m *Management) *RuleConfigManager {
return &RuleConfigManager{m}
}
func (rm *RuleConfigManager) Upsert(key string, r *RuleConfig) (err error) {
return rm.m.put(rm.m.getURI("rules-configs", key), r)
}
func (rm *RuleConfigManager) Read(key string) (*RuleConfig, error) {
var rs []*RuleConfig
err := rm.m.get(rm.m.getURI("rules-configs"), &rs)
if err != nil {
return nil, err
}
for _, r := range rs {
if r.Key == key {
return r, nil
}
}
return nil, &managementError{
StatusCode: 404,
Err: "Not Found",
Message: "Rule config not found",
}
}
func (rm *RuleConfigManager) Delete(key string) (err error) {
return rm.m.delete(rm.m.getURI("rules-configs", key))
}