def add_user(server, options, groupname, username): """ curl -u admin:admin -FaddMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html """ group_path = get_group_path(groupname) path = "{}.rw.html".format(group_path) url = server.url(path) props = {'addMembers': username} resp = requests.post(url, auth=server.auth, data=props) if resp.status_code != 200: error("Failed to add user: {}".format(resp.content)) return SERVER_ERROR if options.raw: sys.stdout.write("{}\n".format(resp.content)) else: path = html.parse_value(resp.text, 'div', 'Path') sys.stdout.write("{}\n".format(path)) return OK
def create_user(server, options, username): """ curl -u admin:admin -FcreateUser= -FauthorizableId=testuser -Frep:password=abc123 http://localhost:4502/libs/granite/security/post/authorizables """ assert len(username) > 0 form_data = { 'createUser': '', 'authorizableId': username, 'rep:password': options.password } url = server.url('/libs/granite/security/post/authorizables') resp = requests.post(url, auth=server.auth, data=form_data) if resp.status_code != 201: error("Failed to create user: {}".format(resp.content)) return SERVER_ERROR if options.raw: sys.stdout.write("{}\n".format(resp.content)) else: path = html.parse_value(resp.text, 'div', 'Path') sys.stdout.write("{}\n".format(path)) return OK
def create_group(server, options, name): """ curl -u admin:admin -FcreateGroup=group1 -FauthorizableId=testGroup1 http://localhost:4502/libs/granite/security/post/authorizables """ assert len(name) > 0 form_data = { 'createGroup': '', 'authorizableId': name } url = server.url('/libs/granite/security/post/authorizables') resp = requests.post(url, auth=server.auth, data=form_data) if resp.status_code != 201: error("Failed to create group: {}".format(resp.content)) return SERVER_ERROR if options.raw: sys.stdout.write("{}\n".format(resp.content)) else: path = html.parse_value(resp.text, 'div', 'Path') sys.stdout.write("{}\n".format(path)) return OK