This documents the various utility scripts that are provided with the project whose purposes are to support the operation of the application in one way or another.
To get a list of the available scripts/flask commands that can be run, do:
FLASK_APP="main.py" flask --help
With that, you should get a list of commands, which as of 2023-05-26 are:
. . . output truncated to save space ... Commands: apply-migrations Apply the dabasase migrations. assign-system-admin Assign user with ID `user_id` administrator role. init-dev-clients Initialise a development client for OAuth2 sessions. init-dev-users Initialise development users for OAuth2 sessions. routes Show the routes for the app. run Run a development server. shell Run a shell in the app context.
*NB*: You can simply do `export FLASK_APP="main.py"` at the beginning of your shell session and then just run the commands without prepending with the `FLASK_APP="main.py"` declaration.
You can register an new user and set them as the system administrator with:
FLASK_APP="main.py" flask register-admin
A typical session might go something like:
$ FLASK_APP="main.py" flask register-admin Enter the user's name: CLI SysAdmin Enter the administrator's email: email@example.com Enter password: Confirm password: $
You can also run the script directly (without flask) with:
$ python3 -m scripts.register_sys_admin /home/frederick/genenetwork/gn3_files/db/auth.db
changing "/home/frederick/genenetwork/gn3_files/db/auth.db" to the path to your database file.
If a user already exists in your system, and you want to make that user system admin, you could do it with:
FLASK_APP="main.py" flask assign-system-admin 5b15ef01-a9d7-4ee4-9a38-fe9dd1d871b8
You can retrieve the user ID from the (SQLite) database, with something like:
$ sqlite3 /home/frederick/genenetwork/gn3_files/db/auth.db SQLite version 3.40.0 2022-11-16 12:10:08 Enter ".help" for usage hints. sqlite> SELECT * FROM users; firstname.lastname@example.org|Test Development User email@example.com|A New Group Member firstname.lastname@example.org|Frederick the Group Leader
This will only act on any existing data that is not already linked with a user group in the new auth system.
This can be run using flask with
FLASK_APP="main.py" flask make-data-public
which will use the application's configuration settings for the auth(entic|oris)ation database and the MariaDB database.
You could also run the script directly with:
python3 -m scripts.migrate_existing_data AUTHDBPATH MYSQLDBURI
where `AUTHDBPATH` and `MYSQLDBURI` are replaced with the appropriate values, e.g.
python3 -m scripts.migrate_existing_data \ /home/frederick/genenetwork/gn3_files/db/auth.db \ mysql://webqtlout:email@example.com:3307/db_webqtl
FLASK_APP="main.py" flask routes
FLASK_APP="main.py" flask shell
The commands in this section are meant for easing development and are not to be run in a production environment.
FLASK_APP="main.py" flask init-dev-users
That will initialise your development database with a development user with the following details:
- User ID: 0ad1917c-57da-46dc-b79e-c81c91e5b928 - Email: firstname.lastname@example.org - Password: testpasswd
FLASK_APP="main.py" flask init-dev-clients