Merge pull request #732 from msteinert/gitlab-verify-skip

Add Gitlab certificate verification configuration
This commit is contained in:
Brad Rydzewski 2014-12-14 23:21:11 -08:00
commit 01ca940add
6 changed files with 24 additions and 13 deletions

View file

@ -114,6 +114,7 @@ secret=""
[gitlab] [gitlab]
url="" url=""
skip_verify=false
[smtp] [smtp]
host="" host=""
@ -171,6 +172,7 @@ export DRONE_BITBUCKET_SECRET=""
# gitlab configuration # gitlab configuration
export DRONE_GITLAB_URL="" export DRONE_GITLAB_URL=""
export DRONE_GITLAB_SKIP_VERIFY=false
# email configuration # email configuration
export DRONE_SMTP_HOST="" export DRONE_SMTP_HOST=""

View file

@ -51,6 +51,7 @@ datasource="/var/lib/drone/drone.sqlite"
# [gitlab] # [gitlab]
# url="" # url=""
# skip_verify=false
##################################################################### #####################################################################

View file

@ -11,11 +11,15 @@ import (
) )
type Gitlab struct { type Gitlab struct {
url string url string
SkipVerify bool
} }
func New(url string) *Gitlab { func New(url string, skipVerify bool) *Gitlab {
return &Gitlab{url: url} return &Gitlab{
url: url,
SkipVerify: skipVerify,
}
} }
// Authorize handles authentication with thrid party remote systems, // Authorize handles authentication with thrid party remote systems,
@ -24,7 +28,7 @@ func (r *Gitlab) Authorize(res http.ResponseWriter, req *http.Request) (*model.L
var username = req.FormValue("username") var username = req.FormValue("username")
var password = req.FormValue("password") var password = req.FormValue("password")
var client = NewClient(r.url, "") var client = NewClient(r.url, "", r.SkipVerify)
var session, err = client.GetSession(username, password) var session, err = client.GetSession(username, password)
if err != nil { if err != nil {
return nil, err return nil, err
@ -55,7 +59,7 @@ func (r *Gitlab) GetHost() string {
func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) { func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) {
var repos []*model.Repo var repos []*model.Repo
var client = NewClient(r.url, user.Access) var client = NewClient(r.url, user.Access, r.SkipVerify)
var list, err = client.AllProjects() var list, err = client.AllProjects()
if err != nil { if err != nil {
return nil, err return nil, err
@ -110,7 +114,7 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) {
// GetScript fetches the build script (.drone.yml) from the remote // GetScript fetches the build script (.drone.yml) from the remote
// repository and returns in string format. // repository and returns in string format.
func (r *Gitlab) GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error) { func (r *Gitlab) GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error) {
var client = NewClient(r.url, user.Access) var client = NewClient(r.url, user.Access, r.SkipVerify)
var path = ns(repo.Owner, repo.Name) var path = ns(repo.Owner, repo.Name)
return client.RepoRawFile(path, hook.Sha, ".drone.yml") return client.RepoRawFile(path, hook.Sha, ".drone.yml")
} }
@ -118,7 +122,7 @@ func (r *Gitlab) GetScript(user *model.User, repo *model.Repo, hook *model.Hook)
// Activate activates a repository by adding a Post-commit hook and // Activate activates a repository by adding a Post-commit hook and
// a Public Deploy key, if applicable. // a Public Deploy key, if applicable.
func (r *Gitlab) Activate(user *model.User, repo *model.Repo, link string) error { func (r *Gitlab) Activate(user *model.User, repo *model.Repo, link string) error {
var client = NewClient(r.url, user.Access) var client = NewClient(r.url, user.Access, r.SkipVerify)
var path = ns(repo.Owner, repo.Name) var path = ns(repo.Owner, repo.Name)
var title, err = GetKeyTitle(link) var title, err = GetKeyTitle(link)
if err != nil { if err != nil {

View file

@ -14,7 +14,7 @@ func Test_Github(t *testing.T) {
var server = testdata.NewServer() var server = testdata.NewServer()
defer server.Close() defer server.Close()
var gitlab = New(server.URL) var gitlab = New(server.URL, false)
var user = model.User{ var user = model.User{
Access: "e3b0c44298fc1c149afbf4c8996fb", Access: "e3b0c44298fc1c149afbf4c8996fb",
} }

View file

@ -9,8 +9,8 @@ import (
// NewClient is a helper function that returns a new GitHub // NewClient is a helper function that returns a new GitHub
// client using the provided OAuth token. // client using the provided OAuth token.
func NewClient(uri, token string) *gogitlab.Gitlab { func NewClient(uri, token string, skipVerify bool) *gogitlab.Gitlab {
return gogitlab.NewGitlab(uri, "/api/v3", token) return gogitlab.NewGitlabCert(uri, "/api/v3", token, skipVerify)
} }
// IsRead is a helper function that returns true if the // IsRead is a helper function that returns true if the

View file

@ -6,7 +6,8 @@ import (
) )
var ( var (
gitlabURL = config.String("gitlab-url", "") gitlabURL = config.String("gitlab-url", "")
gitlabSkipVerify = config.Bool("gitlab-skip-verify", false)
) )
// Registers the Gitlab plugin using the default // Registers the Gitlab plugin using the default
@ -17,6 +18,9 @@ func Register() {
return return
} }
remote.Register( remote.Register(
New(*gitlabURL), New(
*gitlabURL,
*gitlabSkipVerify,
),
) )
} }