Skip to content

Commit a0874a4

Browse files
committed
Enable custom UserAgent
1 parent 21ad328 commit a0874a4

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

gitlab/config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitlab
33
import (
44
"crypto/tls"
55
"crypto/x509"
6+
"fmt"
67
"io/ioutil"
78
"net/http"
89

@@ -12,12 +13,13 @@ import (
1213

1314
// Config is per-provider, specifies where to connect to gitlab
1415
type Config struct {
15-
Token string
16-
BaseURL string
17-
Insecure bool
18-
CACertFile string
19-
ClientCert string
20-
ClientKey string
16+
Token string
17+
BaseURL string
18+
Insecure bool
19+
CACertFile string
20+
ClientCert string
21+
ClientKey string
22+
TerraformVersion string
2123
}
2224

2325
// Client returns a *gitlab.Client to interact with the configured gitlab instance
@@ -61,6 +63,10 @@ func (c *Config) Client() (interface{}, error) {
6163
Transport: logging.NewTransport("GitLab", t),
6264
},
6365
),
66+
func(client *gitlab.Client) error {
67+
client.UserAgent = fmt.Sprintf("terraform-provider-gitlab/%s", c.TerraformVersion)
68+
return nil
69+
},
6470
}
6571

6672
if c.BaseURL != "" {

gitlab/provider.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ func init() {
118118

119119
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
120120
config := Config{
121-
Token: d.Get("token").(string),
122-
BaseURL: d.Get("base_url").(string),
123-
CACertFile: d.Get("cacert_file").(string),
124-
Insecure: d.Get("insecure").(bool),
125-
ClientCert: d.Get("client_cert").(string),
126-
ClientKey: d.Get("client_key").(string),
121+
Token: d.Get("token").(string),
122+
BaseURL: d.Get("base_url").(string),
123+
CACertFile: d.Get("cacert_file").(string),
124+
Insecure: d.Get("insecure").(bool),
125+
ClientCert: d.Get("client_cert").(string),
126+
ClientKey: d.Get("client_key").(string),
127+
TerraformVersion: "TODO", // TODO: How to get Terraform version?
127128
}
128129

129130
return config.Client()
@@ -132,7 +133,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
132133
func validateApiURLVersion(value interface{}, key string) (ws []string, es []error) {
133134
v := value.(string)
134135
if strings.HasSuffix(v, "/api/v3") || strings.HasSuffix(v, "/api/v3/") {
135-
es = append(es, fmt.Errorf("terraform-gitlab-provider does not support v3 api; please upgrade to /api/v4 in %s", v))
136+
es = append(es, fmt.Errorf("terraform-provider-gitlab does not support v3 api; please upgrade to /api/v4 in %s", v))
136137
}
137138
return
138139
}

0 commit comments

Comments
 (0)