Example 6: Creating a User and a User Group
Scenario
This section describes how to create a VPN user and a user group by calling APIs.
Prerequisites
- You have created a P2C VPN gateway.
- You have created a VPN server and set the authentication mode of the server to password authentication. For details, see Creating a Server.
- You have determined the endpoint for calling APIs.
- You have obtained a user token if you need to use token authentication. In addition, you need to add X-Auth-Token to the request header when calling an API. For details about token authentication, see Authentication.
The token obtained through IAM is valid for only 24 hours. When using a token for authentication, cache it to avoid frequent calling.
Calling the APIs related to users and user groups is an asynchronous process. The configuration takes effect after a period of time. If you frequently perform operations on users or user groups within a short period of time, the queue may be congested due to limited performance, and the error message "VPN.0030, The system is busy, please try later." is returned. In this case, you need to wait for a while before calling the APIs again.
Data Preparation
Parameter |
Description |
Example Value |
---|---|---|
vpn_server_id |
Specifies the ID of a VPN server. |
0e325fb6-83b9-4004-a343-8b6fc714a5d9 |
Parameter |
Description |
Example Value |
---|---|---|
vpn_server_id |
Specifies the ID of a VPN server. |
0e325fb6-83b9-4004-a343-8b6fc714a5d9 |
Procedure
- Create a user group.
- Send POST https://{endpoint}/v5/{project_id}/p2c-vpn-gateways/vpn-servers/{vpn_server_id}/groups. {vpn_server_id} specifies the ID of the created VPN server.
- Add X-Auth-Token to the request header.
- Specify the following parameters in the request body:
{ "user_group": { "name": "user-group1", "description": "UserGroup1" } }
- Check the response.
- The request is successful if the following response is displayed. In the response, id specifies the ID of the created user group.
{ "user_group": { "id": "7625fd92-2e20-4e4d-8c56-66f110fbfaa8" }, "request_id": "94d271493e144135423e7377e40127cf" }
- The request is successful if the following response is displayed. In the response, id specifies the ID of the created user group.
- Query the user group.
- Send GET https://{endpoint}/v5/{project_id}/p2c-vpn-gateways/vpn-servers/{vpn_server_id}/groups/{group_id}. {group_id} specifies the ID of the created user group.
- Add X-Auth-Token to the request header.
- Check the response.
{ "user_group": { "id": "7625fd92-2e20-4e4d-8c56-66f110fbfaa8", "name": "user-group1", "description": "UserGroup1", "type": "Custom", "user_number": 0, "created_at": "2024-06-17T09:48:27.548Z", "updated_at": "2024-06-17T09:48:27.548Z" }, "request_id": "6735d32bb3e35e9154caba1dbc6c2dc6" }
- Create a user.
- Send POST https://{endpoint}/v5/{project_id}/p2c-vpn-gateways/vpn-servers/{vpn_server_id}/users. {vpn_server_id} specifies the ID of the created VPN server.
- Add X-Auth-Token to the request header.
- Specify the following parameters in the request body:
{ "user": { "name": "user001", "password": "Qwerasdf", "description": "User1", "user_group_id": "7625fd92-2e20-4e4d-8c56-66f110fbfaa8" } }
- Check the response.
- The request is successful if the following response is displayed. In the response, id specifies the ID of the created user.
{ "user": { "id": "41ad472e-d3e4-482b-8f00-7b2c1bfc4b7d" }, "request_id": "b19ba5a0be8f7b7f664b14596f8f35db" }
- The request is successful if the following response is displayed. In the response, id specifies the ID of the created user.
- Query the user.
- Send GET https://{endpoint}/v5/{project_id}/p2c-vpn-gateways/vpn-servers/{vpn_server_id}/users/{user_id}. {vpn_server_id} specifies the ID of the created VPN server. {user_id} specifies the ID of the created user.
- Add X-Auth-Token to the request header.
- Check the response.
{ "user": { "id": "41ad472e-d3e4-482b-8f00-7b2c1bfc4b7d", "name": "user001", "description": "User1", "user_group_id": "7625fd92-2e20-4e4d-8c56-66f110fbfaa8", "user_group_name": "user-group1", "created_at": "2024-06-17T06:53:46.302Z", "updated_at": "2024-06-17T06:53:46.302Z" }, "request_id": "926a0edb3bf432943e2399b700173add" }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot