@@ -38,7 +38,9 @@ public override void InvokeSync(IExecutionContext executionContext)
38
38
{
39
39
var requestContext = executionContext . RequestContext ;
40
40
var regionalEndpoint = requestContext . Request . Endpoint ;
41
- PreInvoke ( executionContext ) ;
41
+ var immutableCredentials = ( requestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
42
+
43
+ PreInvoke ( executionContext , immutableCredentials ) ;
42
44
43
45
try
44
46
{
@@ -49,7 +51,7 @@ public override void InvokeSync(IExecutionContext executionContext)
49
51
{
50
52
if ( IsInvalidEndpointException ( exception ) )
51
53
{
52
- EvictCacheKeyForRequest ( requestContext , regionalEndpoint ) ;
54
+ EvictCacheKeyForRequest ( requestContext , regionalEndpoint , immutableCredentials ) ;
53
55
}
54
56
55
57
throw ;
@@ -69,7 +71,9 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
69
71
{
70
72
var requestContext = executionContext . RequestContext ;
71
73
var regionalEndpoint = requestContext . Request . Endpoint ;
72
- PreInvoke ( executionContext ) ;
74
+ var immutableCredentials = await ( ( requestContext . Identity as AWSCredentials ) ? . GetCredentialsAsync ( ) ) . ConfigureAwait ( false ) ;
75
+
76
+ PreInvoke ( executionContext , immutableCredentials ) ;
73
77
74
78
try
75
79
{
@@ -80,7 +84,7 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
80
84
var capturedException = System . Runtime . ExceptionServices . ExceptionDispatchInfo . Capture ( exception ) ;
81
85
if ( IsInvalidEndpointException ( capturedException . SourceException ) )
82
86
{
83
- EvictCacheKeyForRequest ( requestContext , regionalEndpoint ) ;
87
+ EvictCacheKeyForRequest ( requestContext , regionalEndpoint , immutableCredentials ) ;
84
88
}
85
89
86
90
capturedException . Throw ( ) ;
@@ -94,22 +98,22 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
94
98
/// Resolves the endpoint to be used for the current request
95
99
/// before invoking the next handler.
96
100
/// </summary>
97
- /// <param name="executionContext">The execution context, it contains the
98
- /// request and response context.</ param>
99
- protected static void PreInvoke ( IExecutionContext executionContext )
101
+ /// <param name="executionContext">The execution context, it contains the request and response context.</param>
102
+ /// < param name="credentials">The AWS credentials for the account making the service call.</param>
103
+ protected static void PreInvoke ( IExecutionContext executionContext , ImmutableCredentials credentials )
100
104
{
101
- DiscoverEndpoints ( executionContext . RequestContext , false ) ;
105
+ DiscoverEndpoints ( executionContext . RequestContext , false , credentials ) ;
102
106
}
103
107
104
- public static void EvictCacheKeyForRequest ( IRequestContext requestContext , Uri regionalEndpoint )
108
+ public static void EvictCacheKeyForRequest ( IRequestContext requestContext , Uri regionalEndpoint , ImmutableCredentials credentials )
105
109
{
106
- DiscoverEndpoints ( requestContext , true ) ;
110
+ DiscoverEndpoints ( requestContext , true , credentials ) ;
107
111
requestContext . Request . Endpoint = regionalEndpoint ;
108
112
}
109
113
110
- public static void DiscoverEndpoints ( IRequestContext requestContext , bool evictCacheKey )
114
+ public static void DiscoverEndpoints ( IRequestContext requestContext , bool evictCacheKey , ImmutableCredentials credentials )
111
115
{
112
- var discoveryEndpoints = ProcessEndpointDiscovery ( requestContext , evictCacheKey , requestContext . Request . Endpoint ) ;
116
+ var discoveryEndpoints = ProcessEndpointDiscovery ( requestContext , evictCacheKey , requestContext . Request . Endpoint , credentials ) ;
113
117
if ( discoveryEndpoints != null )
114
118
{
115
119
foreach ( var endpoint in discoveryEndpoints )
@@ -130,12 +134,11 @@ public static void DiscoverEndpoints(IRequestContext requestContext, bool evictC
130
134
}
131
135
}
132
136
133
- private static IEnumerable < DiscoveryEndpointBase > ProcessEndpointDiscovery ( IRequestContext requestContext , bool evictCacheKey , Uri evictUri )
137
+ private static IEnumerable < DiscoveryEndpointBase > ProcessEndpointDiscovery ( IRequestContext requestContext , bool evictCacheKey , Uri evictUri , ImmutableCredentials credentials )
134
138
{
135
139
var options = requestContext . Options ;
136
- var immutableCredentials = ( requestContext . Identity as AWSCredentials ) ? . GetCredentials ( ) ;
137
140
138
- if ( options . EndpointDiscoveryMarshaller != null && options . EndpointOperation != null && immutableCredentials != null )
141
+ if ( options . EndpointDiscoveryMarshaller != null && options . EndpointOperation != null && credentials != null )
139
142
{
140
143
//Endpoint discovery is supported by this operation and we have an endpoint operation available to use
141
144
var endpointDiscoveryData = options . EndpointDiscoveryMarshaller . Marshall ( requestContext . OriginalRequest ) ;
@@ -144,7 +147,7 @@ private static IEnumerable<DiscoveryEndpointBase> ProcessEndpointDiscovery(IRequ
144
147
{
145
148
operationName = AWSSDKUtils . ExtractOperationName ( requestContext . RequestName ) ;
146
149
}
147
- return options . EndpointOperation ( new EndpointOperationContext ( immutableCredentials . AccessKey , operationName , endpointDiscoveryData , evictCacheKey , evictUri ) ) ;
150
+ return options . EndpointOperation ( new EndpointOperationContext ( credentials . AccessKey , operationName , endpointDiscoveryData , evictCacheKey , evictUri ) ) ;
148
151
}
149
152
150
153
return null ;
0 commit comments