From f5aa25a12a4ab7724736d8f4b3fe1b46ba823dfd Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Tue, 23 Jul 2024 11:46:37 -0400 Subject: [PATCH] =?UTF-8?q?feature:=20ajouter=20cfg.Server.UI.Host=20et=20?= =?UTF-8?q?impl=C3=A9menter=20UI=20TLS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd.go | 24 ++++++++++++++++++++++-- config.go | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/cmd.go b/cmd.go index a477a8a..a54cff6 100644 --- a/cmd.go +++ b/cmd.go @@ -251,7 +251,27 @@ Programme: [%s] %s }) // Execution - e.Logger.Fatal(e.Start( - fmt.Sprintf(":%d", cfg.Server.UI.Port))) + switch cfg.Server.UI.TLS.Enabled { + case false: + e.Logger.Fatal(e.Start( + 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, + ), + ) + } + }, } diff --git a/config.go b/config.go index 01eecd5..c611e07 100644 --- a/config.go +++ b/config.go @@ -46,6 +46,7 @@ type Config struct { Port int `yaml:"port"` Protocol string `yaml:"protocol"` } `yaml:"api"` + Host string `yaml:"host"` Password string `yaml:"password"` Port int `yaml:"port"` TLS struct { @@ -366,6 +367,19 @@ func init() { 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 uiCmd.PersistentFlags().String( "server-ui-password",