Skip to content

Commit f082dd9

Browse files
Merge pull request #451 from bishtawi/sb/user-agent
Enable custom UserAgent
2 parents a4ed289 + 40312dc commit f082dd9

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

gitlab/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Config struct {
2121
}
2222

2323
// Client returns a *gitlab.Client to interact with the configured gitlab instance
24-
func (c *Config) Client() (interface{}, error) {
24+
func (c *Config) Client() (*gitlab.Client, error) {
2525
// Configure TLS/SSL
2626
tlsConfig := &tls.Config{}
2727

gitlab/provider.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"strings"
66

77
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
89
"github.com/hashicorp/terraform-plugin-sdk/terraform"
910
)
1011

1112
// Provider returns a terraform.ResourceProvider.
1213
func Provider() terraform.ResourceProvider {
1314

1415
// The actual provider
15-
return &schema.Provider{
16+
provider := &schema.Provider{
1617
Schema: map[string]*schema.Schema{
1718
"token": {
1819
Type: schema.TypeString,
@@ -93,9 +94,13 @@ func Provider() terraform.ResourceProvider {
9394
"gitlab_project_mirror": resourceGitlabProjectMirror(),
9495
"gitlab_project_level_mr_approvals": resourceGitlabProjectLevelMRApprovals(),
9596
},
97+
}
9698

97-
ConfigureFunc: providerConfigure,
99+
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
100+
return providerConfigure(provider, d)
98101
}
102+
103+
return provider
99104
}
100105

101106
var descriptions map[string]string
@@ -116,7 +121,7 @@ func init() {
116121
}
117122
}
118123

119-
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
124+
func providerConfigure(p *schema.Provider, d *schema.ResourceData) (interface{}, error) {
120125
config := Config{
121126
Token: d.Get("token").(string),
122127
BaseURL: d.Get("base_url").(string),
@@ -126,13 +131,22 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
126131
ClientKey: d.Get("client_key").(string),
127132
}
128133

129-
return config.Client()
134+
client, err := config.Client()
135+
if err != nil {
136+
return nil, err
137+
}
138+
139+
// NOTE: httpclient.TerraformUserAgent is deprecated and removed in Terraform SDK v2
140+
// After upgrading the SDK to v2 replace with p.UserAgent("terraform-provider-gitlab")
141+
client.UserAgent = httpclient.TerraformUserAgent(p.TerraformVersion) + " terraform-provider-gitlab"
142+
143+
return client, err
130144
}
131145

132146
func validateApiURLVersion(value interface{}, key string) (ws []string, es []error) {
133147
v := value.(string)
134148
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))
149+
es = append(es, fmt.Errorf("terraform-provider-gitlab does not support v3 api; please upgrade to /api/v4 in %s", v))
136150
}
137151
return
138152
}

0 commit comments

Comments
 (0)