mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-06-10 06:18:15 +00:00
Merge branch 'main' into Xe/small-sec-fixes
Signed-off-by: Xe Iaso <xe.iaso@techaro.lol>
This commit is contained in:
+15
-4
@@ -1,8 +1,6 @@
|
||||
package policy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/TecharoHQ/anubis/internal"
|
||||
"github.com/TecharoHQ/anubis/lib/config"
|
||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
||||
@@ -13,9 +11,22 @@ type Bot struct {
|
||||
Challenge *config.ChallengeRules
|
||||
Weight *config.Weight
|
||||
Name string
|
||||
Action config.Rule
|
||||
// hash caches the result of Hash() when populated at parse time, see ParseConfig
|
||||
hash string
|
||||
Action config.Rule
|
||||
}
|
||||
|
||||
// Hash returns a stable identifier for this Bot derived from its Name
|
||||
// and Rules. When the cached value is present (populated by
|
||||
// ParseConfig) it is returned directly; otherwise the hash is
|
||||
// recomputed on demand so callers do not have to know about the cache.
|
||||
func (b Bot) Hash() string {
|
||||
return internal.FastHash(fmt.Sprintf("%s::%s", b.Name, b.Rules.Hash()))
|
||||
if b.hash != "" {
|
||||
return b.hash
|
||||
}
|
||||
var rulesHash string
|
||||
if b.Rules != nil { // defensive, should never happen
|
||||
rulesHash = b.Rules.Hash()
|
||||
}
|
||||
return internal.FastHash(b.Name + "::" + rulesHash)
|
||||
}
|
||||
|
||||
@@ -219,6 +219,7 @@ func ParseConfig(ctx context.Context, fin io.Reader, fname string, defaultDiffic
|
||||
result.Impressum = c.Impressum
|
||||
|
||||
parsedBot.Rules = cl
|
||||
parsedBot.hash = parsedBot.Hash()
|
||||
|
||||
result.Bots = append(result.Bots, parsedBot)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user