forked from hashicorp/terraform
/
config.go
52 lines (43 loc) · 978 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package arukas
import (
API "github.com/arukasio/cli"
"os"
"time"
)
const (
JSONTokenParamName = "ARUKAS_JSON_API_TOKEN"
JSONSecretParamName = "ARUKAS_JSON_API_SECRET"
JSONUrlParamName = "ARUKAS_JSON_API_URL"
JSONDebugParamName = "ARUKAS_DEBUG"
JSONTimeoutParamName = "ARUKAS_TIMEOUT"
)
type Config struct {
Token string
Secret string
URL string
Trace string
Timeout int
}
func (c *Config) NewClient() (*ArukasClient, error) {
os.Setenv(JSONTokenParamName, c.Token)
os.Setenv(JSONSecretParamName, c.Secret)
os.Setenv(JSONUrlParamName, c.URL)
os.Setenv(JSONDebugParamName, c.Trace)
client, err := API.NewClient()
if err != nil {
return nil, err
}
client.UserAgent = "Terraform for Arukas"
timeout := time.Duration(0)
if c.Timeout > 0 {
timeout = time.Duration(c.Timeout) * time.Second
}
return &ArukasClient{
Client: client,
Timeout: timeout,
}, nil
}
type ArukasClient struct {
*API.Client
Timeout time.Duration
}