2014-07-23 23:43:28 +02:00
|
|
|
package dnsimple
|
|
|
|
|
|
|
|
import (
|
2014-07-24 16:21:39 +02:00
|
|
|
"fmt"
|
2014-07-23 23:43:28 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2014-07-24 16:21:39 +02:00
|
|
|
"github.com/pearkes/dnsimple"
|
2014-07-23 23:43:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Token string `mapstructure:"token"`
|
|
|
|
Email string `mapstructure:"email"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client() returns a new client for accessing heroku.
|
|
|
|
//
|
2014-07-24 16:21:39 +02:00
|
|
|
func (c *Config) Client() (*dnsimple.Client, error) {
|
2014-07-23 23:43:28 +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("DNSIMPLE_EMAIL"); v != "" {
|
|
|
|
c.Email = v
|
|
|
|
}
|
|
|
|
if v := os.Getenv("DNSIMPLE_TOKEN"); v != "" {
|
|
|
|
c.Token = v
|
|
|
|
}
|
|
|
|
|
2014-07-24 16:21:39 +02:00
|
|
|
client, err := dnsimple.NewClient(c.Email, c.Token)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error setting up client: %s", err)
|
|
|
|
}
|
2014-07-23 23:43:28 +02:00
|
|
|
|
|
|
|
log.Printf("[INFO] DNSimple Client configured for user: %s", client.Email)
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|