|
| 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 | + - :ref:`box.session.user() <box_session-user>` ignores this change |
| 18 | + - :ref:`box.session.effective_user() <box_session-effective_user>` shows this change. |
19 | 19 |
|
20 | 20 | :param string user-name: name of a target user |
21 | | - :param function-to-execute: name of a function, or definition of a function. |
| 21 | + :param function-to-execute: a function object. It can be either name of a function or definition of a function. |
22 | 22 | Additional parameters may be passed to |
23 | | - ``box.session.su``, they will be interpreted |
24 | | - as parameters of function-to-execute. |
| 23 | + ``box.session.su()``, they will be interpreted |
| 24 | + as parameters of ``function-to-execute``. |
| 25 | + |
| 26 | + **Example 1** |
| 27 | + |
| 28 | + Change Tarantool's current user to ``guest``: |
| 29 | + |
| 30 | + .. code-block:: tarantoolsession |
| 31 | +
|
| 32 | + app:instance001> box.session.su('guest') |
| 33 | + --- |
| 34 | + ... |
| 35 | +
|
| 36 | + **Example 2** |
| 37 | + |
| 38 | + Change Tarantool's current user to ``temp_current_user`` temporarily: |
25 | 39 |
|
26 | | - **Example:** |
| 40 | + .. code-block:: tarantoolsession |
27 | 41 |
|
28 | | - .. code-block:: tarantoolsession |
| 42 | + app:instance001> function get_current_user() return box.session.user() end |
| 43 | + --- |
| 44 | + ... |
| 45 | +
|
| 46 | + app:instance001> function get_effective_user() return box.session.effective_user() end |
| 47 | + --- |
| 48 | + ... |
| 49 | +
|
| 50 | + app:instance001> box.session.su('temporary_user', get_current_user) |
| 51 | + --- |
| 52 | + - admin |
| 53 | + ... |
29 | 54 |
|
30 | | - tarantool> function f(a) return box.session.user() .. a end |
| 55 | + app:instance001> box.session.su('temporary_user', get_effective_user) |
31 | 56 | --- |
| 57 | + - temporary_user |
32 | 58 | ... |
33 | 59 |
|
34 | | - tarantool> box.session.su('guest', f, '-xxx') |
| 60 | + app:instance001> box.session.su('temporary_user', get_effective_user, '-xxx') |
35 | 61 | --- |
36 | | - - guest-xxx |
| 62 | + - temporary_user-xxx |
37 | 63 | ... |
38 | 64 |
|
39 | | - tarantool> box.session.su('guest',function(...) return ... end,1,2) |
| 65 | + app:instance001> box.session.su('temporary_user', function(...) return box.session.user() end) |
40 | 66 | --- |
41 | | - - 1 |
42 | | - - 2 |
| 67 | + - admin |
43 | 68 | ... |
0 commit comments