mirror of https://github.com/ledisdb/ledisdb.git
Make the auth stuff simpler - just have a password
This commit is contained in:
parent
623794feb2
commit
d48cb8c773
|
@ -22,6 +22,7 @@ LedisDB now supports multiple different databases as backends.
|
|||
+ Replication to guarantee data safety.
|
||||
+ Supplies tools to load, dump, and repair database.
|
||||
+ Supports cluster, use [xcodis](https://github.com/siddontang/xcodis)
|
||||
+ Authentication (though, not via http)
|
||||
|
||||
## Build and Install
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ type SnapshotConfig struct {
|
|||
type Config struct {
|
||||
m sync.RWMutex `toml:"-"`
|
||||
|
||||
AuthEnabled bool `toml:"auth_enabled"`
|
||||
AuthPassword string `toml:"auth_password"`
|
||||
|
||||
FileName string `toml:"-"`
|
||||
|
@ -171,8 +170,7 @@ func NewConfigDefault() *Config {
|
|||
cfg.SlaveOf = ""
|
||||
cfg.Readonly = false
|
||||
|
||||
// Disable Auth by default
|
||||
cfg.AuthEnabled = false
|
||||
// Disable Auth by default, by setting password to blank
|
||||
cfg.AuthPassword = ""
|
||||
|
||||
// default databases number
|
||||
|
|
|
@ -25,6 +25,9 @@ slaveof = ""
|
|||
# for readonly mode, only replication and flushall can write
|
||||
readonly = false
|
||||
|
||||
# Authentication (for non-http connections). Connect, then use the AUTH command to authenticate.
|
||||
# auth_password = "russellwashere"
|
||||
|
||||
# Choose which backend storage to use, now support:
|
||||
#
|
||||
# leveldb
|
||||
|
|
|
@ -37,11 +37,7 @@ func startTestAppAuth(password string) {
|
|||
|
||||
cfg.Addr = "127.0.0.1:20000"
|
||||
cfg.HttpAddr = "127.0.0.1:20001"
|
||||
|
||||
if password != "" {
|
||||
cfg.AuthPassword = password
|
||||
cfg.AuthEnabled = true
|
||||
}
|
||||
|
||||
os.RemoveAll(cfg.DataDir)
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func newClient(app *App) *client {
|
|||
|
||||
c.app = app
|
||||
c.ldb = app.ldb
|
||||
c.is_authed = false || !app.cfg.AuthEnabled
|
||||
c.is_authed = false || c.authEnabled()
|
||||
c.db, _ = app.ldb.Select(0) //use default db
|
||||
|
||||
return c
|
||||
|
@ -98,6 +98,10 @@ func (c *client) close() {
|
|||
|
||||
}
|
||||
|
||||
func (c *client) authEnabled() bool {
|
||||
return len(c.app.cfg.AuthPassword) > 0
|
||||
}
|
||||
|
||||
func (c *client) perform() {
|
||||
var err error
|
||||
|
||||
|
@ -107,7 +111,7 @@ func (c *client) perform() {
|
|||
err = ErrEmptyCommand
|
||||
} else if exeCmd, ok := regCmds[c.cmd]; !ok {
|
||||
err = ErrNotFound
|
||||
} else if c.app.cfg.AuthEnabled && !c.is_authed && c.cmd != "auth" {
|
||||
} else if c.authEnabled() && !c.is_authed && c.cmd != "auth" {
|
||||
err = ErrNotAuthenticated
|
||||
} else {
|
||||
// if c.db.IsTransaction() {
|
||||
|
|
Loading…
Reference in New Issue