mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-17 13:54:59 +00:00
refactor: use preexisting structs in config
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,20 +36,10 @@ type RobotsRule struct {
|
|||||||
IsBlacklist bool // true if this is a specifically denied user agent
|
IsBlacklist bool // true if this is a specifically denied user agent
|
||||||
}
|
}
|
||||||
|
|
||||||
type Weight struct {
|
|
||||||
Adjust int `yaml:"adjust" json:"adjust"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Challenge struct {
|
|
||||||
Algorithm string `yaml:"algorithm,omitempty" json:"algorithm,omitempty"`
|
|
||||||
Difficulty int `yaml:"difficulty,omitempty" json:"difficulty,omitempty"`
|
|
||||||
ReportAs int `yaml:"report_as,omitempty" json:"report_as,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AnubisRule struct {
|
type AnubisRule struct {
|
||||||
Expression map[string]interface{} `yaml:"expression,omitempty" json:"expression,omitempty"`
|
Expression map[string]interface{} `yaml:"expression,omitempty" json:"expression,omitempty"`
|
||||||
Challenge *Challenge `yaml:"challenge,omitempty" json:"challenge,omitempty"`
|
Challenge *config.ChallengeRules `yaml:"challenge,omitempty" json:"challenge,omitempty"`
|
||||||
Weight *Weight `yaml:"weight,omitempty" json:"weight,omitempty"`
|
Weight *config.Weight `yaml:"weight,omitempty" json:"weight,omitempty"`
|
||||||
Name string `yaml:"name" json:"name"`
|
Name string `yaml:"name" json:"name"`
|
||||||
Action string `yaml:"action" json:"action"`
|
Action string `yaml:"action" json:"action"`
|
||||||
}
|
}
|
||||||
@@ -249,7 +241,7 @@ func convertToAnubisRules(robotsRules []RobotsRule) []AnubisRule {
|
|||||||
rule := AnubisRule{
|
rule := AnubisRule{
|
||||||
Name: fmt.Sprintf("%s-crawl-delay-%d", *policyName, ruleCounter),
|
Name: fmt.Sprintf("%s-crawl-delay-%d", *policyName, ruleCounter),
|
||||||
Action: "WEIGH",
|
Action: "WEIGH",
|
||||||
Weight: &Weight{Adjust: *crawlDelay},
|
Weight: &config.Weight{Adjust: *crawlDelay},
|
||||||
}
|
}
|
||||||
|
|
||||||
if userAgent == "*" {
|
if userAgent == "*" {
|
||||||
@@ -277,7 +269,7 @@ func convertToAnubisRules(robotsRules []RobotsRule) []AnubisRule {
|
|||||||
// This would block everything - convert to a weight adjustment instead
|
// This would block everything - convert to a weight adjustment instead
|
||||||
rule.Name = fmt.Sprintf("%s-global-restriction-%d", *policyName, ruleCounter)
|
rule.Name = fmt.Sprintf("%s-global-restriction-%d", *policyName, ruleCounter)
|
||||||
rule.Action = "WEIGH"
|
rule.Action = "WEIGH"
|
||||||
rule.Weight = &Weight{Adjust: 20} // Increase difficulty significantly
|
rule.Weight = &config.Weight{Adjust: 20} // Increase difficulty significantly
|
||||||
rule.Expression = map[string]interface{}{
|
rule.Expression = map[string]interface{}{
|
||||||
"single": "true", // Always applies
|
"single": "true", // Always applies
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type Weight struct {
|
type Weight struct {
|
||||||
Adjust int `json:"adjust"`
|
Adjust int `json:"adjust" yaml:"adjust"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user