From 6e1f43e7e4112a81cff0d79f3e8c02d0fc9f0f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?EMRE=20=C3=87EL=C4=B0K?= Date: Fri, 17 Jun 2022 20:19:09 +0300 Subject: [PATCH] SSL Config Update Added SSL Config --- pkg/config/server.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/config/server.go b/pkg/config/server.go index 090708a3..675a2326 100644 --- a/pkg/config/server.go +++ b/pkg/config/server.go @@ -74,6 +74,17 @@ type ServerCommonConf struct { // value is 0, the dashboard will not be started. By default, this value is // 0. DashboardPort int `ini:"dashboard_port" json:"dashboard_port" validate:"gte=0,lte=65535"` + // DashboardTLSCertFile specifies the path of the cert file that the server will + // load. If "dashboard_tls_cert_file", "dashboard_tls_key_file" are valid, the server will use this + // supplied tls configuration. + DashboardTLSCertFile string `ini:"dashboard_tls_cert_file" json:"dashboard_tls_cert_file"` + // DashboardTLSKeyFile specifies the path of the secret key that the server will + // load. If "dashboard_tls_cert_file", "dashboard_tls_key_file" are valid, the server will use this + // supplied tls configuration. + DashboardTLSKeyFile string `ini:"dashboard_tls_key_file" json:"dashboard_tls_key_file"` + // DashboardTLSMode specifies the mode of the dashboard between HTTP or HTTPS modes. By + // default, this value is false, which is HTTP mode. + DashboardTLSMode bool `ini:"dashboard_tls_mode" json:"dashboard_tls_mode"` // DashboardUser specifies the username that the dashboard will use for // login. DashboardUser string `ini:"dashboard_user" json:"dashboard_user"` @@ -297,6 +308,23 @@ func (cfg *ServerCommonConf) Complete() { } func (cfg *ServerCommonConf) Validate() error { + if cfg.DashboardTLSMode == false { + if cfg.DashboardTLSCertFile != "" { + fmt.Println("WARNING! dashboard_tls_cert_file is invalid when dashboard_tls_mode is false") + } + + if cfg.DashboardTLSKeyFile != "" { + fmt.Println("WARNING! dashboard_tls_key_file is invalid when dashboard_tls_mode is false") + } + } else { + if cfg.DashboardTLSCertFile == "" { + return fmt.Errorf("ERROR! dashboard_tls_cert_file cannot be null when dashboard_tls_mode is true") + } + + if cfg.DashboardTLSKeyFile == "" { + return fmt.Errorf("ERROR! dashboard_tls_cert_file cannot be null when dashboard_tls_mode is true") + } + } return validator.New().Struct(cfg) }