-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: rollback some part of auth and storage
- Loading branch information
1 parent
bfd268b
commit fda711b
Showing
6 changed files
with
109 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/filebrowser/filebrowser/v2/settings" | ||
"github.com/filebrowser/filebrowser/v2/users" | ||
"net/http" | ||
) | ||
|
||
// Auther is the authentication interface. | ||
//type Auther interface { | ||
// // Auth is called to authenticate a request. | ||
// Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) | ||
// // LoginPage indicates if this auther needs a login page. | ||
// LoginPage() bool | ||
//} | ||
type Auther interface { | ||
// Auth is called to authenticate a request. | ||
Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) | ||
// LoginPage indicates if this auther needs a login page. | ||
LoginPage() bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/filebrowser/filebrowser/v2/settings" | ||
"github.com/filebrowser/filebrowser/v2/users" | ||
"net/http" | ||
) | ||
|
||
// MethodNoAuth is used to identify no auth. | ||
//const MethodNoAuth settings.AuthMethod = "noauth" | ||
// | ||
//// NoAuth is no auth implementation of auther. | ||
//type NoAuth struct{} | ||
// | ||
//// Auth uses authenticates user 1. | ||
//func (a NoAuth) Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) { | ||
// return usr.Get(srv.Root, uint(1)) | ||
//} | ||
// | ||
//// LoginPage tells that no auth doesn't require a login page. | ||
//func (a NoAuth) LoginPage() bool { | ||
// return false | ||
//} | ||
const MethodNoAuth settings.AuthMethod = "noauth" | ||
|
||
// NoAuth is no auth implementation of auther. | ||
type NoAuth struct{} | ||
|
||
// Auth uses authenticates user 1. | ||
func (a NoAuth) Auth(r *http.Request, usr users.Store, stg *settings.Settings, srv *settings.Server) (*users.User, error) { | ||
return usr.Get(srv.Root, uint(1)) | ||
} | ||
|
||
// LoginPage tells that no auth doesn't require a login page. | ||
func (a NoAuth) LoginPage() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/filebrowser/filebrowser/v2/settings" | ||
"github.com/filebrowser/filebrowser/v2/users" | ||
) | ||
|
||
// StorageBackend is a storage backend for auth storage. | ||
//type StorageBackend interface { | ||
// Get(settings.AuthMethod) (Auther, error) | ||
// Save(Auther) error | ||
//} | ||
// | ||
//// Storage is a auth storage. | ||
//type Storage struct { | ||
// back StorageBackend | ||
// users *users.Storage | ||
//} | ||
// | ||
//// NewStorage creates a auth storage from a backend. | ||
//func NewStorage(back StorageBackend, userStore *users.Storage) *Storage { | ||
// return &Storage{back: back, users: userStore} | ||
//} | ||
// | ||
//// Get wraps a StorageBackend.Get. | ||
//func (s *Storage) Get(t settings.AuthMethod) (Auther, error) { | ||
// return s.back.Get(t) | ||
//} | ||
// | ||
//// Save wraps a StorageBackend.Save. | ||
//func (s *Storage) Save(a Auther) error { | ||
// return s.back.Save(a) | ||
//} | ||
type StorageBackend interface { | ||
Get(settings.AuthMethod) (Auther, error) | ||
Save(Auther) error | ||
} | ||
|
||
// Storage is a auth storage. | ||
type Storage struct { | ||
back StorageBackend | ||
users *users.Storage | ||
} | ||
|
||
// NewStorage creates a auth storage from a backend. | ||
func NewStorage(back StorageBackend, userStore *users.Storage) *Storage { | ||
return &Storage{back: back, users: userStore} | ||
} | ||
|
||
// Get wraps a StorageBackend.Get. | ||
func (s *Storage) Get(t settings.AuthMethod) (Auther, error) { | ||
return s.back.Get(t) | ||
} | ||
|
||
// Save wraps a StorageBackend.Save. | ||
func (s *Storage) Save(a Auther) error { | ||
return s.back.Save(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
package bolt | ||
|
||
// | ||
//import ( | ||
// "github.com/asdine/storm/v3" | ||
// | ||
// "github.com/filebrowser/filebrowser/v2/auth" | ||
// "github.com/filebrowser/filebrowser/v2/errors" | ||
// "github.com/filebrowser/filebrowser/v2/settings" | ||
//) | ||
// | ||
//type authBackend struct { | ||
// db *storm.DB | ||
//} | ||
// | ||
//func (s authBackend) Get(t settings.AuthMethod) (auth.Auther, error) { | ||
// var auther auth.Auther | ||
// | ||
// switch t { | ||
// case auth.MethodJSONAuth: | ||
// auther = &auth.JSONAuth{} | ||
// case auth.MethodProxyAuth: | ||
// auther = &auth.ProxyAuth{} | ||
// case auth.MethodHookAuth: | ||
// auther = &auth.HookAuth{} | ||
// case auth.MethodNoAuth: | ||
// auther = &auth.NoAuth{} | ||
// default: | ||
// return nil, errors.ErrInvalidAuthMethod | ||
// } | ||
// | ||
// return auther, get(s.db, "auther", auther) | ||
//} | ||
// | ||
//func (s authBackend) Save(a auth.Auther) error { | ||
// return save(s.db, "auther", a) | ||
//} | ||
import ( | ||
"github.com/asdine/storm/v3" | ||
|
||
"github.com/filebrowser/filebrowser/v2/auth" | ||
"github.com/filebrowser/filebrowser/v2/errors" | ||
"github.com/filebrowser/filebrowser/v2/settings" | ||
) | ||
|
||
type authBackend struct { | ||
db *storm.DB | ||
} | ||
|
||
func (s authBackend) Get(t settings.AuthMethod) (auth.Auther, error) { | ||
var auther auth.Auther | ||
|
||
switch t { | ||
//case auth.MethodJSONAuth: | ||
// auther = &auth.JSONAuth{} | ||
//case auth.MethodProxyAuth: | ||
// auther = &auth.ProxyAuth{} | ||
//case auth.MethodHookAuth: | ||
// auther = &auth.HookAuth{} | ||
case auth.MethodNoAuth: | ||
auther = &auth.NoAuth{} | ||
default: | ||
return nil, errors.ErrInvalidAuthMethod | ||
} | ||
|
||
return auther, get(s.db, "auther", auther) | ||
} | ||
|
||
func (s authBackend) Save(a auth.Auther) error { | ||
return save(s.db, "auther", a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package storage | ||
|
||
import ( | ||
"github.com/filebrowser/filebrowser/v2/auth" | ||
"github.com/filebrowser/filebrowser/v2/settings" | ||
"github.com/filebrowser/filebrowser/v2/users" | ||
) | ||
|
||
// Storage is a storage powered by a Backend which makes the necessary | ||
// verifications when fetching and saving data to ensure consistency. | ||
type Storage struct { | ||
Users users.Store | ||
//Auth *auth.Storage | ||
Users users.Store | ||
Auth *auth.Storage | ||
Settings *settings.Storage | ||
} |