2014-07-23 06:03:30 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
"github.com/cyberdelia/heroku-go/v3"
|
2014-07-23 06:03:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
APIKey string `mapstructure:"api_key"`
|
|
|
|
Email string `mapstructure:"email"`
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
// Client() returns a new Service for accessing Heroku.
|
2014-07-23 06:03:30 +02:00
|
|
|
//
|
2014-08-27 16:50:37 +02:00
|
|
|
func (c *Config) Client() (*heroku.Service, error) {
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
// If we have env vars set (like in the acc) tests,
|
|
|
|
// we need to override the values passed in here.
|
|
|
|
if v := os.Getenv("HEROKU_EMAIL"); v != "" {
|
|
|
|
c.Email = v
|
|
|
|
}
|
|
|
|
if v := os.Getenv("HEROKU_API_KEY"); v != "" {
|
|
|
|
c.APIKey = v
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
heroku.DefaultTransport.Username = c.Email
|
|
|
|
heroku.DefaultTransport.Password = c.APIKey
|
|
|
|
|
|
|
|
client := heroku.NewService(heroku.DefaultClient)
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
log.Printf("[INFO] Heroku Client configured for user: %s", c.Email)
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
return client, nil
|
2014-07-23 06:03:30 +02:00
|
|
|
}
|