12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package github
- import (
- "context"
- "crypto/tls"
- "net/http"
- "strings"
- "github.com/google/go-github/github"
- "github.com/pkg/errors"
- )
- type Config struct {
-
- APIEndpoint string
- SkipVerify bool
- }
- func (c *Config) doAuth(login, password string) (fullname, email, location, website string, err error) {
- tp := github.BasicAuthTransport{
- Username: strings.TrimSpace(login),
- Password: strings.TrimSpace(password),
- Transport: &http.Transport{
- TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify},
- },
- }
- client, err := github.NewEnterpriseClient(c.APIEndpoint, c.APIEndpoint, tp.Client())
- if err != nil {
- return "", "", "", "", errors.Wrap(err, "create new client")
- }
- user, _, err := client.Users.Get(context.Background(), "")
- if err != nil {
- return "", "", "", "", errors.Wrap(err, "get user info")
- }
- if user.Name != nil {
- fullname = *user.Name
- }
- if user.Email != nil {
- email = *user.Email
- } else {
- email = login + "+github@local"
- }
- if user.Location != nil {
- location = strings.ToUpper(*user.Location)
- }
- if user.HTMLURL != nil {
- website = strings.ToLower(*user.HTMLURL)
- }
- return fullname, email, location, website, nil
- }
|