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

     1  package mailgun
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/pearkes/mailgun"
     8  )
     9  
    10  type Config struct {
    11  	APIKey string `mapstructure:"api_key"`
    12  }
    13  
    14  // Client() returns a new client for accessing mailgun.
    15  //
    16  func (c *Config) Client() (*mailgun.Client, error) {
    17  
    18  	// If we have env vars set (like in the acc) tests,
    19  	// we need to override the values passed in here.
    20  	if v := os.Getenv("MAILGUN_API_KEY"); v != "" {
    21  		c.APIKey = v
    22  	}
    23  
    24  	// We don't set a domain right away
    25  	client, err := mailgun.NewClient(c.APIKey)
    26  
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	log.Printf("[INFO] Mailgun Client configured ")
    32  
    33  	return client, nil
    34  }