Skip to content

Commit a7c3914

Browse files
committed
perf: use token when user gives username as apikey
1 parent 185ab73 commit a7c3914

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/IBM.WatsonDeveloperCloud/Service/WatsonService.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,20 @@ protected WatsonService(string serviceName, string url, IClient httpClient)
8989
/// <param name="password">The password</param>
9090
public void SetCredential(string userName, string password)
9191
{
92-
this.UserName = userName;
93-
this.Password = password;
92+
if (userName == "apikey")
93+
{
94+
TokenOptions tokenOptions = new TokenOptions()
95+
{
96+
IamApiKey = password
97+
};
98+
99+
SetCredential(tokenOptions);
100+
}
101+
else
102+
{
103+
this.UserName = userName;
104+
this.Password = password;
105+
}
94106
}
95107

96108
/// <summary>
@@ -100,8 +112,18 @@ public void SetCredential(string userName, string password)
100112
/// <param name="options"></param>
101113
public void SetCredential(TokenOptions options)
102114
{
103-
if(!_userSetEndpoint)
104-
this.Endpoint = options.IamUrl;
115+
if (!string.IsNullOrEmpty(options.ServiceUrl))
116+
{
117+
if (!_userSetEndpoint)
118+
{
119+
this.Endpoint = options.ServiceUrl;
120+
}
121+
}
122+
else
123+
{
124+
options.ServiceUrl = this.Endpoint;
125+
}
126+
105127
_tokenManager = new TokenManager(options);
106128
}
107129

0 commit comments

Comments
 (0)