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 Client string
Secret string Secret string
Private bool 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{ var github = GitHub{
URL: url, URL: url,
API: api, API: api,
Client: client, Client: client,
Secret: secret, Secret: secret,
Private: private, Private: private,
SkipVerify: skipVerify,
} }
// the API must have a trailing slash // the API must have a trailing slash
if !strings.HasSuffix(github.API, "/") { 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 { 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. // 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) 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) var useremail, errr = GetUserEmail(client)
if errr != nil { if errr != nil {
return nil, fmt.Errorf("Error retrieving user or verified email. %s", errr) 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. // user has access to in the remote system.
func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) { func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) {
var repos []*model.Repo 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) var list, err = GetAllRepos(client)
if err != nil { if err != nil {
return nil, err 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 // GetScript fetches the build script (.drone.yml) from the remote
// repository and returns in string format. // repository and returns in string format.
func (r *GitHub) GetScript(user *model.User, repo *model.Repo, hook *model.Hook) ([]byte, error) { 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) return GetFile(client, repo.Owner, repo.Name, ".drone.yml", hook.Sha)
} }
// 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 *GitHub) Activate(user *model.User, repo *model.Repo, link string) error { 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) var title, err = GetKeyTitle(link)
if err != nil { if err != nil {
return err return err

View file

@ -1,6 +1,7 @@
package github package github
import ( import (
"crypto/tls"
"encoding/base32" "encoding/base32"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -15,10 +16,19 @@ 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) *github.Client { func NewClient(uri, token string, skipVerify bool) *github.Client {
t := &oauth.Transport{ t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token}, 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 := github.NewClient(t.Client())
c.BaseURL, _ = url.Parse(uri) c.BaseURL, _ = url.Parse(uri)
return c return c

View file

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