diff options
| author | Devin Carlen <devin.carlen@gmail.com> | 2010-08-14 21:19:32 +0000 |
|---|---|---|
| committer | Tarmac <> | 2010-08-14 21:19:32 +0000 |
| commit | 39b592cbb3cad456146ffc7178f418db9f19894e (patch) | |
| tree | 5e048259a41e7ad42b2d8b93a14cd75b7c572dce | |
| parent | 8d6a1256aef713138ff706bb7b542dc32598db84 (diff) | |
| parent | cf2002486d651576a28a4c53c6b49bb30c047108 (diff) | |
Implemented admin client / admin api for fetching user roles.
| -rw-r--r-- | nova/adminclient.py | 41 | ||||
| -rw-r--r-- | nova/endpoint/admin.py | 15 |
2 files changed, 55 insertions, 1 deletions
diff --git a/nova/adminclient.py b/nova/adminclient.py index 25d5e71cb..242298a75 100644 --- a/nova/adminclient.py +++ b/nova/adminclient.py @@ -57,6 +57,28 @@ class UserInfo(object): elif name == 'secretkey': self.secretkey = str(value) +class UserRole(object): + """ + Information about a Nova user's role, as parsed through SAX. + Fields include: + role + """ + def __init__(self, connection=None): + self.connection = connection + self.role = None + + def __repr__(self): + return 'UserRole:%s' % self.role + + def startElement(self, name, attrs, connection): + return None + + def endElement(self, name, value, connection): + if name == 'role': + self.role = value + else: + setattr(self, name, str(value)) + class ProjectInfo(object): """ Information about a Nova project, as parsed through SAX @@ -114,7 +136,6 @@ class ProjectMember(object): else: setattr(self, name, str(value)) - class HostInfo(object): """ Information about a Nova Host, as parsed through SAX: @@ -196,6 +217,24 @@ class NovaAdminClient(object): """ deletes a user """ return self.apiconn.get_object('DeregisterUser', {'Name': username}, UserInfo) + def get_roles(self, project_roles=True): + """Returns a list of available roles.""" + return self.apiconn.get_list('DescribeRoles', + {'ProjectRoles': project_roles}, + [('item', UserRole)]) + + def get_user_roles(self, user, project=None): + """Returns a list of roles for the given user. + Omitting project will return any global roles that the user has. + Specifying project will return only project specific roles. + """ + params = {'User':user} + if project: + params['Project'] = project + return self.apiconn.get_list('DescribeUserRoles', + params, + [('item', UserRole)]) + def add_user_role(self, user, role, project=None): """ Add a role to a user either globally or for a specific project. diff --git a/nova/endpoint/admin.py b/nova/endpoint/admin.py index c4b8c05ca..4f4824fca 100644 --- a/nova/endpoint/admin.py +++ b/nova/endpoint/admin.py @@ -103,6 +103,21 @@ class AdminController(object): return True @admin_only + def describe_roles(self, context, project_roles=True, **kwargs): + """Returns a list of allowed roles.""" + roles = manager.AuthManager().get_roles(project_roles) + return { 'roles': [{'role': r} for r in roles]} + + @admin_only + def describe_user_roles(self, context, user, project=None, **kwargs): + """Returns a list of roles for the given user. + Omitting project will return any global roles that the user has. + Specifying project will return only project specific roles. + """ + roles = manager.AuthManager().get_user_roles(user, project=project) + return { 'roles': [{'role': r} for r in roles]} + + @admin_only def modify_user_role(self, context, user, role, project=None, operation='add', **kwargs): """Add or remove a role for a user and project.""" |
