diff --git a/README.md b/README.md index 8b90ae4b..307656bd 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 1e4b459e..77f99f0a 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 b4e07597..560678ec 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 ca7e2ba0..38c33136 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 ea2fb25f..c497c369 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 eaac2467..c4e7e4c4 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, + ), ) }