member providers extracted config.

This commit is contained in:
Miroslav Šedivý 2021-03-14 13:07:03 +01:00
parent fceae3818b
commit 00586baffc
5 changed files with 48 additions and 22 deletions

View File

@ -10,23 +10,18 @@ import (
"demodesk/neko/internal/types"
)
func New(file string) types.MemberManager {
func New(config Config) types.MemberManager {
return &MemberManagerCtx{
file: file,
config: config,
mu: sync.Mutex{},
}
}
type MemberManagerCtx struct {
file string
config Config
mu sync.Mutex
}
type MemberEntry struct {
Password string `json:"password"`
Profile types.MemberProfile `json:"profile"`
}
func (manager *MemberManagerCtx) Connect() error {
return nil
}
@ -177,7 +172,7 @@ func (manager *MemberManagerCtx) Delete(id string) error {
}
func (manager *MemberManagerCtx) deserialize() (map[string]MemberEntry, error) {
file, err := os.OpenFile(manager.file, os.O_RDONLY|os.O_CREATE, os.ModePerm)
file, err := os.OpenFile(manager.config.File, os.O_RDONLY|os.O_CREATE, os.ModePerm)
if err != nil {
return nil, err
}
@ -219,5 +214,5 @@ func (manager *MemberManagerCtx) serialize(data map[string]MemberEntry) error {
return err
}
return ioutil.WriteFile(manager.file, raw, os.ModePerm)
return ioutil.WriteFile(manager.config.File, raw, os.ModePerm)
}

View File

@ -0,0 +1,14 @@
package file
import (
"demodesk/neko/internal/types"
)
type MemberEntry struct {
Password string `json:"password"`
Profile types.MemberProfile `json:"profile"`
}
type Config struct {
File string
}

View File

@ -11,9 +11,14 @@ import (
func New(config *config.Member) types.MemberManager {
switch config.Provider {
case "file":
return file.New(config.FilePath)
return file.New(file.Config{
File: config.FilePath,
})
case "object":
return object.New()
return object.New(object.Config{
AdminPassword: config.AdminPassword,
UserPassword: config.Password,
})
case "dummy":
return dummy.New()
}

View File

@ -7,23 +7,20 @@ import (
"demodesk/neko/internal/types"
)
func New() types.MemberManager {
func New(config Config) types.MemberManager {
return &MemberManagerCtx{
config: config,
entries: make(map[string]MemberEntry),
mu: sync.Mutex{},
}
}
type MemberManagerCtx struct {
config Config
entries map[string]MemberEntry
mu sync.Mutex
}
type MemberEntry struct {
Password string `json:"password"`
Profile types.MemberProfile `json:"profile"`
}
func (manager *MemberManagerCtx) Connect() error {
return nil
}

View File

@ -0,0 +1,15 @@
package object
import (
"demodesk/neko/internal/types"
)
type MemberEntry struct {
Password string `json:"password"`
Profile types.MemberProfile `json:"profile"`
}
type Config struct {
AdminPassword string
UserPassword string
}