Skip to content

Commit 998ccb4

Browse files
authored
Add support for count action (#12)
1 parent cd99289 commit 998ccb4

File tree

3 files changed

+161
-138
lines changed

3 files changed

+161
-138
lines changed

config.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ type bouncerConfig struct {
3131
}
3232

3333
type AclConfig struct {
34-
WebACLName string `yaml:"web_acl_name"`
35-
RuleGroupName string `yaml:"rule_group_name"`
36-
Region string `yaml:"region"`
37-
Scope string `yaml:"scope"`
38-
IpsetPrefix string `yaml:"ipset_prefix"`
39-
FallbackAction string `yaml:"fallback_action"`
40-
AWSProfile string `yaml:"aws_profile"`
41-
IPHeader string `yaml:"ip_header"`
42-
IPHeaderPosition string `yaml:"ip_header_position"`
43-
Capacity int `yaml:"capacity"`
34+
WebACLName string `yaml:"web_acl_name"`
35+
RuleGroupName string `yaml:"rule_group_name"`
36+
Region string `yaml:"region"`
37+
Scope string `yaml:"scope"`
38+
IpsetPrefix string `yaml:"ipset_prefix"`
39+
FallbackAction string `yaml:"fallback_action"`
40+
AWSProfile string `yaml:"aws_profile"`
41+
IPHeader string `yaml:"ip_header"`
42+
IPHeaderPosition string `yaml:"ip_header_position"`
43+
Capacity int `yaml:"capacity"`
44+
CloudWatchEnabled bool `yaml:"cloudwatch_enabled"`
45+
CloudWatchMetricName string `yaml:"cloudwatch_metric_name"`
46+
SampleRequests bool `yaml:"sample_requests"`
4447
}
4548

46-
var validActions = []string{"ban", "captcha"}
49+
var validActions = []string{"ban", "captcha", "count"}
4750
var validScopes = []string{"REGIONAL", "CLOUDFRONT"}
4851
var validIpHeaderPosition = []string{"FIRST", "LAST", "ANY"}
4952

@@ -101,6 +104,20 @@ func getConfigFromEnv(config *bouncerConfig) {
101104
log.Warnf("Invalid value for %s: %s", key, value)
102105
acl.Capacity = 300
103106
}
107+
case "CLOUDWATCH_ENABLED":
108+
acl.CloudWatchEnabled, err = strconv.ParseBool(value)
109+
if err != nil {
110+
log.Warnf("Invalid value for %s: %s, defaulting to false", key, value)
111+
acl.CloudWatchEnabled = false
112+
}
113+
case "CLOUDWATCH_METRIC_NAME":
114+
acl.CloudWatchMetricName = value
115+
case "SAMPLE_REQUESTS":
116+
acl.SampleRequests, err = strconv.ParseBool(value)
117+
if err != nil {
118+
log.Warnf("Invalid value for %s: %s, defaulting to false", key, value)
119+
acl.SampleRequests = false
120+
}
104121
}
105122
} else {
106123
switch key {
@@ -234,6 +251,10 @@ func newConfig(configPath string) (bouncerConfig, error) {
234251
}
235252
}
236253

254+
if len(config.SupportedActions) == 0 {
255+
config.SupportedActions = validActions
256+
}
257+
237258
if len(config.WebACLConfig) == 0 {
238259
return bouncerConfig{}, fmt.Errorf("waf_config is required")
239260
}

utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,17 @@ func removeIpSetFromSlice(sets []*WAFIpSet, ipset *WAFIpSet) []*WAFIpSet {
4848
}
4949
return sets
5050
}
51+
52+
func uniqueStrPtr(s []*string) []*string {
53+
m := make(map[*string]bool)
54+
for _, v := range s {
55+
if _, ok := m[v]; !ok {
56+
m[v] = true
57+
}
58+
}
59+
var result []*string
60+
for k := range m {
61+
result = append(result, k)
62+
}
63+
return result
64+
}

0 commit comments

Comments
 (0)