Management Operations

User management

User management is exposed with following methods:

  • CreateUser
  • ChangePermission
  • ChangePassword

Password must have between 8 and 32 letters, digits and special characters of which at least 1 uppercase letter, 1 digit and 1 special character.

Admin permissions are:

  • PermissionSysAdmin = 255
  • PermissionAdmin = 254

Non-admin permissions are:

  • PermissionNone = 0
  • PermissionR = 1
  • PermissionRW = 2
  1. client, err := c.NewImmuClient(c.DefaultOptions())
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. ctx := context.Background()
  6. lr , err := client.Login(ctx, []byte(`immudb`), []byte(`immudb`))
  7. md := metadata.Pairs("authorization", lr.Token)
  8. ctx = metadata.NewOutgoingContext(context.Background(), md)
  9. err = client.CreateUser(ctx, []byte(`myNewUser1`), []byte(`myS3cretPassword!`), auth.PermissionR, "defaultdb")
  10. if err != nil {
  11. log.Fatal(err)
  12. }
  13. err = client.ChangePermission(ctx, schema.PermissionAction_GRANT, "myNewUser1", "defaultDB", auth.PermissionRW)
  14. if err != nil {
  15. log.Fatal(err)
  16. }
  17. err = client.ChangePassword(ctx, []byte(`myNewUser1`), []byte(`myS3cretPassword!`), []byte(`myNewS3cretPassword!`))
  18. if err != nil {
  19. log.Fatal(err)
  20. }
  1. String database = "defaultdb";
  2. String username = "testCreateUser";
  3. String password = "testTest123!";
  4. Permission permission = Permission.PERMISSION_RW;
  5. immuClient.login("immudb", "immudb");
  6. immuClient.useDatabase(database);
  7. try {
  8. immuClient.createUser(username, password, permission, database);
  9. } catch (StatusRuntimeException e) {
  10. System.out.println("createUser exception: " + e.getMessage());
  11. }
  12. // We expect getting back the previously created "testCreateUser" user.
  13. System.out.println("listUsers:");
  14. List<User> users = immuClient.listUsers();
  15. users.forEach(user -> System.out.println("\t- " + user));
  16. // Changing the user password.
  17. immuClient.changePassword(username, password, "newTestTest123!");

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectManagement Operations - 图1 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. import { USER_ACTION, USER_PERMISSION } from 'immudb-node/dist/types/user'
  4. const IMMUDB_HOST = '127.0.0.1'
  5. const IMMUDB_PORT = '3322'
  6. const IMMUDB_USER = 'immudb'
  7. const IMMUDB_PWD = 'immudb'
  8. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  9. (async () => {
  10. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  11. const createUserRequest: Parameters.CreateUser = {
  12. user: 'myNewUser1',
  13. password: 'myS3cretPassword!',
  14. permission: USER_PERMISSION.READ_ONLY,
  15. database: 'defaultdb',
  16. };
  17. const createUserRes = cl.createUser(createUserRequest)
  18. console.log('success: createUser', createUserRes)
  19. const changePermissionReq: Parameters.ChangePermission = {
  20. action: USER_ACTION.GRANT,
  21. username: 'myNewUser1',
  22. database: 'defaultDB',
  23. permission: USER_PERMISSION.READ_WRITE
  24. }
  25. const changePermissionRes = await cl.changePermission(changePermissionReq)
  26. console.log('success: changePermission', changePermissionRes)
  27. const changePasswordReq: Parameters.ChangePassword = {
  28. user: 'myNewUser1',
  29. oldpassword: 'myS3cretPassword!',
  30. newpassword: 'myNewS3cretPassword!'
  31. }
  32. const changePasswordRes = await cl.changePassword(changePasswordReq)
  33. console.log('success: changePassword', changePermissionRes)
  34. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectManagement Operations - 图2 (opens new window)

If you’re using another development language, please read up on our immugwManagement Operations - 图3 (opens new window) option.

Multiple databases

Starting with version 0.7.0 of immudb, we introduced multi-database support. By default, the first database is either called defaultdb or based on the environment variable IMMUDB_DBNAME. Handling users and databases requires the appropriate privileges. Users with PermissionAdmin can control everything. Non-admin users have restricted permissions and can read or write only their databases, assuming sufficient privileges.

Each database has default MaxValueLen and MaxKeyLen values. These are fixed respectively to 1MB and 1KB. These values at the moment are not exposed to client SDK and can be modified using internal store options.

This example shows how to create a new database and how to write records to it. To create a new database, use CreateDatabase method. To write into a specific database an authenticated context is required. Start by calling the UseDatabase method to obtain a token. A token is used for both authorization and routing commands to a specific database. To set up an authenticated context, it’s sufficient to put a token inside metadata.

  1. client, err := c.NewImmuClient(c.DefaultOptions())
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. ctx := context.Background()
  6. lr , err := client.Login(ctx, []byte(`immudb`), []byte(`immudb`))
  7. md := metadata.Pairs("authorization", lr.Token)
  8. ctx = metadata.NewOutgoingContext(context.Background(), md)
  9. err = client.CreateDatabase(ctx, &schema.Database{
  10. Databasename: "myimmutabledb",
  11. })
  12. if err != nil {
  13. log.Fatal(err)
  14. }
  15. dbList, err := client.DatabaseList(ctx)
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. fmt.Printf("database list: %v", dbList)
  20. // creating a context to write in the new database
  21. resp, err := client.UseDatabase(ctx, &schema.Database{
  22. Databasename: "myimmutabledb",
  23. })
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. fmt.Printf("auth token: %v", resp.Token)
  28. md = metadata.Pairs("authorization", resp.Token)
  29. ctx = metadata.NewOutgoingContext(context.Background(), md)
  30. // writing in myimmutabledb
  31. _, err = client.Set(ctx, []byte(`key`), []byte(`val`))
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  1. immuClient.createDatabase("db1");
  2. immuClient.createDatabase("db2");
  3. immuClient.useDatabase("db1");
  4. try {
  5. immuClient.set("k0", new byte[]{0, 1, 2, 3});
  6. } catch (CorruptedDataException e) {
  7. // ...
  8. }
  9. List<String> dbs = immuClient.databases();
  10. // We should have three entries: "defaultdb", "db1", and "db2".

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectManagement Operations - 图4 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  10. const createDatabaseReq: Parameters.CreateDatabase = {
  11. databasename: 'myimmutabledb'
  12. }
  13. const createDatabaseRes = await cl.createDatabase(createDatabaseReq)
  14. console.log('success: createDatabase', createDatabaseRes)
  15. const useDatabaseReq: Parameters.UseDatabase = {
  16. databasename: 'myimmutabledb'
  17. }
  18. const useDatabaseRes = await cl.useDatabase(useDatabaseReq)
  19. console.log('success: useDatabase', useDatabaseRes)
  20. await cl.set('key', 'val')
  21. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectManagement Operations - 图5 (opens new window)

If you’re using another development language, please read up on our immugwManagement Operations - 图6 (opens new window) option.

Index Cleaning

It’s important to keep disk usage under control. CleanIndex it’s a temporary solution to launch an internal clean routine that could free disk space.

immudb uses a btree to index key-value entries. While the key is the same submitted by the client, the value stored in the btree is an offset to the file where the actual value as stored, its size and hash value. The btree is keep in memory as new data is inserted, getting a key or even the historical values of a key can directly be made by using a mutex lock on the btree but scanning by prefix requires the tree to be stored into disk, this is referred as a snapshot. The persistence is implemented in append-only mode, thus whenever a snapshot is created (btree flushed to disk), updated and new nodes are appended to the file, while new or updated nodes may be linked to unmodified nodes (already written into disk) and those unmodified nodes are not rewritten. The snapshot creation does not necessarily take place upon each scan by prefix, it’s possible to reuse an already created one, client can provide his requirements on how new the snapshot should be by providing a transaction ID which at least must be indexed (sinceTx). After some time, several snapshots may be created (specified by flushAfter properties of the btree and the scan requests), the file backing the btree will hold several old snapshots. Thus the clean index process will dump to a different location only the latest snapshot but in this case also writing the unmodified nodes. Once that dump is done, the index folder is replaced by the new one. While the clean process is made, no data is indexed and there will be an extra disk space requirement due to the new dump. Once completed, a considerable disk space will be reduced by removing the previously indexed data (older snapshots). The btree and clean up process is something specific to indexing. And will not lock transaction processing as indexing is asynchronously generated.

  1. client.CleanIndex(ctx, &emptypb.Empty{})
  1. immuClient.cleanIndex();

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectManagement Operations - 图7 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github projectManagement Operations - 图8 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectManagement Operations - 图9 (opens new window)

If you’re using another development language, please read up on our immugwManagement Operations - 图10 (opens new window) option.

HealthCheck

HealthCheck return an error if immudb status is not ok.

  1. err = client.HealthCheck(ctx)
  1. boolean isHealthy = immuClient.healthCheck();

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectManagement Operations - 图11 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. const IMMUDB_HOST = '127.0.0.1'
  3. const IMMUDB_PORT = '3322'
  4. const IMMUDB_USER = 'immudb'
  5. const IMMUDB_PWD = 'immudb'
  6. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  7. (async () => {
  8. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  9. await cl.health()
  10. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectManagement Operations - 图12 (opens new window)

If you’re using another development language, please read up on our immugwManagement Operations - 图13 (opens new window) option.