github.com/IBM-Cloud/terraform@v0.6.4-0.20170726051544-8872b87621df/builtin/providers/github/config.go (about)

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