v3 User CRUD

Change-Id: Ieea3c474ce3795e2c97e399988228cdb2715f2ef
This commit is contained in:
Dolph Mathews
2012-09-11 15:40:37 -05:00
committed by Gerrit Code Review
parent 577c78c991
commit 298b1c4903
3 changed files with 95 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ from keystoneclient.v3 import policies
from keystoneclient.v3 import projects
from keystoneclient.v3 import roles
from keystoneclient.v3 import services
from keystoneclient.v3 import users
_logger = logging.getLogger(__name__)
@@ -69,6 +70,7 @@ class Client(client.Client):
self.projects = projects.ProjectManager(self)
self.roles = roles.RoleManager(self)
self.services = services.ServiceManager(self)
self.users = users.UserManager(self)
# NOTE(gabriel): If we have a pre-defined endpoint then we can
# get away with lazy auth. Otherwise auth immediately.

View File

@@ -0,0 +1,70 @@
# 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 User(base.Resource):
"""Represents an Identity user.
Attributes:
* id: a uuid that identifies the user
"""
pass
class UserManager(base.CrudManager):
"""Manager class for manipulating Identity users."""
resource_class = User
collection_key = 'users'
key = 'user'
def create(self, name, domain=None, project=None, password=None,
email=None, description=None, enabled=True):
return super(UserManager, self).create(
name=name,
domain_id=base.getid(domain),
project_id=base.getid(project),
password=password,
email=email,
description=description,
enabled=enabled)
def list(self, project=None, domain=None):
return super(UserManager, self).list(
domain_id=base.getid(domain),
project_id=base.getid(project))
def get(self, user):
return super(UserManager, self).get(
user_id=base.getid(user))
def update(self, user, name=None, domain=None, project=None, password=None,
email=None, description=None, enabled=None):
return super(UserManager, self).update(
user_id=base.getid(user),
name=name,
domain_id=base.getid(domain),
project_id=base.getid(project),
password=password,
email=email,
description=description,
enabled=enabled)
def delete(self, user):
return super(UserManager, self).delete(
user_id=base.getid(user))

23
tests/v3/test_users.py Normal file
View File

@@ -0,0 +1,23 @@
import uuid
from keystoneclient.v3 import users
from tests.v3 import utils
class UserTests(utils.TestCase, utils.CrudTests):
def setUp(self):
super(UserTests, self).setUp()
self.additionalSetUp()
self.key = 'user'
self.collection_key = 'users'
self.model = users.User
self.manager = self.client.users
def new_ref(self, **kwargs):
kwargs = super(UserTests, self).new_ref(**kwargs)
kwargs.setdefault('description', uuid.uuid4().hex)
kwargs.setdefault('domain_id', uuid.uuid4().hex)
kwargs.setdefault('enabled', True)
kwargs.setdefault('name', uuid.uuid4().hex)
kwargs.setdefault('project_id', uuid.uuid4().hex)
return kwargs