def cluster_znode_acls(cluster_name, znode, headers=None): """get or update the acls of a znode in a specific cluster ``GET`` http://[host]:[port]/wildlife/[cluster_name]/[znode]/acls e.g. http://localhost:5000/wildlife/cluster01/znode1/znode2/znode3/acls ``Headers`` (optional, if the znode you are accessing needs an acl): { "scheme": "digest", "credential": "user1,password1" } ``Response`` (string): [ACL(perms=31, acl_list=['ALL'], id=Id(scheme=u'world', id=u'anyone'))] ``PUT`` http://[host]:[port]/wildlife/[cluster_name]/[znode]/acls ``Content-Type``: "text/plain" or "text/xml" ``Headers`` (optional, if the znode you are accessing needs an acl): { "scheme": "digest", "credential": "user1,password1" } ``DATA``: [ {"scheme": "digest", "credential": "user1,password1", "read": True, "write": False, "create": False, "delete": False, "admin": False, "all": False }, {"scheme": "digest", "credential": "user2,password2", "all": True } ] Parameters Explanations: scheme: The scheme to use. I.e. digest. credential: A colon separated username, password. The password should be hashed with the scheme specified. write (bool): Write permission. create (bool): Create permission. delete (bool): Delete permission. admin (bool): Admin permission. all (bool): All permissions. ``Response`` (string): [created_znode_path_list] """ _zclient = get_client(cluster_name, headers or request.headers) if request.method == "GET": acls = _zclient.get_acls(znode)[0] return make_response(str(acls), 200) if request.method == "PUT": if request.content_type not in ["text/plain", "text/xml"]: return make_response("The Content-Type is not supported. " "Please use text/plain or text/xml. \n", 406) else: acls_raw = eval(request.data) acls_list = list() for _acl_raw in acls_raw: _acl_config = wildutils.ACLConfig(_acl_raw) acls_list.append(_acl_config.make_acl()) zstat = _zclient.set_acls(znode, acls_list) data = {"znodeStat": wildutils.convert_zstat(zstat)} resp = Response(json.dumps(data), status=201, mimetype="application/json") return resp
def cluster_znode(cluster_name, znode, headers=None): """get the znode data including the znodeStat, update the znode data and delete the znode ``GET`` http://[host]:[port]/wildlife/[cluster_name]/[znode] e.g. http://localhost:5000/wildlife/cluster01/znode1/znode2/znode3 ``Headers`` (optional, if the znode you are accessing needs an acl): { "scheme": "digest", "credential": "user1,password1" } ``Response`` (json data): { "znodeStat": { "ephemeralOwner": 0, "dataLength": 19, "mtime": 1448608198011, "czxid": 8589936224, "pzxid": 8589936224, "ctime": 1448608198011, "mzxid": 8589936224, "numChildren": 0, "version": 0, "aversion": 0, "cversion": 0 }, "data": "data for this znode" } ``PUT`` http://[host]:[port]/wildlife/[cluster_name]/[znode] ``Content-Type``: "text/plain;charset=UTF-8", "application/json", "text/xml" or "multipart/form-data" ``Headers`` (optional, if the znode you are accessing needs an acl): { "scheme": "digest", "credential": "user1,password1" } ``DATA`` ``Response`` (json data): { "znodeStat": { "ephemeralOwner": 0, "dataLength": 27, "mtime": 1449033225435, "czxid": 8589936438, "pzxid": 8589936439, "ctime": 1449033225435, "mzxid": 8589936438, "numChildren": 0, "version": 0, "aversion": 0, "cversion": 1 }, "data": "updated data for this znode" } ``DELETE`` http://[host]:[port]/wildlife/[cluster_name]/[znode] ``Headers`` (optional, if the znode you are accessing needs an acl): { "scheme": "digest", "credential": "user1,password1" } ``Response`` (string): Successfully Delete Znode [znode] from Cluster [cluster_name]. """ _zclient = get_client(cluster_name, headers or request.headers) if request.method == "GET": zdata = _zclient.get(znode) data = {"data": zdata[0], "znodeStat": wildutils.convert_zstat(zdata[1])} resp = Response(json.dumps(data), status=200, mimetype="application/json") return resp elif request.method == "PUT": _new_data = request_data(request) zdata = _zclient.set(znode, _new_data) data = {"data": _new_data, "znodeStat": wildutils.convert_zstat(zdata)} resp = Response(json.dumps(data), status=201, mimetype="application/json") return resp elif request.method == "DELETE": _zclient.delete(znode, recursive=False) return make_response("Successfully Delete Znode [%s] from " "Cluster [%s].\n" % (znode, cluster_name), 202)