diff --git a/keystoneclient/v3/client.py b/keystoneclient/v3/client.py index 3117c2a28..f2ea9b59e 100644 --- a/keystoneclient/v3/client.py +++ b/keystoneclient/v3/client.py @@ -19,6 +19,7 @@ from keystoneclient.v2_0 import client from keystoneclient.v3 import endpoints from keystoneclient.v3 import domains from keystoneclient.v3 import policies +from keystoneclient.v3 import roles from keystoneclient.v3 import services @@ -64,6 +65,7 @@ class Client(client.Client): self.endpoints = endpoints.EndpointManager(self) self.domains = domains.DomainManager(self) self.policies = policies.PolicyManager(self) + self.roles = roles.RoleManager(self) self.services = services.ServiceManager(self) # NOTE(gabriel): If we have a pre-defined endpoint then we can diff --git a/keystoneclient/v3/roles.py b/keystoneclient/v3/roles.py new file mode 100644 index 000000000..0e0c180fb --- /dev/null +++ b/keystoneclient/v3/roles.py @@ -0,0 +1,52 @@ +# Copyright 2011 OpenStack LLC. +# Copyright 2011 Nebula, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from keystoneclient import base + + +class Role(base.Resource): + """Represents an Identity role. + + Attributes: + * id: a uuid that identifies the role + * name: user-facing identifier + + """ + pass + + +class RoleManager(base.CrudManager): + """Manager class for manipulating Identity roles.""" + resource_class = Role + collection_key = 'roles' + key = 'role' + + def create(self, name): + return super(RoleManager, self).create( + name=name) + + def get(self, role): + return super(RoleManager, self).get( + role_id=base.getid(role)) + + def update(self, role, name=None): + return super(RoleManager, self).update( + role_id=base.getid(role), + name=name) + + def delete(self, role): + return super(RoleManager, self).delete( + role_id=base.getid(role)) diff --git a/tests/v3/test_roles.py b/tests/v3/test_roles.py new file mode 100644 index 000000000..ef1f7ce39 --- /dev/null +++ b/tests/v3/test_roles.py @@ -0,0 +1,19 @@ +import uuid + +from keystoneclient.v3 import roles +from tests.v3 import utils + + +class RoleTests(utils.TestCase, utils.CrudTests): + def setUp(self): + super(RoleTests, self).setUp() + self.additionalSetUp() + self.key = 'role' + self.collection_key = 'roles' + self.model = roles.Role + self.manager = self.client.roles + + def new_ref(self, **kwargs): + kwargs = super(RoleTests, self).new_ref(**kwargs) + kwargs.setdefault('name', uuid.uuid4().hex) + return kwargs