forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
62 lines (51 loc) · 1.63 KB
/
settings.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
package model
import (
"errors"
"net/url"
"strings"
)
var (
ErrInvalidGitHubTrailingSlash = errors.New("GitHub URL should not have a trailing slash")
ErrInvalidSmtpAddress = errors.New("SMTP From Address must be provided")
ErrInvalidSmtpPort = errors.New("SMTP Port must be provided")
)
type Settings struct {
ID int64 `meddler:"id,pk"`
// SMTP settings.
SmtpServer string `meddler:"smtp_server"`
SmtpPort string `meddler:"smtp_port"`
SmtpAddress string `meddler:"smtp_address"`
SmtpUsername string `meddler:"smtp_username"`
SmtpPassword string `meddler:"smtp_password"`
// GitHub Consumer key and secret.
GitHubKey string `meddler:"github_key"`
GitHubSecret string `meddler:"github_secret"`
GitHubDomain string `meddler:"github_domain"`
GitHubApiUrl string `meddler:"github_apiurl"`
// Bitbucket Consumer Key and secret.
BitbucketKey string `meddler:"bitbucket_key"`
BitbucketSecret string `meddler:"bitbucket_secret"`
// Domain of the server, eg drone.io
Domain string `meddler:"hostname"`
// Scheme of the server, eg https
Scheme string `meddler:"scheme"`
OpenInvitations bool `meddler:"open_invitations"`
}
func (s *Settings) URL() *url.URL {
return &url.URL{
Scheme: s.Scheme,
Host: s.Domain}
}
// Validate verifies all required fields are correctly populated.
func (s *Settings) Validate() error {
switch {
case strings.HasSuffix(s.GitHubApiUrl, "/"):
return ErrInvalidGitHubTrailingSlash
case len(s.SmtpServer) != 0 && len(s.SmtpPort) == 0:
return ErrInvalidSmtpPort
case len(s.SmtpServer) != 0 && len(s.SmtpAddress) == 0:
return ErrInvalidSmtpAddress
default:
return nil
}
}