@@ -15,19 +15,55 @@ a while. Note that this does not delete the user's storage.
15
15
The script ` scripts/delete-unused-users.py ` will delete anyone who hasn't
16
16
registered any activity in a given period of time, double checking to make sure
17
17
they aren't active right now. This will require users to log in again the next
18
- time they use the hub, but that is probably fine .
18
+ time they use the hub.
19
19
20
20
This should be done before the start of each semester, particularly on hubs
21
21
with a lot of users.
22
22
23
- ## Run the script
23
+ ## Running the script
24
24
25
- You can run the script on your own device. The script depends on the
26
- ` jhub_client ` python library. This can be installed with
27
- ` pip install jhub_client ` .
25
+ ```
26
+ ./delete-unused-users.py --help
27
+ usage: delete-unused-users.py [-h] [-c CREDENTIALS] [-H HUB_URL] [--dry_run]
28
+ [--inactive_since INACTIVE_SINCE] [-v] [-d]
28
29
29
- 1 . You will need to acquire a JupyterHub API token with administrative
30
- rights. A hub admin can go to ` {hub_url}/hub/token ` to create a new
31
- one.
32
- 2 . Set the environment variable ` JUPYTERHUB_API_TOKEN ` to the token.
33
- 3 . Run ` python scripts/delete-unused-users.py --hub_url {hub_url} `
30
+ options:
31
+ -h, --help show this help message and exit
32
+ -c CREDENTIALS, --credentials CREDENTIALS
33
+ Path to a json file containing hub url and api keys.
34
+ Format is: {"hub1_url": "hub1_key", "hub2_url":, "hub2_key"}
35
+ -H HUB_URL, --hub_url HUB_URL
36
+ Fully qualified URL to the JupyterHub. You must also
37
+ set the JUPYTERHUB_API_TOKEN environment variable with
38
+ the API key.
39
+ --dry_run Dry run without deleting users.
40
+ --inactive_since INACTIVE_SINCE
41
+ Period of inactivity after which users are considered
42
+ for deletion (literal string constructor values for
43
+ timedelta objects).
44
+ -v, --verbose Set info log level.
45
+ -d, --debug Set debug log level.
46
+ ```
47
+
48
+ The 'best' way to run this script is to log in to each hub and in the Admin
49
+ page, generate a token. The URL will be ` {hub_url}/hub/token ` . You can store
50
+ the tokens in a json-like configuration file on your device with the following
51
+ format:
52
+
53
+ ```
54
+ {
55
+ "https://a11y.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
56
+ "https://astro.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
57
+ "https://biology.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
58
+ "https://cee.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
59
+ "https://data8.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
60
+ "https://data100.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
61
+ "https://data101.datahub.berkeley.edu": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
62
+ }
63
+ ```
64
+
65
+ Then you can execute the script as such:
66
+
67
+ ```
68
+ ./delete-unused-users.py -c ~/.datahub/hub-api-tokens.json -v --inactive_since=days=30
69
+ ```
0 commit comments