Skip to content

Commit dab9964

Browse files
authored
Refactor: organize user commands (#18)
2 parents c91ba56 + 5d94c0a commit dab9964

22 files changed

+309
-265
lines changed

README.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@ Built on top of [GAMADV-XTD3](https://github.com/taers232c/GAMADV-XTD3) and [GYB
1010

1111
```bash
1212
$ compiler-admin -h
13-
usage: compiler-admin [-h] [-v] {info,init,create,convert,delete,offboard,reset-password,restore,signout} ...
13+
usage: compiler-admin [-h] [-v] {info,init,user} ...
1414

1515
positional arguments:
16-
{info,init,create,convert,delete,offboard,reset-password,restore,signout}
17-
info Print configuration and debugging information.
18-
init Initialize a new admin project. This command should be run once before any others.
19-
create Create a new user in the Compiler domain.
20-
convert Convert a user account to a new type.
21-
delete Delete a user account.
22-
offboard Offboard a user account.
23-
reset-password Reset a user's password to a randomly generated string.
24-
restore Restore an email backup from a prior offboarding.
25-
signout Signs a user out from all active sessions.
16+
{info,init,user} The command to run
17+
info Print configuration and debugging information.
18+
init Initialize a new admin project. This command should be run once before any others.
19+
user Work with users in the Compiler org.
2620

2721
options:
28-
-h, --help show this help message and exit
29-
-v, --version show program's version number and exit
22+
-h, --help show this help message and exit
23+
-v, --version show program's version number and exit
3024
```
3125
3226
## Getting started
@@ -60,11 +54,34 @@ The `init` commands follows the steps in the [GAMADV-XTD3 Wiki](https://github.c
6054
6155
Additionally, GYB is used for Gmail backup/restore. See the [GYB Wiki](https://github.com/GAM-team/got-your-back/wiki) for more information.
6256
63-
## Creating a user
57+
## Working with users
58+
59+
The following commands are available to work with users in the Compiler domain:
60+
61+
```bash
62+
$ compiler-admin user -h
63+
usage: compiler-admin user [-h] {create,convert,delete,offboard,reset-password,restore,signout} ...
64+
65+
positional arguments:
66+
{create,convert,delete,offboard,reset-password,restore,signout}
67+
The user command to run.
68+
create Create a new user in the Compiler domain.
69+
convert Convert a user account to a new type.
70+
delete Delete a user account.
71+
offboard Offboard a user account.
72+
reset-password Reset a user's password to a randomly generated string.
73+
restore Restore an email backup from a prior offboarding.
74+
signout Signs a user out from all active sessions.
75+
76+
options:
77+
-h, --help show this help message and exit
78+
```
79+
80+
### Creating a user
6481

6582
```bash
66-
$ compiler-admin create -h
67-
usage: compiler-admin create [-h] [--notify NOTIFY] username
83+
$ compiler-admin user create -h
84+
usage: compiler-admin user create [-h] [--notify NOTIFY] username
6885

6986
positional arguments:
7087
username A Compiler user account name, sans domain.
@@ -76,11 +93,11 @@ options:
7693

7794
Additional options are passed through to GAM, see more about [GAM user create](https://github.com/taers232c/GAMADV-XTD3/wiki/Users#create-a-user)
7895

79-
## Convert a user
96+
### Convert a user
8097

8198
```bash
82-
$ compiler-admin convert -h
83-
usage: compiler-admin convert [-h] username {contractor,partner,staff}
99+
$ compiler-admin user convert -h
100+
usage: compiler-admin user convert [-h] username {contractor,partner,staff}
84101

85102
positional arguments:
86103
username A Compiler user account name, sans domain.
@@ -91,11 +108,11 @@ options:
91108
-h, --help show this help message and exit
92109
```
93110

94-
## Offboarding a user
111+
### Offboarding a user
95112

96113
```bash
97-
$ compiler-admin offboard -h
98-
usage: compiler-admin offboard [-h] [--alias ALIAS] [--force] username
114+
$ compiler-admin user offboard -h
115+
usage: compiler-admin user offboard [-h] [--alias ALIAS] [--force] username
99116

100117
positional arguments:
101118
username A Compiler user account name, sans domain.
@@ -108,13 +125,13 @@ options:
108125
109126
This script creates a local backup of `USER`'s inbox, see [Restore](#restore-an-email-backup)
110127

111-
## Restore an email backup
128+
### Restore an email backup
112129

113130
Retore a backup from a prior [Offboarding](#offboarding-a-user) into the `[email protected]` account.
114131

115132
```bash
116-
$ compiler-admin restore -h
117-
usage: compiler-admin restore [-h] username
133+
$ compiler-admin user restore -h
134+
usage: compiler-admin user restore [-h] username
118135
119136
positional arguments:
120137
username The user's account name, sans domain.

compiler_admin/commands/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from compiler_admin.services.google import CallGAMCommand, CallGYBCommand
33

44

5-
def info() -> int:
5+
def info(*args, **kwargs) -> int:
66
"""Print information about this package and the GAM environment.
77
88
Returns:

compiler_admin/commands/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _clean_config_dir(config_dir: Path) -> None:
2222
rmtree(path)
2323

2424

25-
def init(args: Namespace) -> int:
25+
def init(args: Namespace, *extras) -> int:
2626
"""Initialize a new GAM project.
2727
2828
See https://github.com/taers232c/GAMADV-XTD3/wiki/How-to-Install-Advanced-GAM
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from argparse import Namespace
2+
3+
from compiler_admin.commands.user.create import create # noqa: F401
4+
from compiler_admin.commands.user.convert import convert # noqa: F401
5+
from compiler_admin.commands.user.delete import delete # noqa: F401
6+
from compiler_admin.commands.user.offboard import offboard # noqa: F401
7+
from compiler_admin.commands.user.reset_password import reset_password # noqa: F401
8+
from compiler_admin.commands.user.restore import restore # noqa: F401
9+
from compiler_admin.commands.user.signout import signout # noqa: F401
10+
11+
12+
def user(args: Namespace, *extra):
13+
# try to call the subcommand function directly from local symbols
14+
# if the subcommand function was imported above, it should exist in locals()
15+
if args.subcommand in locals():
16+
locals()[args.subcommand](args, *extra)
17+
else:
18+
raise ValueError(f"Unknown user subcommand: {args.subcommand}")

compiler_admin/commands/offboard.py renamed to compiler_admin/commands/user/offboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from tempfile import NamedTemporaryFile
33

44
from compiler_admin import RESULT_SUCCESS, RESULT_FAILURE
5-
from compiler_admin.commands.delete import delete
6-
from compiler_admin.commands.signout import signout
5+
from compiler_admin.commands.user.delete import delete
6+
from compiler_admin.commands.user.signout import signout
77
from compiler_admin.services.google import (
88
USER_ARCHIVE,
99
CallGAMCommand,

compiler_admin/commands/reset_password.py renamed to compiler_admin/commands/user/reset_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from argparse import Namespace
22

33
from compiler_admin import RESULT_SUCCESS, RESULT_FAILURE
4-
from compiler_admin.commands.signout import signout
4+
from compiler_admin.commands.user.signout import signout
55
from compiler_admin.services.google import USER_HELLO, CallGAMCommand, user_account_name, user_exists
66

77

0 commit comments

Comments
 (0)