Add Gitlab certificate verification configuration

Requires Bugagazavr/go-gitlab-client@4e00e40109
This commit is contained in:
Michael Steinert 2014-11-26 16:21:52 -06:00
parent 5539f63ba5
commit d1099bcf53
6 changed files with 24 additions and 13 deletions

View file

@ -114,6 +114,7 @@ secret=""
[gitlab]
url=""
skip_verify=false
[smtp]
host=""
@ -169,6 +170,7 @@ export DRONE_BITBUCKET_SECRET=""
# gitlab configuration
export DRONE_GITLAB_URL=""
export DRONE_GITLAB_SKIP_VERIFY=false
# email configuration
export DRONE_SMTP_HOST=""
@ -216,4 +218,4 @@ You will need to include a `.drone.yml` file in the root of your repository in o
configure a build. I'm still working on updated documentation, so in the meantime please refer
to the `0.2` README to learn more about the `.drone.yml` format:
https://github.com/drone/drone/blob/v0.2.1/README.md#builds
https://github.com/drone/drone/blob/v0.2.1/README.md#builds

View file

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

View file

@ -11,11 +11,15 @@ import (
)
type Gitlab struct {
url string
url string
SkipVerify bool
}
func New(url string) *Gitlab {
return &Gitlab{url: url}
func New(url string, skipVerify bool) *Gitlab {
return &Gitlab{
url: url,
SkipVerify: skipVerify,
}
}
// 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 password = req.FormValue("password")
var client = NewClient(r.url, "")
var client = NewClient(r.url, "", r.SkipVerify)
var session, err = client.GetSession(username, password)
if err != nil {
return nil, err
@ -55,7 +59,7 @@ func (r *Gitlab) GetHost() string {
func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) {
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()
if err != nil {
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
// repository and returns in string format.
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)
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
// a Public Deploy key, if applicable.
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 title, err = GetKeyTitle(link)
if err != nil {

View file

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

View file

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

View file

@ -6,7 +6,8 @@ import (
)
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
@ -17,6 +18,9 @@ func Register() {
return
}
remote.Register(
New(*gitlabURL),
New(
*gitlabURL,
*gitlabSkipVerify,
),
)
}