-
Notifications
You must be signed in to change notification settings - Fork 27
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
Rewriting the user modify command #126
base: master
Are you sure you want to change the base?
Conversation
Thanks for getting this started! |
@JOJ0 Please review the structure of the commands and the API and request any changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conclusive thoughts: If there are verbs in a command they are self-descriptive. Eg. user deactivate
If there are not they are not 100% obvious what they do (display or modify). Eg. user display-name
Not sure if I'm nitpicking here too much or if the priority should be "shorter" names. Eg. set-display-name
is rather tedious to type and might be a bad choice...
@@ -600,6 +600,7 @@ def user_modify(self, user_id, password, display_name, threepid, | |||
|
|||
Threepid should be passed as a tuple in a tuple | |||
""" | |||
# TODO: deprecate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we should deprecate synadm user modify
within this PR, or actually I'd like to achieve this: As soon as everything from user modify
has its own command or the user should be warned - best with a literal log.warning.
But I'm not sure anymore wether we'd like to keep some parts of user modify
as-is and not invent new commands. Can't recall what was the outcome of that discussion, please help me remember! :-)
If we would keep parts of modify
as-is and do not plan to change, then probably it would be better that exactly when these options are used, a log.warning is spit out. Not sure though what's best....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm not sure anymore wether we'd like to keep some parts of
user modify
as-is and not invent new commands. Can't recall what was the outcome of that discussion, please help me remember! :-)If we would keep parts of
modify
as-is and do not plan to change, then probably it would be better that exactly when these options are used, a log.warning is spit out. Not sure though what's best....
I think deprecating by warning the user is the best option, and we could remove the modify command in the future.
We also do not add any new functions to the modify command to discourage use of it.
@@ -500,6 +500,80 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name, | |||
click.echo("Abort.") | |||
|
|||
|
|||
# for these placeholders, function similarly to the modify command, but in | |||
# it's own command. | |||
# TODO: find 3pid modify command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a 3pid command already, but it's for displaying only: https://synadm.readthedocs.io/en/latest/synadm.cli.user.html#synadm-user-3pid
That I guess is what you are thinking about? Where should we put / and how should we name the modify command for 3pid modify?
Currently 3pid modify is included with the original user modify
command: https://synadm.readthedocs.io/en/latest/synadm.cli.user.html#cmdoption-synadm-user-modify-t
synadm/cli/user.py
Outdated
@click.pass_obj | ||
def reactivate(helper, user_id): | ||
# TODO | ||
# TODO: does this require a password? merge into password? user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely does require a password.
Look for this phrase "Note: the password field must also be set if both of the following are true:" around here: https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#create-or-modify-account
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only requires a password if synapse is storing a password, so I'm thinking of a required flag of either --password $PASSWORD
(must have argument) or --no-password
(no argument), but I'm not sure how to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--password $PASSWORD
(must have argument)
Actually that's a bad idea and we should ask for the password on stdin instead of on the command line arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically agree but on the other hand: why not borrow the ideas we have over at the user password
command?
I think we have both: stdin and cli arg
I still think that securitywise it's an admin's choice whether they want to eg. modify 10 testusers on a playground server - scripted! Or they'd like to securely modify one real user's account on the cli.
It's an old unix philosophy: Know what you are doing if you are root!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So:
--prompt
(default, mutually exclusive of--no-prompt
)--no-prompt
(mutually exclusive of--prompt
, leave errors up to synapse)--password
(likely insecure but useful for automation in testing environments, takes priority over stdin options)
Those arguments will probably also apply to the password command, if it doesn't have such (and it doesn't seem like the password command has such options).
Tangent: We do not securely prompt for a token in synadm config
. We really should do that (no echo and iTerm enables secure keyboard entry on password prompt), but I'm not sure how to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding reusing of an option or even a couple of options, I think I found a nice way we could try. Creating a decorator that applies a group of options. Have a look at the very bottom of this post: https://stackoverflow.com/a/66743881/10207149
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--prompt
(default, mutually exclusive of--no-prompt
)--no-prompt
(mutually exclusive of--prompt
, leave errors up to synapse)--password
(likely insecure but useful for automation in testing environments, takes priority over stdin options)Exactly, something like that!
Those arguments will probably also apply to the password command, if it doesn't have such (and it doesn't seem like the password command has such options).
Oh my bad. When I talked about "borrowing ideas of
user password
command" I probably ment theuser modify
command - We have--password
and--password-prompt
there.As we had it so often already with Click/synadm, copying boilerplate code is the quick way but it would be nice if we could find a way to prepare these options once and reuse them in several commands. That also applies to any sanity-checking code we'd require on the UI end.
Regarding password options streamlining, I would love if we could make use of the _common module I introduced here: 79d0ea4
We could put all password-related options into that module and reuse them with all password-related commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could put all password-related options into that module and reuse them with all password-related commands.
ahem: https://click.palletsprojects.com/en/8.1.x/api/#click.password_option
also, 79d0ea4 doesn't look like it's part of the master branch, so i'll not do that yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, certainly I ment once it's merged ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes: I agree we should also make use of that click.password_option
For some reason I did not use it in my intial implementation of user password
- there might be a reason for it but it could also be that I just didn't read the docs carfully enough (it's been around since Click 6.x at least or even since always ;-). I used a confirmation prompt thing though :-)
$ synadm user password testuser3
Password:
Repeat for confirmation:
{}
Lines 286 to 288 in be77cef
@click.option( | |
"--password", "-p", prompt=True, hide_input=True, | |
confirmation_prompt=True, help="New password.") |
We do also have use-cases were this option might not be enough....for example when handling with tokens there is more to it than either by prompt or by passing a cli arg, for example passing by environment variable as well... probably off-topic here....just mentioning..
checklist of what's been planned/already done so far:
|
It should be with a |
I'm gonna leave those behind for later, keeping the |
Nice summary! Why not move it to the initial description of this PR? Easier to find and also for future reference what's still missing/postponed (as I just read in your subsequent post you plan on doing) |
Good question what's best.... I just had a look on your work so far in reality/--help:
It seems there is no one-way of doing it right - verb in front, verb on the end of the command. Too long, too short command names....I'm not sure where to go actually.... One thing I'm wondering though: let me check, I think I researched this already ages ago and by default Click doesn't have it..... |
See my PR description:
|
Ah ok, not sure how you ment that. You will move the checklist up into the description once it's finished? Anyway, all good, work away! :-) |
I think at this point, we have a mostly clear structure although with not so clear command names. That should allow me to start implementing the commands while we continue deciding on the command names until we find some answer. We can easily change the name later (although less so, the structure, if necessary).
I have these ideas for command names for setting stuff:
|
No, not really. The checklist in the PR description shows up in PR listing as how much has been done. Including the placeholders would add to that number, which isn't really desirable since not all commands have been included, which means not 100% of the tasks done. Although on whether to include checklist or not in the PR description, I'm not sure which side to err on. |
Please go ahead with implementation and just use what you suggested / we have so far! Yes we could think out for ages on how commands should be named :-) Let's see when implementation is finished whether we'd like to change them. |
f05f3b7
to
87ace0f
Compare
to not duplicate the same query code
87ace0f
to
dc615e4
Compare
Just realized, user modify API can also create users. Not sure how we'll deal with that, we might have to keep the user modify command around and possibly also update it with new stuff. |
dc615e4
to
70fdb89
Compare
Oh, I'm sorry I didn't mention that, I was just assuming you are aware of that. I also didn't realise/think hard enough that it could be a problem with all the "redesign"..... :-/ Sorry my bad! |
To wrap this up and partly spice with some new ideas. I was thinking about all this a little: The current Modifying is not possible anymore with this new method Maybe we can reuse _ at least some_ of the cli-options by putting them into the |
Currently a placeholder. Only about the structure of commands (and maybe the parameters) until agreed.
Initial idea: #100 (comment)
Resolves #100
Placeholder/existing commands checklist
(Commits history will 100% get rewritten after the code is finished)
Progress checklist:
synadm user reactivate
with--batch
)