github.com/maheshbr/terraform@v0.3.1-0.20141020033300-deec7194a3ea/builtin/providers/heroku/config.go (about)

     1  package heroku
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  	"os"
     7  
     8  	"github.com/cyberdelia/heroku-go/v3"
     9  )
    10  
    11  type Config struct {
    12  	APIKey string `mapstructure:"api_key"`
    13  	Email  string `mapstructure:"email"`
    14  }
    15  
    16  // Client() returns a new Service for accessing Heroku.
    17  //
    18  func (c *Config) Client() (*heroku.Service, error) {
    19  
    20  	// If we have env vars set (like in the acc) tests,
    21  	// we need to override the values passed in here.
    22  	if v := os.Getenv("HEROKU_EMAIL"); v != "" {
    23  		c.Email = v
    24  	}
    25  	if v := os.Getenv("HEROKU_API_KEY"); v != "" {
    26  		c.APIKey = v
    27  	}
    28  
    29  	service := heroku.NewService(&http.Client{
    30  		Transport: &heroku.Transport{
    31  			Username:  c.Email,
    32  			Password:  c.APIKey,
    33  			UserAgent: heroku.DefaultUserAgent,
    34  		},
    35  	})
    36  
    37  	log.Printf("[INFO] Heroku Client configured for user: %s", c.Email)
    38  
    39  	return service, nil
    40  }