2014-07-19 02:20:28 +02:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2014-11-02 23:44:32 +01:00
|
|
|
"os"
|
2014-07-19 02:20:28 +02:00
|
|
|
|
|
|
|
"github.com/pearkes/digitalocean"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Token string `mapstructure:"token"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client() returns a new client for accessing digital
|
|
|
|
// ocean.
|
|
|
|
//
|
|
|
|
func (c *Config) Client() (*digitalocean.Client, error) {
|
2014-11-02 23:44:32 +01: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("DIGITALOCEAN_TOKEN"); v != "" {
|
|
|
|
c.Token = v
|
|
|
|
}
|
|
|
|
|
2014-07-19 02:20:28 +02:00
|
|
|
client, err := digitalocean.NewClient(c.Token)
|
|
|
|
|
|
|
|
log.Printf("[INFO] DigitalOcean Client configured for URL: %s", client.URL)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|