def get_user(self, name): """ Finds the user in this instance with the specified name, and returns a CloudDatabaseUser object. If no match is found, a NoSuchDatabaseUser exception is raised. """ try: return self._user_manager.get(name) except exc.NotFound: raise exc.NoSuchDatabaseUser("No user by the name '%s' exists." % name)
def get_user(self, name): """ Finds the user in this instance with the specified name, and returns a CloudDatabaseUser object. If no match is found, a NoSuchDatabaseUser exception is raised. """ try: return [user for user in self.list_users() if user.name == name][0] except IndexError: raise exc.NoSuchDatabaseUser("No user by the name '%s' exists." % name)
def list_user_access(self, user): """ Returns a list of all database names for which the specified user has access rights. """ user = utils.get_name(user) uri = "/%s/%s/databases" % (self.uri_base, user) try: resp, resp_body = self.api.method_get(uri) except exc.NotFound as e: raise exc.NoSuchDatabaseUser("User '%s' does not exist." % user) dbs = resp_body.get("databases", {}) return [CloudDatabaseDatabase(self, db) for db in dbs]
def grant_user_access(self, user, db_names, strict=True): """ Gives access to the databases listed in `db_names` to the user. You may pass in either a single db or a list of dbs. If any of the databases do not exist, a NoSuchDatabase exception will be raised, unless you specify `strict=False` in the call. """ user = utils.get_name(user) uri = "/%s/%s/databases" % (self.uri_base, user) db_names = self._get_db_names(db_names, strict=strict) dbs = [{"name": db_name} for db_name in db_names] body = {"databases": dbs} try: resp, resp_body = self.api.method_put(uri, body=body) except exc.NotFound as e: raise exc.NoSuchDatabaseUser("User '%s' does not exist." % user)
def test_get_user_fail(self): inst = self.instance bad_name = utils.random_name() inst._user_manager.get = Mock(side_effect=exc.NoSuchDatabaseUser()) self.assertRaises(exc.NoSuchDatabaseUser, inst.get_user, bad_name)