Skip to content

Commit ff0bb62

Browse files
committed
review: 3
1 parent 439df49 commit ff0bb62

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

providers/dns/nicru/internal/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/xml"
77
"errors"
8+
"fmt"
89
"net/http"
910
"net/url"
1011
"strconv"
@@ -27,14 +28,12 @@ type OauthConfiguration struct {
2728
Password string
2829
}
2930

30-
func NewOauthClient(config *OauthConfiguration) (*http.Client, error) {
31+
func NewOauthClient(ctx context.Context, config *OauthConfiguration) (*http.Client, error) {
3132
err := validateAuthOptions(config)
3233
if err != nil {
3334
return nil, err
3435
}
3536

36-
ctx := context.TODO()
37-
3837
oauth2Config := oauth2.Config{
3938
ClientID: config.OAuth2ClientID,
4039
ClientSecret: config.OAuth2SecretID,
@@ -47,7 +46,7 @@ func NewOauthClient(config *OauthConfiguration) (*http.Client, error) {
4746

4847
oauth2Token, err := oauth2Config.PasswordCredentialsToken(ctx, config.Username, config.Password)
4948
if err != nil {
50-
return nil, err
49+
return nil, fmt.Errorf("failed to create oauth2 token: %w", err)
5150
}
5251

5352
return oauth2Config.Client(ctx, oauth2Token), nil

providers/dns/nicru/nicru.go

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

44
import (
5+
"context"
56
"errors"
67
"fmt"
78
"time"
@@ -87,7 +88,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
8788
Password: config.Password,
8889
}
8990

90-
oauthClient, err := internal.NewOauthClient(clientCfg)
91+
oauthClient, err := internal.NewOauthClient(context.Background(), clientCfg)
9192
if err != nil {
9293
return nil, fmt.Errorf("nicru: %w", err)
9394
}

providers/dns/nicru/nicru_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestNewDNSProvider(t *testing.T) {
3636
EnvUsername: fakeUsername,
3737
EnvPassword: fakePassword,
3838
},
39+
expected: "nicru: failed to create oauth2 token: oauth2: cannot fetch token: 401 Unauthorized\nResponse: {\"error\":\"invalid_client\"}",
3940
},
4041
{
4142
desc: "missing serviceId",
@@ -127,6 +128,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
127128
PropagationTimeout: defaultPropagationTimeout,
128129
PollingInterval: defaultPollingInterval,
129130
},
131+
expected: "nicru: failed to create oauth2 token: oauth2: cannot fetch token: 401 Unauthorized\nResponse: {\"error\":\"invalid_client\"}",
130132
},
131133
{
132134
desc: "nil config",
@@ -142,7 +144,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
142144
PropagationTimeout: defaultPropagationTimeout,
143145
PollingInterval: defaultPollingInterval,
144146
},
145-
expected: "nicru: unable to build RU CENTER client: service name is missing in credentials information",
147+
expected: "nicru: serviceId is missing in credentials information",
146148
},
147149
{
148150
desc: "missing username",
@@ -154,7 +156,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
154156
PropagationTimeout: defaultPropagationTimeout,
155157
PollingInterval: defaultPollingInterval,
156158
},
157-
expected: "nicru: unable to build RU CENTER client: username is missing in credentials information",
159+
expected: "nicru: username is missing in credentials information",
158160
},
159161
{
160162
desc: "missing password",
@@ -167,7 +169,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
167169
PropagationTimeout: defaultPropagationTimeout,
168170
PollingInterval: defaultPollingInterval,
169171
},
170-
expected: "nicru: unable to build RU CENTER client: password is missing in credentials information",
172+
expected: "nicru: password is missing in credentials information",
171173
},
172174
{
173175
desc: "missing secret",
@@ -179,7 +181,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
179181
PropagationTimeout: defaultPropagationTimeout,
180182
PollingInterval: defaultPollingInterval,
181183
},
182-
expected: "nicru: unable to build RU CENTER client: secret is missing in credentials information",
184+
expected: "nicru: secret is missing in credentials information",
183185
},
184186
{
185187
desc: "missing serviceId",
@@ -190,7 +192,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
190192
Password: fakePassword,
191193
Domain: defaultDomainName,
192194
},
193-
expected: "nicru: unable to build RU CENTER client: serviceId is missing in credentials information",
195+
expected: "nicru: serviceId is missing in credentials information",
194196
},
195197
}
196198

0 commit comments

Comments
 (0)