Skip to content

Commit 4f468e6

Browse files
committed
feat(Authentication): make auth type case insesitive
1 parent 78584a2 commit 4f468e6

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

Authentication/ConfigBasedAuthenticatorFactory.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
using IBM.Cloud.SDK.Authentication.NoAuth;
2323
using IBM.Cloud.SDK.Utilities;
2424
using System.Collections.Generic;
25+
using System;
2526

2627
namespace IBM.Cloud.SDK.Authentication
2728
{
2829
public class ConfigBasedAuthenticatorFactory
2930
{
31+
public static string ErrorMessageAuthTypeUnknown = "Unrecognized authentication type: {0}";
32+
3033
public static Authenticator GetAuthenticator(string serviceName)
3134
{
3235
Authenticator authenticator = null;
@@ -77,29 +80,29 @@ private static Authenticator CreateAuthenticator(Dictionary<string, string> prop
7780
authType = Authenticator.AuthTypeIam;
7881
}
7982

80-
switch (authType)
83+
if (authType.Equals(Authenticator.AuthTypeNoAuth, StringComparison.InvariantCultureIgnoreCase))
8184
{
82-
case Authenticator.AuthTypeNoAuth:
83-
authenticator = new NoAuthAuthenticator(props);
84-
break;
85-
86-
case Authenticator.AuthTypeBasic:
87-
authenticator = new BasicAuthenticator(props);
88-
break;
89-
90-
case Authenticator.AuthTypeIam:
91-
authenticator = new IamAuthenticator(props);
92-
break;
93-
94-
case Authenticator.AuthTypeCp4d:
95-
authenticator = new CloudPakForDataAuthenticator(props);
96-
break;
97-
98-
case Authenticator.AuthTypeBearer:
99-
authenticator = new BearerTokenAuthenticator(props);
100-
break;
101-
default:
102-
break;
85+
authenticator = new NoAuthAuthenticator(props);
86+
}
87+
else if (authType.Equals(Authenticator.AuthTypeBasic, StringComparison.InvariantCultureIgnoreCase))
88+
{
89+
authenticator = new BasicAuthenticator(props);
90+
}
91+
else if (authType.Equals(Authenticator.AuthTypeIam, StringComparison.InvariantCultureIgnoreCase))
92+
{
93+
authenticator = new IamAuthenticator(props);
94+
}
95+
else if (authType.Equals(Authenticator.AuthTypeCp4d, StringComparison.InvariantCultureIgnoreCase))
96+
{
97+
authenticator = new CloudPakForDataAuthenticator(props);
98+
}
99+
else if (authType.Equals(Authenticator.AuthTypeBearer, StringComparison.InvariantCultureIgnoreCase))
100+
{
101+
authenticator = new BearerTokenAuthenticator(props);
102+
}
103+
else
104+
{
105+
throw new ArgumentException(string.Format(ErrorMessageAuthTypeUnknown, authType));
103106
}
104107

105108
return authenticator;

0 commit comments

Comments
 (0)