aboutsummaryrefslogtreecommitdiff
path: root/cmd/anubis
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2025-04-23 07:01:28 -0400
committerGitHub <noreply@github.com>2025-04-23 07:01:28 -0400
commit74e11505c6133ee1107811e81a0fd53e1d7876dd (patch)
tree9169e3fccc32657a9a84358bf7e6d7779fa704df /cmd/anubis
parent4e2c9de7085fbc8e5abe8d0659d807881d69769c (diff)
downloadanubis-74e11505c6133ee1107811e81a0fd53e1d7876dd.tar.xz
anubis-74e11505c6133ee1107811e81a0fd53e1d7876dd.zip
feat: enable loading config fragments (#321)
* feat(config): support importing bot policy snippets This changes the grammar of the Anubis bot policy config to allow importing from internal shared rules or external rules on the filesystem. This lets you create a file at `/data/policies/block-evilbot.yaml` and then import it with: ```yaml bots: - import: /data/policies/block-evilbot.yaml ``` This also explodes the default policy file into a bunch of composable snippets. Thank you @Aibrew for your example gitea Atom / RSS feed rules! Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(data): update botPolicies.json to use imports Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(cmd/anubis): extract bot policies with --extract-resources This allows a user that doesn't have anything but the Anubis binary to figure out what the default configuration does. * docs(data/botPolices.yaml): document import syntax in-line Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(lib/policy): better test importing from JSON snippets Signed-off-by: Xe Iaso <me@xeiaso.net> * docs(admin): Add import syntax documentation This documents the import syntax and is based on the block comment at the top of the default bot policy file. * docs(changelog): add note about importing snippets Signed-off-by: Xe Iaso <me@xeiaso.net> * style(lib/policy/config): use an error value instead of an inline error Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/anubis')
-rw-r--r--cmd/anubis/main.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go
index b7375ea..f47acec 100644
--- a/cmd/anubis/main.go
+++ b/cmd/anubis/main.go
@@ -27,6 +27,7 @@ import (
"time"
"github.com/TecharoHQ/anubis"
+ "github.com/TecharoHQ/anubis/data"
"github.com/TecharoHQ/anubis/internal"
libanubis "github.com/TecharoHQ/anubis/lib"
botPolicy "github.com/TecharoHQ/anubis/lib/policy"
@@ -184,6 +185,9 @@ func main() {
}
if *extractResources != "" {
+ if err := extractEmbedFS(data.BotPolicies, ".", *extractResources); err != nil {
+ log.Fatal(err)
+ }
if err := extractEmbedFS(web.Static, "static", *extractResources); err != nil {
log.Fatal(err)
}
@@ -347,7 +351,7 @@ func extractEmbedFS(fsys embed.FS, root string, destDir string) error {
return err
}
- destPath := filepath.Join(destDir, relPath)
+ destPath := filepath.Join(destDir, root, relPath)
if d.IsDir() {
return os.MkdirAll(destPath, 0o700)