feature: ajouter cfg.Server.UI.Host et implémenter UI TLS #61

Merged
vlbeaudoin merged 1 commit from vlbeaudoin/feature/ui-tls into main 2024-07-23 11:48:41 -04:00 AGit
2 changed files with 36 additions and 2 deletions
Showing only changes of commit f5aa25a12a - Show all commits

22
cmd.go
View file

@ -251,7 +251,27 @@ Programme: [%s] %s
}) })
// Execution // Execution
switch cfg.Server.UI.TLS.Enabled {
case false:
e.Logger.Fatal(e.Start( e.Logger.Fatal(e.Start(
fmt.Sprintf(":%d", cfg.Server.UI.Port))) fmt.Sprintf("%s:%d", cfg.Server.UI.Host, cfg.Server.UI.Port)))
case true:
if cfg.Server.UI.TLS.Certfile == "" {
log.Fatal("TLS enabled for UI but no certificate file provided")
}
if cfg.Server.UI.TLS.Keyfile == "" {
log.Fatal("TLS enabled for UI but no private key file provided")
}
e.Logger.Fatal(
e.StartTLS(
fmt.Sprintf("%s:%d", cfg.Server.UI.Host, cfg.Server.UI.Port),
cfg.Server.UI.TLS.Certfile,
cfg.Server.UI.TLS.Keyfile,
),
)
}
}, },
} }

View file

@ -46,6 +46,7 @@ type Config struct {
Port int `yaml:"port"` Port int `yaml:"port"`
Protocol string `yaml:"protocol"` Protocol string `yaml:"protocol"`
} `yaml:"api"` } `yaml:"api"`
Host string `yaml:"host"`
Password string `yaml:"password"` Password string `yaml:"password"`
Port int `yaml:"port"` Port int `yaml:"port"`
TLS struct { TLS struct {
@ -366,6 +367,19 @@ func init() {
log.Fatal(err) log.Fatal(err)
} }
// server.ui.host
uiCmd.PersistentFlags().String(
"server-ui-host",
"",
"Web UI host",
)
if err := viper.BindPFlag(
"server.ui.host",
uiCmd.PersistentFlags().Lookup("server-ui-host"),
); err != nil {
log.Fatal(err)
}
// server.ui.password // server.ui.password
uiCmd.PersistentFlags().String( uiCmd.PersistentFlags().String(
"server-ui-password", "server-ui-password",