-
Notifications
You must be signed in to change notification settings - Fork 4
/
integrity.go
80 lines (68 loc) · 2 KB
/
integrity.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
package limacharlie
type IntegrityRule struct {
Patterns []string `json:"patterns"`
Filters IntegrityRuleFilter `json:"filters"`
CreatedBy string `json:"by,omitempty"`
LastUpdated uint64 `json:"updated,omitempty"`
}
type IntegrityRuleFilter struct {
Tags []string `json:"tags" yaml:"tags"`
Platforms []string `json:"platforms" yaml:"platforms"`
}
func (ir IntegrityRule) WithPatterns(patterns []string) IntegrityRule {
ir.Patterns = append(ir.Patterns, patterns...)
return ir
}
func (ir IntegrityRule) WithTags(tags []string) IntegrityRule {
ir.Filters.Tags = append(ir.Filters.Tags, tags...)
return ir
}
func (ir IntegrityRule) WithPlatforms(platforms []string) IntegrityRule {
ir.Filters.Platforms = append(ir.Filters.Platforms, platforms...)
return ir
}
type IntegrityRuleName = string
type IntegrityRulesByName = map[IntegrityRuleName]IntegrityRule
func (org Organization) integrity(responseData interface{}, action string, req Dict) error {
reqData := req
reqData["action"] = action
return org.client.serviceRequest(responseData, "integrity", reqData, false)
}
func (org Organization) IntegrityRules() (IntegrityRulesByName, error) {
resp := IntegrityRulesByName{}
if err := org.integrity(&resp, "list_rules", Dict{}); err != nil {
return IntegrityRulesByName{}, err
}
return resp, nil
}
func (org Organization) IntegrityRuleAdd(ruleName IntegrityRuleName, rule IntegrityRule) error {
patterns := rule.Patterns
if patterns == nil {
patterns = []string{}
}
tags := rule.Filters.Tags
if tags == nil {
tags = []string{}
}
platforms := rule.Filters.Platforms
if platforms == nil {
platforms = []string{}
}
req := Dict{
"name": ruleName,
"patterns": patterns,
"tags": tags,
"platforms": platforms,
}
resp := Dict{}
err := org.integrity(&resp, "add_rule", req)
return err
}
func (org Organization) IntegrityRuleDelete(ruleName string) error {
req := Dict{
"name": ruleName,
}
resp := Dict{}
err := org.integrity(&resp, "remove_rule", req)
return err
}