|
| 1 | +.. _box_session-su: |
1 | 2 |
|
2 | | -.. _box_session-su: |
3 | | - |
4 | | -================================================================================ |
5 | 3 | box.session.su() |
6 | | -================================================================================ |
| 4 | +================ |
7 | 5 |
|
8 | | -.. module:: box.session |
| 6 | +.. module:: box.session |
9 | 7 |
|
10 | | -.. function:: su(user-name [, function-to-execute]) |
| 8 | +.. function:: su(user-name [, function-to-execute]) |
11 | 9 |
|
12 | 10 | Change Tarantool's :ref:`current user <authentication-users>` -- |
13 | 11 | this is analogous to the Unix command ``su``. |
14 | 12 |
|
15 | | - Or, if function-to-execute is specified, |
16 | | - change Tarantool's :ref:`current user <authentication-users>` |
17 | | - temporarily while executing the function -- |
| 13 | + Or, if the ``function-to-execute`` option is specified, |
| 14 | + change Tarantool's current user temporarily while executing the function -- |
18 | 15 | this is analogous to the Unix command ``sudo``. |
| 16 | + If the user is changed temporarily: |
| 17 | + |
| 18 | + - :ref:`box.session.user() <box_session-user>` ignores this change. |
| 19 | + - :ref:`box.session.effective_user() <box_session-effective_user>` shows this change. |
| 20 | + |
19 | 21 |
|
20 | 22 | :param string user-name: name of a target user |
21 | | - :param function-to-execute: name of a function, or definition of a function. |
| 23 | + :param function-to-execute: a function object. |
22 | 24 | Additional parameters may be passed to |
23 | | - ``box.session.su``, they will be interpreted |
24 | | - as parameters of function-to-execute. |
| 25 | + ``box.session.su()``, they will be interpreted |
| 26 | + as parameters of ``function-to-execute``. |
| 27 | + |
| 28 | + **Example 1** |
| 29 | + |
| 30 | + Change Tarantool's current user to ``guest``: |
| 31 | + |
| 32 | + .. code-block:: tarantoolsession |
| 33 | +
|
| 34 | + app:instance001> box.session.su('guest') |
| 35 | + --- |
| 36 | + ... |
| 37 | +
|
| 38 | + **Example 2** |
| 39 | + |
| 40 | + Change Tarantool's current user to ``temporary_user`` temporarily: |
25 | 41 |
|
26 | | - **Example:** |
| 42 | + .. code-block:: tarantoolsession |
27 | 43 |
|
28 | | - .. code-block:: tarantoolsession |
| 44 | + app:instance001> function get_current_user() return box.session.user() end |
| 45 | + --- |
| 46 | + ... |
| 47 | +
|
| 48 | + app:instance001> function get_effective_user() return box.session.effective_user() end |
| 49 | + --- |
| 50 | + ... |
| 51 | +
|
| 52 | + app:instance001> get_current_user() |
| 53 | + --- |
| 54 | + - admin |
| 55 | + ... |
| 56 | +
|
| 57 | + app:instance001> box.session.su('temporary_user', get_current_user) |
| 58 | + --- |
| 59 | + - admin |
| 60 | + ... |
29 | 61 |
|
30 | | - tarantool> function f(a) return box.session.user() .. a end |
| 62 | + app:instance001> box.session.su('temporary_user', get_effective_user) |
31 | 63 | --- |
| 64 | + - temporary_user |
32 | 65 | ... |
33 | 66 |
|
34 | | - tarantool> box.session.su('guest', f, '-xxx') |
| 67 | + app:instance001> box.session.su('temporary_user', get_effective_user, '-xxx') |
35 | 68 | --- |
36 | | - - guest-xxx |
| 69 | + - temporary_user-xxx |
37 | 70 | ... |
38 | 71 |
|
39 | | - tarantool> box.session.su('guest',function(...) return ... end,1,2) |
| 72 | + app:instance001> box.session.su('temporary_user', function(...) return box.session.user() end) |
40 | 73 | --- |
41 | | - - 1 |
42 | | - - 2 |
| 74 | + - admin |
43 | 75 | ... |
0 commit comments