Skip to content

Commit a46d36f

Browse files
author
Alan Quillin
committed
Added support for Get All Users for a Role. Updated Assembly to v1.1.3.3
1 parent 90a04ef commit a46d36f

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/corelib/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.3.2")]
36-
[assembly: AssemblyFileVersion("1.1.3.2")]
35+
[assembly: AssemblyVersion("1.1.3.3")]
36+
[assembly: AssemblyFileVersion("1.1.3.3")]
3737

3838
[assembly: InternalsVisibleTo("OpenStackNet.Testing.Integration")]
3939
[assembly: InternalsVisibleTo("OpenStackNet.Testing.Unit")]

src/corelib/Providers/Rackspace/CloudIdentityProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public IEnumerable<Role> ListRoles(string serviceId = null, string markerId = nu
6060
return provider.ListRoles(serviceId, markerId, limit, identity);
6161
}
6262

63+
/// <inheritdoc/>
64+
public IEnumerable<User> ListUsersByRole(string roleId, bool? enabled = null, int? marker = null, int? limit = null, CloudIdentity identity = null)
65+
{
66+
var provider = GetProvider(identity);
67+
return provider.ListUsersByRole(roleId, enabled, marker, limit, identity);
68+
}
69+
6370
public Role AddRole(string name, string descritpion, CloudIdentity identity)
6471
{
6572
var provider = GetProvider(identity);

src/corelib/Providers/Rackspace/GeographicalCloudIdentityProvider.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ public bool DeleteRoleFromUser(string userId, string roleId, CloudIdentity ident
107107
return false;
108108
}
109109

110+
/// <inheritdoc/>
111+
public IEnumerable<User> ListUsersByRole(string roleId, bool? enabled = null, int? markerId = null, int? limit = null, CloudIdentity identity = null)
112+
{
113+
if (limit < 0 || limit > 1000)
114+
throw new ArgumentOutOfRangeException("limit");
115+
116+
var parameters = BuildOptionalParameterList(new Dictionary<string, string>
117+
{
118+
{"enabled", !enabled.HasValue ? null : enabled.Value ? "true" : "false"},
119+
{"marker", !markerId.HasValue ? null : markerId.Value.ToString()},
120+
{"limit", !limit.HasValue ? null : limit.Value.ToString()},
121+
});
122+
123+
var urlPath = string.Format("/v2.0/OS-KSADM/roles/{0}/RAX-AUTH/users", roleId);
124+
var response = ExecuteRESTRequest<UsersResponse>(identity, urlPath, HttpMethod.GET, queryStringParameter: parameters);
125+
126+
if (response == null || response.Data == null)
127+
return null;
128+
// Due to the fact the sometimes the API returns a JSON array of users and sometimes it returns a single JSON user object.
129+
// Therefore if we get a null data object (which indicates that the deserializer could not parse to an array) we need to try and parse as a single User object.
130+
if (response.Data.Users == null)
131+
{
132+
var userResponse = JsonConvert.DeserializeObject<UserResponse>(response.RawBody);
133+
134+
if (response == null || response.Data == null)
135+
return null;
136+
137+
return new[] { userResponse.User };
138+
}
139+
140+
return response.Data.Users;
141+
}
142+
110143
#endregion
111144

112145
#region Credentials

src/corelib/Providers/Rackspace/IExtendedCloudIdentityProvider.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Collections.Generic;
2-
using net.openstack.Core;
1+
using System;
2+
using System.Collections.Generic;
33
using net.openstack.Core.Domain;
4+
using net.openstack.Core.Exceptions.Response;
45
using net.openstack.Core.Providers;
56

67
namespace net.openstack.Providers.Rackspace
@@ -17,6 +18,21 @@ public interface IExtendedCloudIdentityProvider : IIdentityProvider
1718
/// <returns>List of <see cref="Role"/></returns>
1819
IEnumerable<Role> ListRoles(string serviceId = null, string markerId = null, int? limit = null, CloudIdentity identity = null);
1920

21+
/// <summary>
22+
/// Lists all users by role.
23+
/// </summary>
24+
/// <param name="roleId">The role ID. The behavior is unspecified if this is not obtained from <see cref="Role.Id"/>.</param>
25+
/// <param name="enabled">Allows you to filter enabled or un-enabled users. If the value is <c>null</c>, a provider-specific default value is used.</param>
26+
/// <param name="marker">The index of the last item in the previous list. Used for pagination. If the value is <c>null</c>, the list starts at the beginning.</param>
27+
/// <param name="limit">Indicates the maximum number of items to return. Used for pagination. If the value is <c>null</c>, a provider-specific default value is used.</param>
28+
/// <param name="identity">The cloud identity to use for this request. If not specified, the default identity for the current provider instance will be used.</param>
29+
/// <returns>A collection of <see cref="Role"/> objects describing the requested roles.</returns>
30+
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than 0 or greater than 1000.</exception>
31+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
32+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.</exception>
33+
/// <exception cref="ResponseException">If the REST API request failed.</exception>
34+
IEnumerable<User> ListUsersByRole(string roleId, bool? enabled = null, int? marker = null, int? limit = null, CloudIdentity identity = null);
35+
2036
/// <summary>
2137
/// Create a new role.
2238
/// </summary>

0 commit comments

Comments
 (0)