-
Notifications
You must be signed in to change notification settings - Fork 132
/
config.go
38 lines (29 loc) · 831 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
package fastly
import (
"fmt"
gofastly "github.com/fastly/go-fastly/v3/fastly"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
)
type Config struct {
ApiKey string
BaseURL string
UserAgent string
}
type FastlyClient struct {
conn *gofastly.Client
}
func (c *Config) Client() (*FastlyClient, diag.Diagnostics) {
var client FastlyClient
if c.ApiKey == "" {
return nil, diag.FromErr(fmt.Errorf("[Err] No API key for Fastly"))
}
gofastly.UserAgent = c.UserAgent
fastlyClient, err := gofastly.NewClientForEndpoint(c.ApiKey, c.BaseURL)
if err != nil {
return nil, diag.FromErr(err)
}
fastlyClient.HTTPClient.Transport = logging.NewTransport("Fastly", fastlyClient.HTTPClient.Transport)
client.conn = fastlyClient
return &client, nil
}