mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
members: direct providers config.
This commit is contained in:
parent
524d895db8
commit
0233daf125
@ -3,17 +3,17 @@ package config
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"demodesk/neko/internal/member/file"
|
||||||
|
"demodesk/neko/internal/member/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Member struct {
|
type Member struct {
|
||||||
Provider string
|
Provider string
|
||||||
|
|
||||||
// file provider
|
// providers
|
||||||
FilePath string
|
File file.Config
|
||||||
|
Object object.Config
|
||||||
// object provider
|
|
||||||
ObjectUserPassword string
|
|
||||||
ObjectAdminPassword string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Member) Init(cmd *cobra.Command) error {
|
func (Member) Init(cmd *cobra.Command) error {
|
||||||
@ -46,9 +46,9 @@ func (s *Member) Set() {
|
|||||||
s.Provider = viper.GetString("member.provider")
|
s.Provider = viper.GetString("member.provider")
|
||||||
|
|
||||||
// file provider
|
// file provider
|
||||||
s.FilePath = viper.GetString("member.file.path")
|
s.File.Path = viper.GetString("member.file.path")
|
||||||
|
|
||||||
// object provider
|
// object provider
|
||||||
s.ObjectUserPassword = viper.GetString("member.object.user_password")
|
s.Object.UserPassword = viper.GetString("member.object.user_password")
|
||||||
s.ObjectAdminPassword = viper.GetString("member.object.admin_password")
|
s.Object.AdminPassword = viper.GetString("member.object.admin_password")
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func (provider *MemberProviderCtx) Delete(id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (provider *MemberProviderCtx) deserialize() (map[string]MemberEntry, error) {
|
func (provider *MemberProviderCtx) deserialize() (map[string]MemberEntry, error) {
|
||||||
file, err := os.OpenFile(provider.config.File, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
file, err := os.OpenFile(provider.config.Path, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -190,5 +190,5 @@ func (provider *MemberProviderCtx) serialize(data map[string]MemberEntry) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(provider.config.File, raw, os.ModePerm)
|
return ioutil.WriteFile(provider.config.Path, raw, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,5 @@ type MemberEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
File string
|
Path string
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,9 @@ func New(sessions types.SessionManager, config *config.Member) *MemberManagerCtx
|
|||||||
|
|
||||||
switch config.Provider {
|
switch config.Provider {
|
||||||
case "file":
|
case "file":
|
||||||
manager.provider = file.New(file.Config{
|
manager.provider = file.New(config.File)
|
||||||
File: config.FilePath,
|
|
||||||
})
|
|
||||||
case "object":
|
case "object":
|
||||||
manager.provider = object.New(object.Config{
|
manager.provider = object.New(config.Object)
|
||||||
AdminPassword: config.ObjectAdminPassword,
|
|
||||||
UserPassword: config.ObjectUserPassword,
|
|
||||||
})
|
|
||||||
case "dummy":
|
case "dummy":
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user