Skip to content

Commit 925be85

Browse files
authored
Merge pull request #7 from IBM/credential-file-iam-fix
Look for iam_apikey in credential file for IAM auth
2 parents e89b299 + c46e68b commit 925be85

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

BaseService.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
using IBM.Cloud.SDK.Utilities;
1919
using System;
20-
using System.Collections.Generic;
21-
20+
using System.Collections.Generic;
21+
2222
namespace IBM.Cloud.SDK
2323
{
2424
public class BaseService
@@ -40,7 +40,11 @@ public BaseService(string serviceId)
4040
}
4141
}
4242

43-
string ApiKey = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_APIKEY");
43+
string ApiKey = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_IAM_APIKEY");
44+
// check for old IAM API key name as well
45+
if (string.IsNullOrEmpty(apiKey)) {
46+
apiKey = Environment.GetEnvironmentVariable(ServiceName.ToUpper() + "_APIKEY");
47+
}
4448
string Username = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_USERNAME");
4549
string Password = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_PASSWORD");
4650
string ServiceUrl = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_URL");
@@ -78,36 +82,36 @@ public BaseService(string versionDate, Credentials credentials, string serviceId
7882

7983
public BaseService(Credentials credentials, string serviceId) { }
8084

81-
public void WithHeader(string name, string value)
85+
public void WithHeader(string name, string value)
8286
{
83-
if (!customRequestHeaders.ContainsKey(name))
84-
{
85-
customRequestHeaders.Add(name, value);
87+
if (!customRequestHeaders.ContainsKey(name))
88+
{
89+
customRequestHeaders.Add(name, value);
90+
}
91+
else
92+
{
93+
customRequestHeaders[name] = value;
8694
}
87-
else
88-
{
89-
customRequestHeaders[name] = value;
90-
}
9195
}
9296

93-
public void WithHeaders(Dictionary<string, string> headers)
97+
public void WithHeaders(Dictionary<string, string> headers)
9498
{
95-
foreach (KeyValuePair<string, string> kvp in headers)
99+
foreach (KeyValuePair<string, string> kvp in headers)
96100
{
97-
if (!customRequestHeaders.ContainsKey(kvp.Key))
98-
{
99-
customRequestHeaders.Add(kvp.Key, kvp.Value);
101+
if (!customRequestHeaders.ContainsKey(kvp.Key))
102+
{
103+
customRequestHeaders.Add(kvp.Key, kvp.Value);
104+
}
105+
else
106+
{
107+
customRequestHeaders[kvp.Key] = kvp.Value;
100108
}
101-
else
102-
{
103-
customRequestHeaders[kvp.Key] = kvp.Value;
104-
}
105-
}
109+
}
106110
}
107111

108-
protected void ClearCustomRequestHeaders()
109-
{
110-
customRequestHeaders = new Dictionary<string, string>();
112+
protected void ClearCustomRequestHeaders()
113+
{
114+
customRequestHeaders = new Dictionary<string, string>();
111115
}
112116
}
113117
}

0 commit comments

Comments
 (0)