instructs Drone to ignore cert verification if self-signed

This commit is contained in:
Brad Rydzewski 2014-11-17 11:18:58 -08:00
parent 2302d74465
commit 0dce99f5f4
3 changed files with 36 additions and 22 deletions

View file

@ -26,15 +26,17 @@ type GitHub struct {
Client string
Secret string
Private bool
SkipVerify bool
}
func New(url, api, client, secret string, private bool) *GitHub {
func New(url, api, client, secret string, private, skipVerify bool) *GitHub {
var github = GitHub{
URL: url,
API: api,
Client: client,
Secret: secret,
Private: private,
SkipVerify: skipVerify,
}
// the API must have a trailing slash
if !strings.HasSuffix(github.API, "/") {
@ -48,7 +50,7 @@ func New(url, api, client, secret string, private bool) *GitHub {
}
func NewDefault(client, secret string) *GitHub {
return New(DefaultURL, DefaultAPI, client, secret, false)
return New(DefaultURL, DefaultAPI, client, secret, false, false)
}
// Authorize handles GitHub API Authorization.
@ -84,7 +86,7 @@ func (r *GitHub) Authorize(res http.ResponseWriter, req *http.Request) (*model.L
return nil, fmt.Errorf("Error exchanging token. %s", err)
}
var client = NewClient(r.API, token.AccessToken)
var client = NewClient(r.API, token.AccessToken, r.SkipVerify)
var useremail, errr = GetUserEmail(client)
if errr != nil {
return nil, fmt.Errorf("Error retrieving user or verified email. %s", errr)
@ -127,7 +129,7 @@ func (r *GitHub) IsEnterprise() bool {
// user has access to in the remote system.
func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) {
var repos []*model.Repo
var client = NewClient(r.API, user.Access)
var client = NewClient(r.API, user.Access, r.SkipVerify)
var list, err = GetAllRepos(client)
if err != nil {
return nil, err
@ -173,14 +175,14 @@ func (r *GitHub) 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 *GitHub) GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error) {
var client = NewClient(r.API, user.Access)
var client = NewClient(r.API, user.Access, r.SkipVerify)
return GetFile(client, repo.Owner, repo.Name, ".drone.yml", hook.Sha)
}
// Activate activates a repository by adding a Post-commit hook and
// a Public Deploy key, if applicable.
func (r *GitHub) Activate(user *model.User, repo *model.Repo, link string) error {
var client = NewClient(r.API, user.Access)
var client = NewClient(r.API, user.Access, r.SkipVerify)
var title, err = GetKeyTitle(link)
if err != nil {
return err

View file

@ -1,6 +1,7 @@
package github
import (
"crypto/tls"
"encoding/base32"
"fmt"
"io/ioutil"
@ -15,10 +16,19 @@ import (
// NewClient is a helper function that returns a new GitHub
// client using the provided OAuth token.
func NewClient(uri, token string) *github.Client {
func NewClient(uri, token string, skipVerify bool) *github.Client {
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
}
// this is for GitHub enterprise users that are using
// self-signed certificates.
if skipVerify {
t.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
c := github.NewClient(t.Client())
c.BaseURL, _ = url.Parse(uri)
return c

View file

@ -16,6 +16,7 @@ var (
githubEnterpriseClient = config.String("github-enterprise-client", "")
githubEnterpriseSecret = config.String("github-enterprise-secret", "")
githubEnterprisePrivate = config.Bool("github-enterprise-private-mode", true)
githubEnterpriseSkipVerify = config.Bool("github-enterprise-skip-verify", false)
)
// Registers the GitHub plugins using the default
@ -51,6 +52,7 @@ func registerGitHubEnterprise() {
*githubEnterpriseClient,
*githubEnterpriseSecret,
*githubEnterprisePrivate,
*githubEnterpriseSkipVerify,
),
)
}