1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/remote/bitbucketserver/client.go
Joachim Hill-Grannec 02c87d02f5 Merge branch 'master' into bitbucketserver
Moving git username and password to the url
Removing un-needed setting of Allows
Moving log.Fatal to log.Error
Removing panics
Moving to https for gravatar

# Conflicts:
#	remote/remote.go
2016-04-19 09:47:02 -07:00

62 lines
1.3 KiB
Go

package bitbucketserver
import (
"net/http"
"crypto/tls"
log "github.com/Sirupsen/logrus"
"io/ioutil"
"encoding/pem"
"crypto/x509"
"github.com/mrjones/oauth"
)
func NewClient(ConsumerKey string, URL string) *oauth.Consumer{
privateKeyFileContents, err := ioutil.ReadFile("/private_key.pem")
log.Info("Tried to read the key")
if err != nil {
log.Error(err)
}
block, _ := pem.Decode([]byte(privateKeyFileContents))
privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
log.Error(err)
}
c := oauth.NewRSAConsumer(
ConsumerKey,
privateKey,
oauth.ServiceProvider{
RequestTokenUrl: URL + "/plugins/servlet/oauth/request-token",
AuthorizeTokenUrl: URL + "/plugins/servlet/oauth/authorize",
AccessTokenUrl: URL + "/plugins/servlet/oauth/access-token",
HttpMethod: "POST",
})
c.HttpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
return c
}
func NewClientWithToken(ConsumerKey string, URL string, AccessToken string) *http.Client{
NewClient(ConsumerKey, URL)
c := NewClient(ConsumerKey, URL)
var token oauth.AccessToken
token.Token = AccessToken
client, err := c.MakeHttpClient(&token)
if err != nil {
log.Error(err)
}
return client
}