|
22 | 22 | using IBM.Cloud.SDK.Authentication.NoAuth;
|
23 | 23 | using IBM.Cloud.SDK.Utilities;
|
24 | 24 | using System.Collections.Generic;
|
| 25 | +using System; |
25 | 26 |
|
26 | 27 | namespace IBM.Cloud.SDK.Authentication
|
27 | 28 | {
|
28 | 29 | public class ConfigBasedAuthenticatorFactory
|
29 | 30 | {
|
| 31 | + public static string ErrorMessageAuthTypeUnknown = "Unrecognized authentication type: {0}"; |
| 32 | + |
30 | 33 | public static Authenticator GetAuthenticator(string serviceName)
|
31 | 34 | {
|
32 | 35 | Authenticator authenticator = null;
|
@@ -77,29 +80,29 @@ private static Authenticator CreateAuthenticator(Dictionary<string, string> prop
|
77 | 80 | authType = Authenticator.AuthTypeIam;
|
78 | 81 | }
|
79 | 82 |
|
80 |
| - switch (authType) |
| 83 | + if (authType.Equals(Authenticator.AuthTypeNoAuth, StringComparison.InvariantCultureIgnoreCase)) |
81 | 84 | {
|
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)); |
103 | 106 | }
|
104 | 107 |
|
105 | 108 | return authenticator;
|
|
0 commit comments