From d1099bcf53de3f5c9dc22d70798014cd2a21d40a Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Wed, 26 Nov 2014 16:21:52 -0600 Subject: [PATCH] Add Gitlab certificate verification configuration Requires Bugagazavr/go-gitlab-client@4e00e401096c8a1fcab40bdc4f7aa03b6da0b57c --- README.md | 4 +++- packaging/root/etc/drone/drone.toml | 1 + plugin/remote/gitlab/gitlab.go | 18 +++++++++++------- plugin/remote/gitlab/gitlab_test.go | 2 +- plugin/remote/gitlab/helper.go | 4 ++-- plugin/remote/gitlab/register.go | 8 ++++++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8b90ae4be..307656bdf 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +https://github.com/drone/drone/blob/v0.2.1/README.md#builds diff --git a/packaging/root/etc/drone/drone.toml b/packaging/root/etc/drone/drone.toml index 1e4b459e4..77f99f0ab 100644 --- a/packaging/root/etc/drone/drone.toml +++ b/packaging/root/etc/drone/drone.toml @@ -51,6 +51,7 @@ datasource="/var/lib/drone/drone.sqlite" # [gitlab] # url="" +# skip_verify=false ##################################################################### diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index b4e07597d..560678ece 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -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 { diff --git a/plugin/remote/gitlab/gitlab_test.go b/plugin/remote/gitlab/gitlab_test.go index ca7e2ba0f..38c331364 100644 --- a/plugin/remote/gitlab/gitlab_test.go +++ b/plugin/remote/gitlab/gitlab_test.go @@ -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", } diff --git a/plugin/remote/gitlab/helper.go b/plugin/remote/gitlab/helper.go index ea2fb25f1..c497c3699 100644 --- a/plugin/remote/gitlab/helper.go +++ b/plugin/remote/gitlab/helper.go @@ -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 diff --git a/plugin/remote/gitlab/register.go b/plugin/remote/gitlab/register.go index eaac24670..c4e7e4c48 100644 --- a/plugin/remote/gitlab/register.go +++ b/plugin/remote/gitlab/register.go @@ -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, + ), ) }