members: direct providers config.

This commit is contained in:
Miroslav Šedivý 2021-03-16 15:28:40 +01:00
parent 524d895db8
commit 0233daf125
4 changed files with 14 additions and 19 deletions

View File

@ -3,17 +3,17 @@ package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"demodesk/neko/internal/member/file"
"demodesk/neko/internal/member/object"
)
type Member struct {
Provider string
// file provider
FilePath string
// object provider
ObjectUserPassword string
ObjectAdminPassword string
// providers
File file.Config
Object object.Config
}
func (Member) Init(cmd *cobra.Command) error {
@ -46,9 +46,9 @@ func (s *Member) Set() {
s.Provider = viper.GetString("member.provider")
// file provider
s.FilePath = viper.GetString("member.file.path")
s.File.Path = viper.GetString("member.file.path")
// object provider
s.ObjectUserPassword = viper.GetString("member.object.user_password")
s.ObjectAdminPassword = viper.GetString("member.object.admin_password")
s.Object.UserPassword = viper.GetString("member.object.user_password")
s.Object.AdminPassword = viper.GetString("member.object.admin_password")
}

View File

@ -148,7 +148,7 @@ func (provider *MemberProviderCtx) Delete(id string) 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 {
return nil, err
}
@ -190,5 +190,5 @@ func (provider *MemberProviderCtx) serialize(data map[string]MemberEntry) error
return err
}
return ioutil.WriteFile(provider.config.File, raw, os.ModePerm)
return ioutil.WriteFile(provider.config.Path, raw, os.ModePerm)
}

View File

@ -10,5 +10,5 @@ type MemberEntry struct {
}
type Config struct {
File string
Path string
}

View File

@ -23,14 +23,9 @@ func New(sessions types.SessionManager, config *config.Member) *MemberManagerCtx
switch config.Provider {
case "file":
manager.provider = file.New(file.Config{
File: config.FilePath,
})
manager.provider = file.New(config.File)
case "object":
manager.provider = object.New(object.Config{
AdminPassword: config.ObjectAdminPassword,
UserPassword: config.ObjectUserPassword,
})
manager.provider = object.New(config.Object)
case "dummy":
fallthrough
default: