Skip to content

Commit 40312dc

Browse files
committed
Simplify logic
1 parent 40c85a4 commit 40312dc

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

gitlab/config.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ import (
1212

1313
// Config is per-provider, specifies where to connect to gitlab
1414
type Config struct {
15-
Token string
16-
BaseURL string
17-
Insecure bool
18-
CACertFile string
19-
ClientCert string
20-
ClientKey string
21-
TerraformUserAgent string
15+
Token string
16+
BaseURL string
17+
Insecure bool
18+
CACertFile string
19+
ClientCert string
20+
ClientKey string
2221
}
2322

2423
// Client returns a *gitlab.Client to interact with the configured gitlab instance
25-
func (c *Config) Client() (interface{}, error) {
24+
func (c *Config) Client() (*gitlab.Client, error) {
2625
// Configure TLS/SSL
2726
tlsConfig := &tls.Config{}
2827

@@ -62,10 +61,6 @@ func (c *Config) Client() (interface{}, error) {
6261
Transport: logging.NewTransport("GitLab", t),
6362
},
6463
),
65-
func(client *gitlab.Client) error {
66-
client.UserAgent = c.TerraformUserAgent
67-
return nil
68-
},
6964
}
7065

7166
if c.BaseURL != "" {

gitlab/provider.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,18 @@ func providerConfigure(p *schema.Provider, d *schema.ResourceData) (interface{},
129129
Insecure: d.Get("insecure").(bool),
130130
ClientCert: d.Get("client_cert").(string),
131131
ClientKey: d.Get("client_key").(string),
132+
}
132133

133-
// NOTE: httpclient.TerraformUserAgent is deprecated and removed in Terraform SDK v2
134-
// After upgrading the SDK to v2 replace with p.UserAgent()
135-
TerraformUserAgent: httpclient.TerraformUserAgent(p.TerraformVersion),
134+
client, err := config.Client()
135+
if err != nil {
136+
return nil, err
136137
}
137138

138-
return config.Client()
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
139144
}
140145

141146
func validateApiURLVersion(value interface{}, key string) (ws []string, es []error) {

0 commit comments

Comments
 (0)