Description
You can call this operation to create a database role.
Call description
Prerequisites
You have passed the authentication for the OCP application service.
You have the Update permission on the specified tenant.
Request path
POST /api/v2/ob/clusters/{id}/tenants/{tenantId}/roles
Request parameters
path parameters
| Parameter | Type | Required | Example value | Description |
|---|---|---|---|---|
| id | Integer | Yes | 1 | The ID of the cluster. |
| tenantId | Integer | Yes | 5 | The ID of the tenant. |
Request body parameters
| Parameter | Type | Required | Example value | Description |
|---|---|---|---|---|
| roleName | String | Yes | ROLE1 | The role name. |
| globalPrivileges | ArrayString | No | [SELECT, CREATE] | The list of system privileges to be granted. |
| roles | StringArray | No | [R1, R2] | The list of roles to be granted. |
Response parameters
| Parameter | Type | Description |
|---|---|---|
| data | Object | The database role. For more information about the data structure of a database role, see the following table. |
| successful | Boolean | Indicates whether the request was successful. |
| timestamp | Datetime | The timestamp when the server completed the request. |
| duration | Integer | The time taken by the server to process the request, in milliseconds. |
| status | Integer | An HTTP status code. |
| traceId | String | The trace ID of the request. This trace ID is used for troubleshooting. |
| server | String | The address of the application server that responded to the request. |
Data structure of a database role
| Parameter | Type | Description |
|---|---|---|
| name | String | The role name. |
| createTime | Datetime | The time when the user account was created. |
| updateTime | Datetime | The update time of the role. |
| globalPrivileges | StringArray | The list of system privileges. |
| objectPrivileges | Array | The list of object privileges. |
| ├─ dbObject | Object | The database object. For more information, see dbObject parameters. |
| ├─ privileges | StringArray | The list of object privileges. |
| grantedRoles | StringArray | The roles granted to the role. |
| userGrantees | StringArray | The users to whom the role is granted. |
| roleGrantees | StringArray | The roles to which the role is granted. |
dbObject parameters
| Parameter | Type | Description |
|---|---|---|
| objectType | String | The type of the database object. Valid values: * TABLE * VIEW * STORED_PROCEDURE |
| objectName | String | The name of the database object, namely, the name of the table, view, or stored procedure. |
| schemaName | String | The schema name, which is generally the same as the username. |
Examples
Sample request
Create ROLE1 in Tenant 1000001 of Cluster 1.
POST /api/v2/ob/clusters/1/tenants/2000001/roles?id=1&tenantId=2000001
{
"roleName": "ROLE1",
"globalPrivileges": [
"CREATE_TABLE",
"CREATE_ANY_TABLE",
"ALTER_ANY_TABLE"
],
"roles": [
"PUBLIC",
"CONNECT"
]
}
Sample response
{
"data": {
"createTime": "2021-09-07T15:51:28.385543+08:00",
"globalPrivileges": [
"CREATE_TABLE",
"CREATE_ANY_TABLE",
"ALTER_ANY_TABLE"
],
"grantedRoles": [
"CONNECT",
"PUBLIC"
],
"name": "ROLE1",
"objectPrivileges": [],
"roleGrantees": [],
"updateTime": "2021-09-07T15:51:28.709504+08:00",
"userGrantees": [
"SYS"
]
},
"duration": 691,
"server": "a83ad33525",
"status": 200,
"successful": true,
"timestamp": "2021-09-07T15:51:28.748+08:00",
"traceId": "e78b9c9cb9a5419f"
}