Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to promote a user to an admin #59

Merged
merged 36 commits into from
Oct 23, 2023

Conversation

amandahla
Copy link
Collaborator

@amandahla amandahla commented Oct 4, 2023

Overview

To promote a user to an admin you need to interact with the Synapse API. This action makes this easier so the user can use a juju command to do that like:

juju run-action synapse/0 promote-user-admin username=user1 --wait

Note:

  • The API call to do that requires an admin access token.
  • Mjolnir has the same requirement so the interaction with Synapse and peer data to get this admin access token is already implemented there.
  • This PR moves this implementation to a new module called Secret Storage so both, Mjolnir and the new action, can get an admin access token that is stored on peer data.
  • Mind that is a little bit different from the way it was implemented on Flask because to get an admin access token, we need Synapse to be running, register a new user and then we'll have the token we need. Since this is not needed for the charm itself, it will only happen if Mjolnir is enabled or if the user runs the action to make a user an admin. That's why we are not observing the leader elected or relation joined event.
  • Why not add the admin access token to charm_state? This would create a cyclic import like this: Cyclic import (actions -> actions.register_user -> synapse -> synapse.api -> charm_state -> secret_storage)

Plus:

  • Create a Secret Storage module
  • Change all references to admin_access_token to typing.Optional[str]
  • Fix typo in src/charm_state.py

Rationale

Provide an easy way to make a user an admin.

Juju Events Changes

Module Changes

Library Changes

Checklist

@amandahla amandahla requested a review from a team as a code owner October 4, 2023 13:53
@amandahla amandahla marked this pull request as draft October 4, 2023 13:53
@amandahla amandahla mentioned this pull request Oct 4, 2023
6 tasks
actions.yaml Outdated Show resolved Hide resolved
actions.yaml Outdated Show resolved Hide resolved
src/actions/change_user_admin.py Outdated Show resolved Hide resolved
src/actions/change_user_admin.py Outdated Show resolved Hide resolved
src/actions/change_user_admin.py Outdated Show resolved Hide resolved
src/mjolnir.py Show resolved Hide resolved
src/secret_storage.py Outdated Show resolved Hide resolved
src/secret_storage.py Outdated Show resolved Hide resolved
src/secret_storage.py Outdated Show resolved Hide resolved
src/synapse/api.py Outdated Show resolved Hide resolved
@amandahla amandahla changed the title WIP - Add action to make a user an admin WIP - Add action to promote a user to an admin Oct 9, 2023
@amandahla amandahla changed the title WIP - Add action to promote a user to an admin Add action to promote a user to an admin Oct 10, 2023
@amandahla amandahla marked this pull request as ready for review October 10, 2023 20:12
Copy link
Contributor

@jdkandersson jdkandersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not looked at the tests yet

src-docs/api.md Outdated Show resolved Hide resolved
src-docs/charm_state.py.md Outdated Show resolved Hide resolved
src-docs/promote_user_admin.md Outdated Show resolved Hide resolved
src/actions/__init__.py Outdated Show resolved Hide resolved
src/actions/promote_user_admin.py Outdated Show resolved Hide resolved
src/actions/promote_user_admin.py Outdated Show resolved Hide resolved
src/secret_storage.py Outdated Show resolved Hide resolved
nrobinaubertin
nrobinaubertin previously approved these changes Oct 16, 2023
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/mjolnir.py Outdated Show resolved Hide resolved
Copy link
Contributor

@gregory-schiano gregory-schiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

nrobinaubertin
nrobinaubertin previously approved these changes Oct 18, 2023
src/charm.py Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

Test coverage for 6d99b5c

Name                            Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------------------------
src/actions/__init__.py             3      0      0      0   100%
src/actions/register_user.py       22      0      2      0   100%
src/actions/reset_instance.py      21      0      2      0   100%
src/charm.py                      175      8     32      4    94%   124-125, 177-178, 197-198, 239, 253
src/charm_state.py                 63      1     12      1    97%   138
src/charm_types.py                 11      0      0      0   100%
src/database_client.py             53      1     10      3    94%   35, 47->exit, 69->exit
src/database_observer.py           54      4      6      0    93%   70-72, 88
src/exceptions.py                   4      0      0      0   100%
src/mjolnir.py                     76      8     20      2    88%   60-64, 73, 93-96
src/observability.py                9      0      0      0   100%
src/pebble.py                      75      9      4      2    86%   90-91, 93, 107-112
src/saml_observer.py               45      1      8      0    98%   64
src/synapse/__init__.py             3      0      0      0   100%
src/synapse/api.py                161      2     22      2    98%   207, 376
src/synapse/workload.py           192      6     30      5    95%   343-344, 360, 409->412, 458, 460, 465
src/user.py                        24      0      4      0   100%
---------------------------------------------------------------------------
TOTAL                             991     40    152     19    95%

Static code analysis report

Run started:2023-10-23 14:20:20.848145

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 4996
  Total lines skipped (#nosec): 4
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

@amandahla amandahla merged commit 818711a into main Oct 23, 2023
20 checks passed
@amandahla amandahla deleted the ISD-1112-synapse-add-action-to-make-user-an-admin branch October 23, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants