Coverage for compiler_admin / commands / user / create.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 05:48 +0000

1import click 

2 

3from compiler_admin import Result 

4from compiler_admin.services.google import GoogleAccount, GoogleGroups, GoogleUsers 

5 

6 

7@click.command(context_settings={"ignore_unknown_options": True}) 

8@click.option("-n", "--notify", help="An email address to send the new password notification.") 

9@click.argument("username") 

10@click.argument("gam_args", nargs=-1, type=click.UNPROCESSED) 

11def create(username: str, notify: str = "", gam_args: list = []): 

12 """Create a new user account. 

13 

14 The user's password is randomly generated and requires reset on first login. 

15 

16 Extra args are passed along to GAM as options. 

17 

18 <https://github.com/GAM-team/GAM/wiki/Users#create-a-user> 

19 """ 

20 account = GoogleAccount(username) 

21 

22 if account.exists(): 

23 click.echo(f"User already exists: {account}") 

24 raise SystemExit(Result.FAILURE) 

25 

26 click.echo(f"User does not exist, continuing: {account}") 

27 

28 GoogleUsers().create(account, notify, *gam_args) 

29 GoogleGroups(GoogleGroups.GROUP_TEAM).add_user(account) 

30 

31 click.echo(f"User created successfully: {account}")