forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
38 lines (29 loc) · 765 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package dnsimple
import (
"fmt"
"log"
"os"
"github.com/pearkes/dnsimple"
)
type Config struct {
Token string `mapstructure:"token"`
Email string `mapstructure:"email"`
}
// Client() returns a new client for accessing dnsimple.
//
func (c *Config) Client() (*dnsimple.Client, error) {
// 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
}
client, err := dnsimple.NewClient(c.Email, c.Token)
if err != nil {
return nil, fmt.Errorf("Error setting up client: %s", err)
}
log.Printf("[INFO] DNSimple Client configured for user: %s", client.Email)
return client, nil
}