getmango / Mango

Mango is a self-hosted manga server and web reader
https://getmango.app
MIT License
1.7k stars 120 forks source link

[Feature Request] API / CLI with documentation #44

Closed flying-sausages closed 4 years ago

flying-sausages commented 4 years ago

Is your feature request related to a problem? Please describe. I would like to integrate Mango into an installer toolset and would like to integrate mango's user management system into the toolset's, therefore being able to create users, change passwords and delete users.

Describe the solution you'd like An API/CLI access to make these changes would be very useful. This goes for more than just user management.

Additional context Nextcloud provides the occ command, The Lounge provides the thelounge CLI tool, etc. These tools allow admins to do user management on the command line, and use those commands within scripts for automation. Currently I would opt for doing SQL into the mango.db but nobody likes SQL...

hkalexling commented 4 years ago

May I know the use case of this? Sorry, I don't understand the "installer toolset" you mentioned. Is it a script you wrote that installs Mango and creates a user for you automatically?

Actually the Mango frontend talks to the server using a set of APIs (see https://github.com/hkalexling/Mango/blob/master/src/routes/api.cr) but they are not documented, because Mango is still in early development and some APIs might be updated/removed in future releases. I suppose we can have a section in the Wiki to document some commonly used APIs. Let me know what you think!

flying-sausages commented 4 years ago

This would be part of swizzin. The tool can add users to the server and create accounts for them within the user management systems of other applications, as well as make sure their passwordsa re in sync. I mainly need to set the admin username and password on install to be the same as the master user who is installing it.

hkalexling commented 4 years ago

Thanks for the clarification.

I took a look at your PR draft, and it looks like you are able to parse the initial password from stdout. With the initial username and password, you can call the login API, retrieve the token from cookies, and then use the token to create/delete users. These can be easily done with a few curl commands.

It would definitely work, but I am not sure if we should do this. Parsing password from stdout feels hacky, and it would be much more robust if we can do something like

mango adduser --username admin --password password

in the CLI. But you will have to wait for the next release if you prefer the CLI option.

flying-sausages commented 4 years ago

Happy to wait for this and patch it into swizzin later if the PR gets accepted before it :)

hkalexling commented 4 years ago

The requested CLI tool is added in v0.5.0. You can run mango admin user --help to see the detailed help message. Here are some examples:

# list the users
mango admin user list

# create a new user with admin access
mango admin user add -u new_user -p 123456 --admin

# rename the user
mango admin user update new_user -u new_name --admin

# remove admin access
mango admin user update new_name

# delete the user
mango admin user delete new_name

Thanks for the feature request!