github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/arukas/config.go (about)

     1  package arukas
     2  
     3  import (
     4  	API "github.com/arukasio/cli"
     5  	"os"
     6  	"time"
     7  )
     8  
     9  const (
    10  	JSONTokenParamName   = "ARUKAS_JSON_API_TOKEN"
    11  	JSONSecretParamName  = "ARUKAS_JSON_API_SECRET"
    12  	JSONUrlParamName     = "ARUKAS_JSON_API_URL"
    13  	JSONDebugParamName   = "ARUKAS_DEBUG"
    14  	JSONTimeoutParamName = "ARUKAS_TIMEOUT"
    15  )
    16  
    17  type Config struct {
    18  	Token   string
    19  	Secret  string
    20  	URL     string
    21  	Trace   string
    22  	Timeout int
    23  }
    24  
    25  func (c *Config) NewClient() (*ArukasClient, error) {
    26  
    27  	os.Setenv(JSONTokenParamName, c.Token)
    28  	os.Setenv(JSONSecretParamName, c.Secret)
    29  	os.Setenv(JSONUrlParamName, c.URL)
    30  	os.Setenv(JSONDebugParamName, c.Trace)
    31  
    32  	client, err := API.NewClient()
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  	client.UserAgent = "Terraform for Arukas"
    37  
    38  	timeout := time.Duration(0)
    39  	if c.Timeout > 0 {
    40  		timeout = time.Duration(c.Timeout) * time.Second
    41  	}
    42  
    43  	return &ArukasClient{
    44  		Client:  client,
    45  		Timeout: timeout,
    46  	}, nil
    47  }
    48  
    49  type ArukasClient struct {
    50  	*API.Client
    51  	Timeout time.Duration
    52  }