mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-02-07 12:29:44 -06: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>
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package challenge
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"sort"
|
|
"sync"
|
|
|
|
"github.com/TecharoHQ/anubis/lib/config"
|
|
"github.com/TecharoHQ/anubis/lib/policy"
|
|
"github.com/TecharoHQ/anubis/lib/store"
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
var (
|
|
registry map[string]Impl = map[string]Impl{}
|
|
regLock sync.RWMutex
|
|
)
|
|
|
|
func Register(name string, impl Impl) {
|
|
regLock.Lock()
|
|
defer regLock.Unlock()
|
|
|
|
registry[name] = impl
|
|
}
|
|
|
|
func Get(name string) (Impl, bool) {
|
|
regLock.RLock()
|
|
defer regLock.RUnlock()
|
|
result, ok := registry[name]
|
|
return result, ok
|
|
}
|
|
|
|
func Methods() []string {
|
|
regLock.RLock()
|
|
defer regLock.RUnlock()
|
|
var result []string
|
|
for method := range registry {
|
|
result = append(result, method)
|
|
}
|
|
sort.Strings(result)
|
|
return result
|
|
}
|
|
|
|
type IssueInput struct {
|
|
Impressum *config.Impressum
|
|
Rule *policy.Bot
|
|
Challenge *Challenge
|
|
OGTags map[string]string
|
|
Store store.Interface
|
|
}
|
|
|
|
type ValidateInput struct {
|
|
Rule *policy.Bot
|
|
Challenge *Challenge
|
|
Store store.Interface
|
|
}
|
|
|
|
type Impl interface {
|
|
// Setup registers any additional routes with the Impl for assets or API routes.
|
|
Setup(mux *http.ServeMux)
|
|
|
|
// Issue a new challenge to the user, called by the Anubis.
|
|
Issue(w http.ResponseWriter, r *http.Request, lg *slog.Logger, in *IssueInput) (templ.Component, error)
|
|
|
|
// Validate a challenge, making sure that it passes muster.
|
|
Validate(r *http.Request, lg *slog.Logger, in *ValidateInput) error
|
|
}
|