This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
gitlabbuildtrigger_validator.go
90 lines (76 loc) · 2.65 KB
/
gitlabbuildtrigger_validator.go
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
90
package gitlabbuildtrigger
import (
"strings"
"github.com/quay/config-tool/pkg/lib/shared"
)
// Validate checks the configuration settings for this field group
func (fg *GitLabBuildTriggerFieldGroup) Validate(opts shared.Options) []shared.ValidationError {
fgName := "GitLabBuildTrigger"
// Make empty errors
errors := []shared.ValidationError{}
// If build support is off, return false
if fg.FeatureBuildSupport == false {
return errors
}
// If github trigger is off
if fg.FeatureGitlabBuild == false {
return errors
}
// Check for config
if fg.GitlabTriggerConfig == nil {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG"},
FieldGroup: fgName,
Message: "GITLAB_TRIGGER_CONFIG is required for GitLabBuildTrigger",
}
errors = append(errors, newError)
return errors
}
// Check for endpoint
if fg.GitlabTriggerConfig.GitlabEndpoint == "" {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG.GITLAB_ENDPOINT"},
FieldGroup: fgName,
Message: "GITLAB_TRIGGER_CONFIG.GITLAB_ENDPOINT is required for GitLabBuildTrigger",
}
errors = append(errors, newError)
}
// Check for endpoint
if !strings.HasPrefix(fg.GitlabTriggerConfig.GitlabEndpoint, "http://") && !strings.HasPrefix(fg.GitlabTriggerConfig.GitlabEndpoint, "https://") {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG.GITLAB_ENDPOINT"},
FieldGroup: fgName,
Message: "GITLAB_TRIGGER_CONFIG.GITLAB_ENDPOINT must be a url",
}
errors = append(errors, newError)
}
// Check for client id
if fg.GitlabTriggerConfig.ClientId == "" {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG.CLIENT_ID"},
FieldGroup: fgName,
Message: "GITLAB_TRIGGER_CONFIG.CLIENT_ID is required for GitLabBuildTrigger",
}
errors = append(errors, newError)
}
// Check for endpoint
if fg.GitlabTriggerConfig.ClientSecret == "" {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG.CLIENT_SECRET"},
FieldGroup: fgName,
Message: "GITLAB_TRIGGER_CONFIG.CLIENT_SECRET is required for GitLabBuildTrigger",
}
errors = append(errors, newError)
}
// Check OAuth endpoint
success := shared.ValidateGitLabOAuth(fg.GitlabTriggerConfig.ClientId, fg.GitlabTriggerConfig.ClientSecret, fg.GitlabTriggerConfig.GitlabEndpoint)
if !success {
newError := shared.ValidationError{
Tags: []string{"GITLAB_TRIGGER_CONFIG.CLIENT_ID", "GITLAB_TRIGGER_CONFIG.CLIENT_SECRET"},
FieldGroup: fgName,
Message: "Could not verify GitLab OAuth credentials",
}
errors = append(errors, newError)
}
return errors
}