mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-11-28 08:30:23 +08:00
* refactor: move lib/policy/config to lib/config Signed-off-by: Xe Iaso <me@xeiaso.net> * refactor: don't set global loggers anymore Ref #864 You were right @kotx, it is a bad idea to set the global logger instance. Signed-off-by: Xe Iaso <me@xeiaso.net> * feat(config): add log sink support Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: update spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * chore(test): go mod tidy Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: update spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * docs(admin/policies): add logging block documentation Signed-off-by: Xe Iaso <me@xeiaso.net> * docs: update CHANGELOG Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(cmd/anubis): revert this change, it's meant to be its own PR Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: go mod tidy Signed-off-by: Xe Iaso <me@xeiaso.net> * test: add file logging smoke test Assisted-by: GLM 4.6 via Claude Code Signed-off-by: Xe Iaso <me@xeiaso.net> * fix: don't expose the old log file time format string Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
44 lines
804 B
Go
44 lines
804 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
ErrPrivateASN = errors.New("bot.ASNs: you have specified a private use ASN")
|
|
)
|
|
|
|
type ASNs struct {
|
|
Match []uint32 `json:"match"`
|
|
}
|
|
|
|
func (a *ASNs) Valid() error {
|
|
var errs []error
|
|
|
|
for _, asn := range a.Match {
|
|
if isPrivateASN(asn) {
|
|
errs = append(errs, fmt.Errorf("%w: %d is private (see RFC 6996)", ErrPrivateASN, asn))
|
|
}
|
|
}
|
|
|
|
if len(errs) != 0 {
|
|
return fmt.Errorf("bot.ASNs: invalid ASN settings: %w", errors.Join(errs...))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// isPrivateASN checks if an ASN is in the private use area.
|
|
//
|
|
// Based on RFC 6996 and IANA allocations.
|
|
func isPrivateASN(asn uint32) bool {
|
|
switch {
|
|
case asn >= 64512 && asn <= 65534:
|
|
return true
|
|
case asn >= 4200000000 && asn <= 4294967294:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|