-
Notifications
You must be signed in to change notification settings - Fork 132
/
config.go
46 lines (34 loc) · 1.11 KB
/
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
package fastly
import (
"fmt"
gofastly "github.com/fastly/go-fastly/v2/fastly"
"github.com/fastly/terraform-provider-fastly/version"
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
)
const TerraformProviderProductUserAgent = "terraform-provider-fastly"
type Config struct {
ApiKey string
BaseURL string
terraformVersion string
}
type FastlyClient struct {
conn *gofastly.Client
}
func (c *Config) Client() (interface{}, error) {
var client FastlyClient
if c.ApiKey == "" {
return nil, fmt.Errorf("[Err] No API key for Fastly")
}
tfUserAgent := httpclient.TerraformUserAgent(c.terraformVersion)
providerUserAgent := fmt.Sprintf("%s/%s", TerraformProviderProductUserAgent, version.ProviderVersion)
ua := fmt.Sprintf("%s %s", tfUserAgent, providerUserAgent)
gofastly.UserAgent = ua
fastlyClient, err := gofastly.NewClientForEndpoint(c.ApiKey, c.BaseURL)
if err != nil {
return nil, err
}
fastlyClient.HTTPClient.Transport = logging.NewTransport("Fastly", fastlyClient.HTTPClient.Transport)
client.conn = fastlyClient
return &client, nil
}