Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2021-08-03 08:12:53 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-08-03 08:13:15 +0300
commit0dc345e1a3278ea4b922e2a7bf4952caf20bc139 (patch)
treea39a7d914c3d1c4c14f471f18c69463ff61b8e80
parente48c8977887e0f33f2934b46e97e8dfe96f08d92 (diff)
refactor: fail to start without listeners
defined as part of the configuration during daemon initialization. Changelog: other
-rw-r--r--app_test.go7
-rw-r--r--internal/config/multi_string_flag.go4
-rw-r--r--internal/config/validate.go15
3 files changed, 26 insertions, 0 deletions
diff --git a/app_test.go b/app_test.go
index 48a6013b..669d041e 100644
--- a/app_test.go
+++ b/app_test.go
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/http/httptest"
+ "os"
"testing"
"github.com/stretchr/testify/require"
@@ -84,6 +85,12 @@ func TestHealthCheckMiddleware(t *testing.T) {
},
}
+ // required by LoadConfig
+ require.NoError(t, os.Setenv("LISTEN_HTTP", ":0"))
+ t.Cleanup(func() {
+ require.NoError(t, os.Unsetenv("LISTEN_HTTP"))
+ })
+
cfg, err := config.LoadConfig()
require.NoError(t, err)
cfg.General.StatusPath = "/-/healthcheck"
diff --git a/internal/config/multi_string_flag.go b/internal/config/multi_string_flag.go
index fc63299b..0d90b572 100644
--- a/internal/config/multi_string_flag.go
+++ b/internal/config/multi_string_flag.go
@@ -49,3 +49,7 @@ func (s *MultiStringFlag) sep() string {
return s.separator
}
+
+func (s *MultiStringFlag) Len() int {
+ return len(s.value)
+}
diff --git a/internal/config/validate.go b/internal/config/validate.go
index f73aabff..87f932c0 100644
--- a/internal/config/validate.go
+++ b/internal/config/validate.go
@@ -10,6 +10,10 @@ import (
)
func validateConfig(config *Config) error {
+ if err := validateListeners(config); err != nil {
+ return err
+ }
+
if err := validateAuthConfig(config); err != nil {
return err
}
@@ -21,6 +25,17 @@ func validateConfig(config *Config) error {
return tls.ValidateTLSVersions(*tlsMinVersion, *tlsMaxVersion)
}
+func validateListeners(config *Config) error {
+ if config.ListenHTTPStrings.Len() == 0 &&
+ config.ListenHTTPSStrings.Len() == 0 &&
+ config.ListenHTTPSProxyv2Strings.Len() == 0 &&
+ config.ListenProxyStrings.Len() == 0 {
+ return errors.New("no listener defined, please specify at least one --listen-* flag")
+ }
+
+ return nil
+}
+
func validateAuthConfig(config *Config) error {
if config.Authentication.Secret == "" && config.Authentication.ClientID == "" &&
config.Authentication.ClientSecret == "" && config.Authentication.RedirectURI == "" {