mirror of
https://github.com/1f349/daisy.git
synced 2024-12-21 15:04:14 +00:00
Add nullauth for testing
This commit is contained in:
parent
cb65794fb6
commit
f8de80e311
@ -74,7 +74,7 @@ func (s *serveCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...any) subcomm
|
||||
func normalLoad(startUp daisy.Conf, wd string) {
|
||||
srv := daisy.NewHttpServer(startUp, wd)
|
||||
daisy.Logger.Infof("Starting HTTP server on '%s'", srv.Addr)
|
||||
go utils.RunBackgroundHttp("HTTP", srv)
|
||||
go utils.RunBackgroundHttp(daisy.Logger, srv)
|
||||
|
||||
exit_reload.ExitReload("Daisy", func() {}, func() {
|
||||
// stop http server
|
||||
|
4
go.mod
4
go.mod
@ -4,8 +4,8 @@ go 1.22
|
||||
|
||||
require (
|
||||
git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca
|
||||
github.com/1f349/cardcaldav v0.0.3
|
||||
github.com/1f349/violet v0.0.13
|
||||
github.com/1f349/cardcaldav v0.0.4
|
||||
github.com/1f349/violet v0.0.14
|
||||
github.com/charmbracelet/log v0.4.0
|
||||
github.com/emersion/go-webdav v0.5.1-0.20240419143909-21f251fa1de2
|
||||
github.com/google/subcommands v1.2.0
|
||||
|
8
go.sum
8
go.sum
@ -2,12 +2,12 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca h1:HBRu4nwicaaZ4oqwTis2qy4Gb/CKLA2OSlibdKpMhb8=
|
||||
git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca/go.mod h1:/1jsi+vx9b/T8UHrDRJXwoY8td9JUXd9UajtVCpVoeg=
|
||||
github.com/1f349/cardcaldav v0.0.3 h1:c2/wmOf+hwgKdaWLlKm5v8l0g9brD+Seqcp+xIDUXJI=
|
||||
github.com/1f349/cardcaldav v0.0.3/go.mod h1:MCoGRimM7p/rLWtaJxYO91tsvgXZ47M69X3lldb5dfk=
|
||||
github.com/1f349/cardcaldav v0.0.4 h1:byhhQOFJ2JItbMBp9mUc1hn8KAE22iem8ico4/piyyA=
|
||||
github.com/1f349/cardcaldav v0.0.4/go.mod h1:MCoGRimM7p/rLWtaJxYO91tsvgXZ47M69X3lldb5dfk=
|
||||
github.com/1f349/go-webdav v0.0.1 h1:qF0k+zdcwE9DapLu+fGYQO866W269eHVLQ1mrhZGlb4=
|
||||
github.com/1f349/go-webdav v0.0.1/go.mod h1:mI8iBx3RAODwX7PJJ7qzsKAKs/vY429YfS2/9wKnDbQ=
|
||||
github.com/1f349/violet v0.0.13 h1:lJpTz15Ea83Uc1VAISXTjtKuzr8Pe8NM4cMGp3Aiyhk=
|
||||
github.com/1f349/violet v0.0.13/go.mod h1:Ga5/hWqI+EkR6J1mAMNzs7aJhuGcA89XFqgQaDXC7Jo=
|
||||
github.com/1f349/violet v0.0.14 h1:MpBZ4n1dJjdiIwYMTfh0PBIFll3kjqowxR6DLasafqE=
|
||||
github.com/1f349/violet v0.0.14/go.mod h1:iAREhm+wxnGXkmuvmBhOuhUx2T7/5w7stLYNgQGbqC8=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
|
||||
|
22
nullauth.go
Normal file
22
nullauth.go
Normal file
@ -0,0 +1,22 @@
|
||||
//go:build nullauth
|
||||
|
||||
package daisy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type nullAuth struct{}
|
||||
|
||||
func (n *nullAuth) Middleware(next http.Handler) http.Handler {
|
||||
return next
|
||||
}
|
||||
|
||||
func (n *nullAuth) CurrentUserPrincipal(ctx context.Context) (string, error) {
|
||||
return "/jane@example.com/", nil
|
||||
}
|
||||
|
||||
func NullAuth(_ AuthProvider) AuthProvider {
|
||||
return &nullAuth{}
|
||||
}
|
7
nullauth_stub.go
Normal file
7
nullauth_stub.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build !nullauth
|
||||
|
||||
package daisy
|
||||
|
||||
func NullAuth(provider AuthProvider) AuthProvider {
|
||||
return provider
|
||||
}
|
@ -16,7 +16,7 @@ type Conf struct {
|
||||
}
|
||||
|
||||
type daisyHandler struct {
|
||||
auth *cardcaldav.Auth
|
||||
auth AuthProvider
|
||||
backend carddav.Backend
|
||||
}
|
||||
|
||||
@ -55,9 +55,14 @@ func (d *daisyHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
http.NotFound(rw, req)
|
||||
}
|
||||
|
||||
type AuthProvider interface {
|
||||
cardcaldav.ProviderMiddleware
|
||||
webdav.UserPrincipalBackend
|
||||
}
|
||||
|
||||
func NewHttpServer(conf Conf, wd string) *http.Server {
|
||||
cardcaldav.SetupLogger(Logger)
|
||||
principle := cardcaldav.NewAuth(conf.DB, Logger)
|
||||
principle := NullAuth(cardcaldav.NewAuth(conf.DB, Logger))
|
||||
|
||||
_, cardStorage, err := storage.NewFilesystem(filepath.Join(wd, "storage"), "/calendar/", "/contacts/", principle)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user