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 ( 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")
} }

View File

@ -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)
} }

View File

@ -10,5 +10,5 @@ type MemberEntry struct {
} }
type Config 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 { 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: