Files
go-semantic-release/internal/releaser/util/util.go

38 lines
874 B
Go
Raw Normal View History

2019-06-15 23:03:27 +02:00
package util
import (
"context"
"fmt"
2019-06-15 23:03:27 +02:00
"net/http"
"os"
"strings"
2019-06-15 23:03:27 +02:00
log "github.com/sirupsen/logrus"
2019-06-15 23:03:27 +02:00
"golang.org/x/oauth2"
)
//CreateBearerHTTPClient with given token
func CreateBearerHTTPClient(ctx context.Context, token string) *http.Client {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: token},
)
client := oauth2.NewClient(ctx, tokenSource)
return client
}
// GetAccessToken lookup for the providers accesstoken
func GetAccessToken(providerName string) (string, error) {
var token string
var exists bool
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(providerName))
log.Debugf("check if %s environment variable is set", envName)
if token, exists = os.LookupEnv(envName); !exists {
2019-06-18 21:35:51 +02:00
return "", fmt.Errorf("could not find %s in the enviroment variables. Please check if it is set", envName)
}
return token, nil
}