blob: 3831b45b561a455cc881fbe8ebfef5ef6a3b60c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package config
import (
"errors"
"net/url"
"github.com/hashicorp/go-multierror"
"gitlab.com/gitlab-org/gitlab-pages/internal/config/tls"
)
// Validate values populated in Config
func Validate(config *Config) error {
if err := validateListeners(config); err != nil {
return err
}
if err := validateAuthConfig(config); err != nil {
return err
}
if err := validateArtifactsServerConfig(config); err != nil {
return err
}
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 == "" {
return nil
}
var result *multierror.Error
if config.Authentication.Secret == "" {
err := errors.New("auth-secret must be defined if authentication is supported")
result = multierror.Append(result, err)
}
if config.Authentication.ClientID == "" {
err := errors.New("auth-client-id must be defined if authentication is supported")
result = multierror.Append(result, err)
}
if config.Authentication.ClientSecret == "" {
err := errors.New("auth-client-secret must be defined if authentication is supported")
result = multierror.Append(result, err)
}
if config.GitLab.PublicServer == "" {
err := errors.New("gitlab-server must be defined if authentication is supported")
result = multierror.Append(result, err)
}
if config.Authentication.RedirectURI == "" {
err := errors.New("auth-redirect-uri must be defined if authentication is supported")
result = multierror.Append(result, err)
}
return result.ErrorOrNil()
}
func validateArtifactsServerConfig(config *Config) error {
if config.ArtifactsServer.URL == "" {
return nil
}
u, err := url.Parse(config.ArtifactsServer.URL)
if err != nil {
return err
}
// url.Parse ensures that the Scheme attribute is always lower case.
if u.Scheme != "http" && u.Scheme != "https" {
return errors.New("artifacts-server scheme must be either http:// or https://")
}
if config.ArtifactsServer.TimeoutSeconds < 1 {
return errors.New("artifacts-server-timeout must be greater than or equal to 1")
}
return nil
}
|