-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth.go
54 lines (47 loc) · 1.34 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package bytengine
import (
"fmt"
"log"
)
var authPlugins = make(map[string]Authentication)
type User struct {
Username string `json:"username"`
Active bool `json:"active"`
Databases []string `json:"databases"`
Root bool `json:"root"`
}
type Authentication interface {
Start(config string) error
ClearAll() error
Authenticate(usr, pw string) bool
NewUser(usr, pw string, root bool) error
ChangeUserPassword(usr, pw string) error
ChangeUserStatus(usr string, isactive bool) error
ListUser(rgx string) ([]string, error)
ChangeUserDbAccess(usr, db string, grant bool) error
HasDbAccess(usr, db string) bool
RemoveUser(usr string) error
UserInfo(u string) (*User, error)
}
func RegisterAuthentication(name string, plugin Authentication) {
if plugin == nil {
log.Fatal("Authentication Plugin Registration: plugin is nil")
}
if _, exists := authPlugins[name]; exists {
log.Printf("Authentication Plugin Registration: plugin %q already registered", name)
return
}
authPlugins[name] = plugin
}
func NewAuthentication(pluginName, config string) (plugin Authentication, err error) {
plugin, ok := authPlugins[pluginName]
if !ok {
err = fmt.Errorf("Authentication Plugin Creation: unknown plugin name %q (forgot to import?)", pluginName)
return
}
err = plugin.Start(config)
if err != nil {
plugin = nil
}
return
}