@@ -64,7 +64,7 @@ public void RequiredNoIdentifiers(string endpoint, string expectedEndpoint)
64
64
var config = SetupConfig ( ) ;
65
65
var client = new EndpointDiscoveryTestClient ( config , baseUrl : endpoint ) ;
66
66
var executionContext = CreateExecutionContext ( client , config , true , null ) ;
67
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
67
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
68
68
69
69
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
70
70
Assert . AreEqual ( expectedEndpoint ,
@@ -84,7 +84,7 @@ public void RequiredNoIdentifiersCached()
84
84
var config = SetupConfig ( ) ;
85
85
var client = new EndpointDiscoveryTestClient ( config ) ;
86
86
var executionContext = CreateExecutionContext ( client , config , true , null ) ;
87
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
87
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
88
88
89
89
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
90
90
Assert . AreEqual ( "https://test123.amazonaws.com/shared/" ,
@@ -115,7 +115,7 @@ public void RequiredNoIdentifiersEvictCache()
115
115
var config = SetupConfig ( ) ;
116
116
var client = new EndpointDiscoveryTestClient ( config ) ;
117
117
var executionContext = CreateExecutionContext ( client , config , true , null ) ;
118
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
118
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
119
119
120
120
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
121
121
Assert . AreEqual ( "https://test123.amazonaws.com/shared/" ,
@@ -156,7 +156,7 @@ public void RequiredWithIdentifiers()
156
156
SortedDictionary < string , string > identifiers = new SortedDictionary < string , string > ( ) ;
157
157
identifiers . Add ( IDENTIFIER_NAME , "test" ) ;
158
158
var executionContext = CreateExecutionContext ( client , config , true , identifiers ) ;
159
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
159
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
160
160
161
161
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
162
162
Assert . AreEqual ( "https://test123.amazonaws.com/shared/CreateTable" ,
@@ -178,7 +178,7 @@ public void RequiredWithIdentifiersCached()
178
178
SortedDictionary < string , string > identifiers = new SortedDictionary < string , string > ( ) ;
179
179
identifiers . Add ( IDENTIFIER_NAME , "test" ) ;
180
180
var executionContext = CreateExecutionContext ( client , config , true , identifiers ) ;
181
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
181
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
182
182
183
183
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
184
184
Assert . AreEqual ( "https://test123.amazonaws.com/shared/CreateTable" ,
@@ -208,7 +208,7 @@ public void RequiredNoIdentifiersFailedDiscovery()
208
208
SortedDictionary < string , string > identifiers = new SortedDictionary < string , string > ( ) ;
209
209
identifiers . Add ( IDENTIFIER_NAME , "test" ) ;
210
210
var executionContext = CreateExecutionContext ( client , config , true , identifiers ) ;
211
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
211
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
212
212
213
213
Utils . AssertExceptionExpected (
214
214
( ) => { EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ; } ,
@@ -227,7 +227,7 @@ public void NotRequiredNoIdentifiersFailedDiscoveryWait()
227
227
var config = SetupConfig ( true ) ;
228
228
var client = new EndpointDiscoveryTestClient ( config , true ) ;
229
229
var executionContext = CreateExecutionContext ( client , config , false , null ) ;
230
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
230
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
231
231
232
232
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
233
233
var endpoints = client . WaitForCachedValue ( CACHEKEY ) ;
@@ -247,7 +247,7 @@ public void NotRequiredEnabledNoIdentifiersWait()
247
247
var config = SetupConfig ( true ) ;
248
248
var client = new EndpointDiscoveryTestClient ( config ) ;
249
249
var executionContext = CreateExecutionContext ( client , config , false , null ) ;
250
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
250
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
251
251
252
252
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
253
253
var endpoints = client . WaitForCachedValue ( CACHEKEY ) ;
@@ -268,7 +268,7 @@ public void NotRequiredEnabledHasIdentifiersWait()
268
268
SortedDictionary < string , string > identifiers = new SortedDictionary < string , string > ( ) ;
269
269
identifiers . Add ( IDENTIFIER_NAME , "test" ) ;
270
270
var executionContext = CreateExecutionContext ( client , config , false , identifiers ) ;
271
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
271
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
272
272
273
273
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
274
274
var endpoints = client . WaitForCachedValue ( CACHEKEY_IDENTIFIERS ) ;
@@ -287,7 +287,7 @@ public void NotRequiredNoIdentifiersFailedDiscoveryNoWait()
287
287
var config = SetupConfig ( true ) ;
288
288
var client = new EndpointDiscoveryTestClient ( config , true ) ;
289
289
var executionContext = CreateExecutionContext ( client , config , false , null ) ;
290
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
290
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
291
291
292
292
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
293
293
@@ -303,7 +303,7 @@ public void NotRequiredEnabledNoIdentifiersNoWait()
303
303
var config = SetupConfig ( true ) ;
304
304
var client = new EndpointDiscoveryTestClient ( config ) ;
305
305
var executionContext = CreateExecutionContext ( client , config , false , null ) ;
306
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
306
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
307
307
308
308
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
309
309
@@ -321,7 +321,7 @@ public void NotRequiredEnabledHasIdentifiersNoWait()
321
321
SortedDictionary < string , string > identifiers = new SortedDictionary < string , string > ( ) ;
322
322
identifiers . Add ( IDENTIFIER_NAME , "test" ) ;
323
323
var executionContext = CreateExecutionContext ( client , config , false , identifiers ) ;
324
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
324
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
325
325
326
326
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
327
327
@@ -343,7 +343,7 @@ public void CacheEvictionTestUsingEndpointDiscoveryCallStack()
343
343
var config = SetupConfig ( ) ;
344
344
var client = new EndpointDiscoveryTestClient ( config ) ;
345
345
var executionContext = CreateExecutionContext ( client , config , true , null ) ;
346
- var immutableCredentials = ( executionContext . RequestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
346
+ var immutableCredentials = GetCredentialsFromContext ( executionContext ) ;
347
347
EndpointDiscoveryHandler . DiscoverEndpoints ( executionContext . RequestContext , false , immutableCredentials ) ;
348
348
349
349
Assert . AreEqual ( 1 , client . CacheCount ) ;
@@ -430,6 +430,16 @@ private bool HasEndpointAddress(IEnumerable<DiscoveryEndpointBase> endpoints, st
430
430
return endpoints . Any ( endpoint =>
431
431
string . Equals ( endpoint ? . Address , address , StringComparison . OrdinalIgnoreCase ) ) ;
432
432
}
433
+
434
+ private ImmutableCredentials GetCredentialsFromContext ( ExecutionContext executionContext )
435
+ {
436
+ if ( executionContext . RequestContext . Identity is AWSCredentials credentials )
437
+ {
438
+ return credentials . GetCredentials ( ) ;
439
+ }
440
+
441
+ return null ;
442
+ }
433
443
}
434
444
435
445
public class EndpointDiscoveryTestClient : AmazonDynamoDBClient
0 commit comments