def set_acl(self, path, version, acl): """sets the acl associated with a node synchronously. PARAMETERS: path: the name of the node. Expressed as a file name with slashes separating ancestors of the node. version: the expected version of the path. acl: the acl to be set on the path. RETURNS: OK operation completed successfully EXCEPTIONS: NONODE the node does not exist. NOAUTH the client does not have permission. INVALIDACL invalid ACL specified BADVERSION expected version does not match actual version. BADARGUMENTS - invalid input parameters INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE MARSHALLINGERROR - failed to marshall a request; possibly, out of memory """ results = [] pc = utils.PipeCondition() ok = zookeeper.aset_acl(self._zhandle, path, version, acl, functools.partial(generic_completion, pc, results)) assert ok == zookeeper.OK pc.wait() # unpack result as void_completion handle, rc = results assert handle == self._zhandle if rc == zookeeper.OK: return rc self._raise_exception(rc)
def set_acl(self, path, acls, version=-1): """ Set the list of acls on a node. Each acl is a dictionary containing keys/values for scheme, id, and perms. The value for id is username:hash_value The hash_value component is the base64 encoded sha1 hash of a username and password that's colon separated. For example >>> import hashlib, base64 >>> digest = base64.b64encode( ... hashlib.new('sha1', 'mary:apples').digest())) >>> id = '%s:%s'%('mary', digest) >>> id 'mary:9MTr9XuZvmudebp9aOo4DtXwyII=' >>> acl = {'id':id, 'scheme':'digest', 'perms':zookeeper.PERM_ALL} @param path: The string path to the node. @param acls: A list of acl dictionaries. @param version: A version id of the node we're modifying, if this doesn't match the version on the server, then a BadVersionException is raised. """ d = defer.Deferred() if self._check_connected(d): return d callback = self._zk_thread_callback(self._cb_set_acl, d, path, acls) result = zookeeper.aset_acl( self.handle, path, version, acls, callback) self._check_result(result, d, path=path) return d
def set_acl(self, path, version, acl): """sets the acl associated with a node synchronously. PARAMETERS: path: the name of the node. Expressed as a file name with slashes separating ancestors of the node. version: the expected version of the path. acl: the acl to be set on the path. RETURNS: OK operation completed successfully EXCEPTIONS: NONODE the node does not exist. NOAUTH the client does not have permission. INVALIDACL invalid ACL specified BADVERSION expected version does not match actual version. BADARGUMENTS - invalid input parameters INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE MARSHALLINGERROR - failed to marshall a request; possibly, out of memory """ results = [] pc = utils.PipeCondition() ok = zookeeper.aset_acl( self._zhandle, path, version, acl, functools.partial(generic_completion, pc, results)) assert ok == zookeeper.OK pc.wait() #unpack result as void_completion handle, rc = results assert handle == self._zhandle if rc == zookeeper.OK: return rc self._raise_exception(rc)
def test_async_acl(self): self.cv = threading.Condition() self.cv = threading.Condition() def aget_callback(handle, rc, acl, stat): self.cv.acquire() self.callback_flag = True self.rc = rc self.acl = acl self.stat = stat self.cv.notify() self.cv.release() def aset_callback(handle, rc): self.cv.acquire() self.callback_flag = True self.rc = rc self.cv.notify() self.cv.release() self.assertEqual(self.connected, True, "Not connected!") ret = zookeeper.create(self.handle, "/zk-python-aacltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) self.cv.acquire() zookeeper.aget_acl(self.handle, "/zk-python-aacltest", aget_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aget_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aget failed") self.assertEqual(self.acl, [ZOO_OPEN_ACL_UNSAFE], "Wrong ACL returned from aget") self.cv.acquire() self.callback_flag = False zookeeper.aset_acl(self.handle, "/zk-python-aacltest", -1, [ZOO_ACL_READ], aset_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aset_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aset failed") acls = zookeeper.get_acl(self.handle, "/zk-python-aacltest") self.assertEqual(acls[1], [ZOO_ACL_READ], "Wrong ACL returned from get when aset")
def aset_acl(self, path, callback, acl, version=-1): return zookeeper.aset_acl(self.handle, path, version, acl, callback)