Skip to content

Commit e9862ff

Browse files
author
Ilyas Gasanov
committed
[DOP-19931] Add manage_superusers script
1 parent d2254d5 commit e9862ff

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ services:
3838
- 8000:8000
3939
environment:
4040
# list here usernames which should be assigned SUPERUSER role on application start
41-
SYNCMASTER__ENTRYPOINT__SUPERUSERS: syncmaster
41+
SYNCMASTER__ENTRYPOINT__SUPERUSERS: admin
4242
# PROMETHEUS_MULTIPROC_DIR is required for multiple workers, see:
4343
# https://prometheus.github.io/client_python/multiprocess/
4444
PROMETHEUS_MULTIPROC_DIR: /tmp/prometheus-metrics

docker/entrypoint_backend.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set -e
33

44
python -m syncmaster.db.migrations upgrade head
55

6-
# use only by entrypoint
76
if [[ "x${SYNCMASTER__ENTRYPOINT__SUPERUSERS}" != "x" ]]; then
87
superusers=$(echo "${SYNCMASTER__ENTRYPOINT__SUPERUSERS}" | tr "," " ")
98
python -m syncmaster.backend.scripts.manage_superusers add ${superusers}

docs/backend/install.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,29 @@ Options can be set via ``.env`` file or ``environment`` section in ``docker-comp
2828

2929
After container is started and ready, open http://localhost:8000/docs.
3030

31+
Managing superusers
32+
^^^^^^^^^^^^^^^^^^^
33+
3134
Users listed in ``SYNCMASTER__ENTRYPOINT__SUPERUSERS`` env variable will be automatically promoted to ``SUPERUSER`` role.
3235

36+
Adding superusers:
37+
38+
.. code-block:: console
39+
40+
$ python -m syncmaster.backend.scripts.manage_superusers add <username1> <username2>
41+
42+
Removing superusers:
43+
44+
.. code-block:: console
45+
46+
$ python -m syncmaster.backend.scripts.manage_superusers remove <username1> <username2>
47+
48+
Viewing list of superusers:
49+
50+
.. code-block:: console
51+
52+
$ python -m syncmaster.backend.scripts.manage_superusers list
53+
3354
Without docker
3455
--------------
3556

tests/test_database/test_manage_superusers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ async def test_add_superusers(caplog, session: AsyncSession, simple_users: list[
5050

5151
@pytest.mark.parametrize("simple_users", [10], indirect=True)
5252
async def test_remove_superusers(caplog, session: AsyncSession, simple_users: list[MockUser]):
53-
# users 0 and 1 will be superusers, 2-10 will not
53+
# users 0-4 will be superusers, 5-10 will not
5454
to_create = [user.username for user in simple_users[:5]]
55-
to_delete = [user.username for user in simple_users[2:]]
55+
to_delete = [user.username for user in simple_users[5:]]
5656

57-
expected_superusers = [user.username for user in simple_users[:2]]
58-
expected_not_superusers = [user.username for user in simple_users[2:]]
57+
expected_superusers = [user.username for user in simple_users[:5]]
58+
expected_not_superusers = [user.username for user in simple_users[5:]]
5959

6060
await add_superusers(session, to_create)
6161

0 commit comments

Comments
 (0)