如何通过curl命令访问Manager REST API
说明
用户可通过openssl version查看系统的openssl版本,如果版本低于OpenSSL 1.0.1,需要为操作系统安装较高版本的openssl,以支持使用TLSv1.1和TLSv1.2与集群交互。
操作样例及步骤
- 发送GET方法访问查询用户列表接口并保存“jsessionid”到“jessionid.txt”文件中:
curl -k -i --basic -u <user name>:<password> -c /tmp/jsessionid.txt 'https://x.x.x.x:28443/web/api/v2/permission/users?limit=10&offset=0&filter=&order=ASC&order_by=userName'
- 利用“jsessionid”访问用户组接口,实现对用户组的增、改、删操作:
- 发送POST方法,增加用户。
curl -k -i -b /tmp/jsessionid.txt -X POST -HContent-type:application/json -d '{"userName":"user888","userType":"HM","password":"xxx","confirmPassword":"xxxx","userGroups":["supergroup"],"userRoles":[],"primaryGroup":"supergroup","description":"Add user"}' 'https://x.x.x.x:28443/web/api/v2/permission/users'
- 发送PUT方法,修改用户信息。
curl -k -i -b /tmp/jsessionid.txt -X PUT -HContent-type:application/json -d '{"userName":"user888","userType":"HM","password":"","confirmPassword":"","userGroups":["supergroup","hadoopmanager"],"primaryGroup":"supergroup","userRoles":[],"description":"Modify user"}' 'https://x.x.x.x:28443/web/api/v2/permission/users/user888'
- 发送DELETE方法,删除用户。
curl -k -i -b /tmp/jsessionid.txt -X DELETE -HContent-type:application/json -d '{"userNames":["user888"]}' 'https://x.x.x.x:28443/web/api/v2/permission/users
- 发送POST方法,增加用户。