feat #4: add storage config in config file
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8852e3de52
commit
a6011106d5
2 changed files with 37 additions and 5 deletions
|
@ -54,6 +54,19 @@ type OpenConnectConfig struct {
|
|||
Issuer string `json:"issuer"`
|
||||
}
|
||||
|
||||
type StorageConfigConfig struct {
|
||||
File string `json:"file"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Database string `json:"database"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Ssl struct {
|
||||
Mode string `json:"mode"`
|
||||
CaFile string `json:"caFile"`
|
||||
} `json:"ssl"`
|
||||
}
|
||||
|
||||
type jsonConf struct {
|
||||
Log struct {
|
||||
Level string `json:"level"`
|
||||
|
@ -64,6 +77,10 @@ type jsonConf struct {
|
|||
Mode string `json:"mode"`
|
||||
SockPath string `json:"sock"`
|
||||
} `json:"server"`
|
||||
Storage struct {
|
||||
StorageType string `json:"type"`
|
||||
StorageConfig *StorageConfigConfig `json:"config"`
|
||||
} `json:"storage"`
|
||||
OpenConnectConfig *OpenConnectConfig `json:"openconnect"`
|
||||
}
|
||||
|
||||
|
@ -73,6 +90,8 @@ type AppConfig struct {
|
|||
Host string
|
||||
Port int
|
||||
SockPath string
|
||||
StorageType string
|
||||
StorageConfig *StorageConfigConfig
|
||||
OpenConnectConfig *OpenConnectConfig
|
||||
}
|
||||
|
||||
|
@ -102,6 +121,8 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
|
|||
ac.Host = jsonConf.Server.Host
|
||||
ac.Port = jsonConf.Server.Port
|
||||
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
|
||||
ac.StorageType = jsonConf.Storage.StorageType
|
||||
ac.StorageConfig = jsonConf.Storage.StorageConfig
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -110,6 +131,7 @@ var defaultConfig AppConfig = AppConfig{
|
|||
ServerMode: ModeNet,
|
||||
Host: "0.0.0.0",
|
||||
Port: 5000,
|
||||
StorageType: "memory",
|
||||
}
|
||||
|
||||
func New(filepath string) (*AppConfig, error) {
|
||||
|
|
|
@ -47,12 +47,22 @@ func main() {
|
|||
logger.Init(conf.LogLevel)
|
||||
logger.L.Infof("Initialized logger with level %v", conf.LogLevel)
|
||||
|
||||
var storageType storage.Storage
|
||||
switch conf.StorageType {
|
||||
case "memory":
|
||||
storageType = memory.New(logger.L)
|
||||
default:
|
||||
logger.L.Fatalf("Unsupported storage backend type: %s", conf.StorageType)
|
||||
}
|
||||
|
||||
logger.L.Infof("Initialized storage backend \"%s\"", conf.StorageType)
|
||||
|
||||
dexConf := dex_server.Config{
|
||||
Web: dex_server.WebConfig{
|
||||
Dir: "./",
|
||||
Theme: "default",
|
||||
},
|
||||
Storage: memory.New(logger.L),
|
||||
Storage: storageType,
|
||||
Issuer: conf.OpenConnectConfig.Issuer,
|
||||
SupportedResponseTypes: []string{"code"},
|
||||
SkipApprovalScreen: false,
|
||||
|
|
Loading…
Reference in a new issue