1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/pkg/model/settings.go

63 lines
1.6 KiB
Go
Raw Normal View History

2014-02-07 13:10:01 +03:00
package model
import (
2014-02-22 01:25:05 +03:00
"errors"
2014-02-07 13:10:01 +03:00
"net/url"
2014-02-22 01:25:05 +03:00
"strings"
)
var (
ErrInvalidGitHubTrailingSlash = errors.New("GitHub URL should not have a trailing slash")
2014-03-07 22:10:40 +03:00
ErrInvalidSmtpAddress = errors.New("SMTP From Address must be provided")
ErrInvalidSmtpPort = errors.New("SMTP Port must be provided")
2014-02-07 13:10:01 +03:00
)
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"`
2014-02-07 13:10:01 +03:00
// 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"`
2014-02-13 12:08:20 +03:00
OpenInvitations bool `meddler:"open_invitations"`
2014-02-07 13:10:01 +03:00
}
func (s *Settings) URL() *url.URL {
return &url.URL{
Scheme: s.Scheme,
Host: s.Domain}
}
2014-02-22 01:25:05 +03:00
// Validate verifies all required fields are correctly populated.
func (s *Settings) Validate() error {
switch {
case strings.HasSuffix(s.GitHubApiUrl, "/"):
return ErrInvalidGitHubTrailingSlash
2014-03-07 22:10:40 +03:00
case len(s.SmtpServer) != 0 && len(s.SmtpPort) == 0:
return ErrInvalidSmtpPort
case len(s.SmtpServer) != 0 && len(s.SmtpAddress) == 0:
return ErrInvalidSmtpAddress
2014-02-22 01:25:05 +03:00
default:
return nil
}
}