Create a database user

2023-08-22 02:46:05  Updated

Description

You can call this operation to create database users.

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}/users

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
username String Yes user1 The username.
password String Yes ****** The password.
saveToCredential Boolean No true Specifies whether to save the user password in the password box of the current OCP user.
globalPrivileges ArrayString No [SELECT, CREATE] The list of global privileges to be granted. * For MySQL tenants, it is a list of global privileges. * For Oracle tenants, it is a list of system privileges.
dbPrivileges Array No The list of database privileges to be granted. Note This parameter is available only in MySQL tenants.
├─ dbName String Yes db1 The name of the database.
├─ privileges StringArray Yes [ALTER, INDEX] The list of database privileges.
roles StringArray No [R1, R2] The list of roles to be granted. Note This parameter is available only in Oracle tenants.

Response parameters

Parameter Type Description
data Object The database user. For more information about the data structure, 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 database user information

Parameter Type Description
username String The username.
globalPrivileges StringArray The list of global privileges. * For MySQL tenants, it is a list of global privileges. * For Oracle tenants, it is a list of system privileges.
dbPrivileges Array The list of database privileges. This parameter is not available in Oracle tenants.
├─ dbName String The name of the database.
├─ privileges StringArray The list of database privileges.
objectPrivileges Array The list of object privileges. This parameter is not available in MySQL tenants.
├─ dbObject Object The database object.
├─├─ 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.
├─ privileges StringArray The list of object privileges.
grantedRoles String The roles granted to the user. Note This parameter is available only in Oracle tenants.
isLocked Bool Indicates whether the user has been locked.
createTime Datetime The time when the user account was created.
connectionStrings Array The list of OBProxies and connection strings.
├─ connectionStringType String The type of the connection string. Valid values: * OBPROXY * DIRECT
├─ obProxyAddress String The IP address of the OBProxy. Note This parameter is valid only when the connection string type is OBProxy.
├─ obProxyPort Integer The port number of the OBProxy. Note This parameter is valid only when the connection string type is OBProxy.
├─ connectionString String The connection string.
accessibleDatabases StringArray The accessible database. Note This parameter is available only in MySQL tenants.

Examples

Sample request

Create user1 in Tenant 1000001 of Cluster 1.

POST /api/v2/ob/clusters/1/tenants/1000001/users?id=1&tenantId=1000001

{
  "username": "user1",
  "password": "******",
  "globalPrivileges": [
    "DELETE",
    "SELECT",
    "INDEX"
  ],
  "dbPrivileges": [
    {
      "dbName": "db1",
      "privileges": [
        "ALTER",
        "CREATE",
        "SELECT"
      ]
    }
  ]
}

Sample response

{
  "data": {
    "createTime": "2021-09-07T15:21:52.664003+08:00",
    "dbPrivileges": [
      {
        "dbName": "db1",
        "privileges": [
          "SELECT",
          "CREATE",
          "ALTER"
        ]
      }
    ],
    "globalPrivileges": [
      "DELETE",
      "SELECT",
      "INDEX"
    ],
    "isLocked": false,
    "username": "user1"
  },
  "duration": 413,
  "server": "xxx.xxx.xxx.xxx",
  "status": 200,
  "successful": true,
  "timestamp": "2021-09-07T15:21:52.838+08:00",
  "traceId": "9f90d133858c41e4"
}

Contact Us