Skip to content

Commit f825849

Browse files
committed
Use context when querying current user during provider configuration
1 parent 71c711d commit f825849

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

internal/provider/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider
22

33
import (
4+
"context"
45
"crypto/tls"
56
"crypto/x509"
67
"io/ioutil"
@@ -22,7 +23,7 @@ type Config struct {
2223
}
2324

2425
// Client returns a *gitlab.Client to interact with the configured gitlab instance
25-
func (c *Config) Client() (*gitlab.Client, error) {
26+
func (c *Config) Client(ctx context.Context) (*gitlab.Client, error) {
2627
// Configure TLS/SSL
2728
tlsConfig := &tls.Config{}
2829

@@ -78,7 +79,7 @@ func (c *Config) Client() (*gitlab.Client, error) {
7879

7980
// Test the credentials by checking we can get information about the authenticated user.
8081
if c.EarlyAuthFail {
81-
_, _, err = client.Users.CurrentUser()
82+
_, _, err = client.Users.CurrentUser(gitlab.WithContext(ctx))
8283
}
8384

8485
return client, err

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
105105
EarlyAuthFail: d.Get("early_auth_check").(bool),
106106
}
107107

108-
client, err := config.Client()
108+
client, err := config.Client(ctx)
109109
if err != nil {
110110
return nil, diag.FromErr(err)
111111
}

internal/provider/provider_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider
22

33
import (
4+
"context"
45
"os"
56
"testing"
67

@@ -35,7 +36,7 @@ var testGitlabClient *gitlab.Client
3536

3637
func init() {
3738
if os.Getenv(resource.EnvTfAcc) != "" {
38-
client, err := testGitlabConfig.Client()
39+
client, err := testGitlabConfig.Client(context.Background())
3940
if err != nil {
4041
panic("failed to create test client: " + err.Error()) // lintignore: R009 // TODO: Resolve this tfproviderlint issue
4142
}

0 commit comments

Comments
 (0)