Skip to content

Commit 6cacad8

Browse files
committed
Don't throw a NoDefaultRegionSetException if the service includes a region-independent endpoint
1 parent 9c84cf0 commit 6cacad8

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

src/corelib/Providers/Rackspace/CloudBlockStorageProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public CloudBlockStorageProvider(CloudIdentity identity, IIdentityProvider ident
131131
/// the specified default identity, default region, identity provider, and REST service implementation.
132132
/// </summary>
133133
/// <param name="identity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
134-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
134+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
135135
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="identity"/> as the default identity.</param>
136136
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
137137
public CloudBlockStorageProvider(CloudIdentity identity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)
@@ -143,7 +143,7 @@ public CloudBlockStorageProvider(CloudIdentity identity, string defaultRegion, I
143143
/// implementation, and block storage validator.
144144
/// </summary>
145145
/// <param name="identity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
146-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
146+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
147147
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created with no default identity.</param>
148148
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
149149
/// <param name="cloudBlockStorageValidator">The <see cref="IBlockStorageValidator"/> to use for validating requests to this service.</param>

src/corelib/Providers/Rackspace/CloudFilesProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public CloudFilesProvider(CloudIdentity defaultIdentity, IIdentityProvider ident
140140
/// delete results mapper.
141141
/// </summary>
142142
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
143-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
143+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
144144
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
145145
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
146146
public CloudFilesProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)
@@ -152,7 +152,7 @@ public CloudFilesProvider(CloudIdentity defaultIdentity, string defaultRegion, I
152152
/// provider, REST service implementation, validator, metadata processor, encoder,
153153
/// status parser, and bulk delete results mapper.
154154
/// </summary>
155-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
155+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
156156
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created with no default identity.</param>
157157
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
158158
/// <param name="cloudFilesValidator">The <see cref="IObjectStorageValidator"/> to use for validating requests to this service.</param>
@@ -181,7 +181,7 @@ internal CloudFilesProvider(string defaultRegion, IIdentityProvider identityProv
181181
/// delete results mapper.
182182
/// </summary>
183183
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
184-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
184+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
185185
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
186186
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
187187
/// <param name="cloudFilesValidator">The <see cref="IObjectStorageValidator"/> to use for validating requests to this service.</param>

src/corelib/Providers/Rackspace/CloudNetworksProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public CloudNetworksProvider(CloudIdentity identity, IIdentityProvider identity
101101
/// service implementation.
102102
/// </summary>
103103
/// <param name="identity">An instance of a <see cref="net.openstack.Core.Domain.CloudIdentity"/> object. <remarks>If not provided, the user will be required to pass a <see cref="net.openstack.Core.Domain.CloudIdentity"/> object to each method individually.</remarks></param>
104-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
104+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
105105
/// <param name="identityProvider">An instance of an <see cref="IIdentityProvider"/> to override the default <see cref="CloudIdentity"/></param>
106106
/// <param name="restService">An instance of an <see cref="IRestService"/> to override the default <see cref="JsonRestServices"/></param>
107107
public CloudNetworksProvider(CloudIdentity identity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)

src/corelib/Providers/Rackspace/CloudServersProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public CloudServersProvider(CloudIdentity identity, IIdentityProvider identityPr
106106
/// service implementation.
107107
/// </summary>
108108
/// <param name="identity">An instance of a <see cref="net.openstack.Core.Domain.CloudIdentity"/> object. <remarks>If not provided, the user will be required to pass a <see cref="net.openstack.Core.Domain.CloudIdentity"/> object to each method individually.</remarks></param>
109-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
109+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
110110
/// <param name="identityProvider">An instance of an <see cref="IIdentityProvider"/> to override the default <see cref="CloudIdentity"/></param>
111111
/// <param name="restService">An instance of an <see cref="IRestService"/> to override the default <see cref="JsonRestServices"/></param>
112112
public CloudServersProvider(CloudIdentity identity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)

src/corelib/Providers/Rackspace/ProviderBase`1.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public abstract class ProviderBase<TProvider>
6262
/// implementation, and the default HTTP response code validator.
6363
/// </summary>
6464
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
65-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
65+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
6666
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
6767
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
6868
protected ProviderBase(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)
@@ -73,7 +73,7 @@ protected ProviderBase(CloudIdentity defaultIdentity, string defaultRegion, IIde
7373
/// using the specified values.
7474
/// </summary>
7575
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
76-
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise all calls must specify an explicit region.</param>
76+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
7777
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
7878
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
7979
/// <param name="httpStatusCodeValidator">The HTTP status code validator to use. If this value is <c>null</c>, the provider will use <see cref="HttpResponseCodeValidator.Default"/>.</param>
@@ -559,7 +559,7 @@ protected virtual RequestSettings BuildDefaultRequestSettings(IEnumerable<HttpSt
559559
/// <exception cref="InvalidOperationException">
560560
/// If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.
561561
/// </exception>
562-
/// <exception cref="NoDefaultRegionSetException">If <paramref name="region"/> is <c>null</c> and no default region is available for the identity or provider.</exception>
562+
/// <exception cref="NoDefaultRegionSetException">If <paramref name="region"/> is <c>null</c>, the service does not provide a region-independent endpoint, and no default region is available for the identity or provider.</exception>
563563
/// <exception cref="UserAuthenticationException">If no service catalog is available for the user.</exception>
564564
/// <exception cref="UserAuthorizationException">If no endpoint is available for the requested service.</exception>
565565
/// <exception cref="ResponseException">If the REST API request failed.</exception>
@@ -593,19 +593,21 @@ protected Endpoint GetServiceEndpoint(CloudIdentity identity, string serviceType
593593
string effectiveRegion = region;
594594
if (string.IsNullOrEmpty(effectiveRegion))
595595
{
596-
if (!string.IsNullOrEmpty(userAccess.User.DefaultRegion))
596+
if (!string.IsNullOrEmpty(DefaultRegion))
597+
effectiveRegion = DefaultRegion;
598+
else if (!string.IsNullOrEmpty(userAccess.User.DefaultRegion))
597599
effectiveRegion = userAccess.User.DefaultRegion;
598-
599-
if (string.IsNullOrEmpty(effectiveRegion))
600-
throw new NoDefaultRegionSetException("No region was provided and there is no default region set for the user's account.");
601600
}
602601

603602
IEnumerable<Tuple<ServiceCatalog, Endpoint>> regionEndpoints =
604-
endpoints.Where(i => string.Equals(i.Item2.Region, effectiveRegion, StringComparison.OrdinalIgnoreCase));
603+
endpoints.Where(i => string.Equals(i.Item2.Region ?? string.Empty, effectiveRegion ?? string.Empty, StringComparison.OrdinalIgnoreCase));
605604

606605
if (regionEndpoints.Any())
607606
endpoints = regionEndpoints;
608607

608+
if (effectiveRegion == null && endpoints.Any())
609+
throw new NoDefaultRegionSetException("No region was provided, the service does not provide a region-independent endpoint, and there is no default region set for the user's account.");
610+
609611
Tuple<ServiceCatalog, Endpoint> serviceEndpoint = endpoints.FirstOrDefault();
610612
if (serviceEndpoint == null)
611613
throw new UserAuthorizationException("The user does not have access to the requested service or region.");

0 commit comments

Comments
 (0)