-
Notifications
You must be signed in to change notification settings - Fork 21
/
config.go
42 lines (34 loc) · 1.15 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
package ionoscloud
import (
"fmt"
"log"
"runtime"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
ionoscloud "github.com/ionos-cloud/sdk-go/v6"
)
// Config represents
type Config struct {
Username string
Password string
Endpoint string
Retries int
Token string
}
// Client returns a new client for accessing ionoscloud.
func (c *Config) Client(terraformVersion string) (*ionoscloud.APIClient, error) {
var client *ionoscloud.APIClient
if c.Token != "" {
client = ionoscloud.NewAPIClient(ionoscloud.NewConfiguration("", "", c.Token, c.Endpoint))
} else {
client = ionoscloud.NewAPIClient(ionoscloud.NewConfiguration(c.Username, c.Password, "", c.Endpoint))
}
client.GetConfig().UserAgent = fmt.Sprintf(
"terraform-provider/%s_ionos-cloud-sdk-go/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
Version, ionoscloud.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH)
log.Printf("[DEBUG] Terraform client UA set to %s", client.GetConfig().UserAgent)
client.GetConfig().AddDefaultQueryParam("depth", "5")
if len(c.Endpoint) > 0 {
client.GetConfig().Host = c.Endpoint
}
return client, nil
}