github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ns1/config.go (about)

     1  package ns1
     2  
     3  import (
     4  	"crypto/tls"
     5  	"errors"
     6  	"log"
     7  	"net/http"
     8  
     9  	ns1 "gopkg.in/ns1/ns1-go.v2/rest"
    10  )
    11  
    12  type Config struct {
    13  	Key       string
    14  	Endpoint  string
    15  	IgnoreSSL bool
    16  }
    17  
    18  // Client() returns a new NS1 client.
    19  func (c *Config) Client() (*ns1.Client, error) {
    20  	httpClient := &http.Client{}
    21  	decos := []func(*ns1.Client){}
    22  
    23  	if c.Key == "" {
    24  		return nil, errors.New(`No valid credential sources found for NS1 Provider.
    25    Please see https://terraform.io/docs/providers/ns1/index.html for more information on
    26    providing credentials for the NS1 Provider`)
    27  	}
    28  
    29  	decos = append(decos, ns1.SetAPIKey(c.Key))
    30  	if c.Endpoint != "" {
    31  		decos = append(decos, ns1.SetEndpoint(c.Endpoint))
    32  	}
    33  	if c.IgnoreSSL {
    34  		tr := &http.Transport{
    35  			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    36  		}
    37  		httpClient.Transport = tr
    38  	}
    39  
    40  	client := ns1.NewClient(httpClient, decos...)
    41  	client.RateLimitStrategySleep()
    42  
    43  	log.Printf("[INFO] NS1 Client configured for Endpoint: %s", client.Endpoint.String())
    44  
    45  	return client, nil
    46  }