github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/github/config.go (about)

     1  package github
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/google/go-github/github"
     7  	"golang.org/x/oauth2"
     8  )
     9  
    10  type Config struct {
    11  	Token        string
    12  	Organization string
    13  	BaseURL      string
    14  }
    15  
    16  type Organization struct {
    17  	name   string
    18  	client *github.Client
    19  }
    20  
    21  // Client configures and returns a fully initialized GithubClient
    22  func (c *Config) Client() (interface{}, error) {
    23  	var org Organization
    24  	org.name = c.Organization
    25  	ts := oauth2.StaticTokenSource(
    26  		&oauth2.Token{AccessToken: c.Token},
    27  	)
    28  	tc := oauth2.NewClient(oauth2.NoContext, ts)
    29  
    30  	org.client = github.NewClient(tc)
    31  	if c.BaseURL != "" {
    32  		u, err := url.Parse(c.BaseURL)
    33  		if err != nil {
    34  			return nil, err
    35  		}
    36  		org.client.BaseURL = u
    37  	}
    38  	return &org, nil
    39  }