autograder.cli.users.upsert

Upsert a server user.

usage: python3 -m autograder.cli.users.upsert [-h] [--version]
                                              [--server SERVER] [--user USER]
                                              [--pass PASS] [--dry-run]
                                              [--skip-inserts]
                                              [--skip-updates] [--send-emails]
                                              --new-email NEW_EMAIL
                                              [--new-name NEW_NAME]
                                              [--new-pass NEW_PASS]
                                              [--new-role {unknown,user,creator,admin,owner}]
                                              [--new-course NEW_COURSE]
                                              [--new-course-role {unknown,other,student,grader,admin,owner}]
                                              [--new-lms-id NEW_LMS_ID]
                                              [--testing-mode]

Upsert a server user.

options:
    -h, --help          show this help message and exit
    --version           show program's version number and exit

command-specific options:
    --server SERVER     The URL of the autograder server to communicate with.
    --user USER         The email of the user making this request.
    --pass PASS         The password of the user making this request.
    --dry-run           Do not commit/finalize the operation, just do all the
                        steps and state what the result would look like.
    --skip-inserts      Skip insert operations.
    --skip-updates      Skip update operations.
    --send-emails       Send any relevant emails to users affected by this
                        operation (e.g., a user being enrolled in a course).
    --new-email NEW_EMAIL
                        The email for the new user.
    --new-name NEW_NAME
                        The name for the new user.
    --new-pass NEW_PASS
                        The password for the new user (random if not
                        supplied).
    --new-role {unknown,user,creator,admin,owner}
                        The server role for the new user. (default: user)
    --new-course NEW_COURSE
                        An optional course to enroll the new user in
    --new-course-role {unknown,other,student,grader,admin,owner}
                        The course role for the new user. (default: student)
    --new-lms-id NEW_LMS_ID
                        The LMS ID for the new user.

testing options:
    --testing-mode      Run as if a test is being run (default: False).
 1"""
 2Upsert a server user.
 3"""
 4
 5import argparse
 6import sys
 7
 8import edq.util.json
 9
10import autograder.api.users.upsert
11import autograder.cli.parser
12
13def run_cli(args: argparse.Namespace) -> int:
14    """ Run the CLI. """
15
16    config = args._config_info.application_config
17
18    config.raw_server_users = [
19        {
20            'email': config.new_email,
21            'pass': config.new_pass,
22            'name': config.new_name,
23            'role': config.new_role,
24            'course': config.new_course,
25            'course-role': config.new_course_role,
26            'course-lms-id': config.new_lms_id,
27        },
28    ]
29
30    result = autograder.api.users.upsert.send(config, exit_on_error = True)
31    print(edq.util.json.dumps(result, indent = 4))
32
33    return 0
34
35def main() -> int:
36    """ Get a parser, parse the args, and call run. """
37
38    return run_cli(_get_parser().parse_args())
39
40def _get_parser() -> argparse.ArgumentParser:
41    """ Get a parser for this operation. """
42
43    parser = autograder.cli.parser.get_parser(
44        __doc__.strip(),
45        autograder.api.users.upsert.API_PARAMS)
46
47    return parser
48
49if (__name__ == '__main__'):
50    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
14def run_cli(args: argparse.Namespace) -> int:
15    """ Run the CLI. """
16
17    config = args._config_info.application_config
18
19    config.raw_server_users = [
20        {
21            'email': config.new_email,
22            'pass': config.new_pass,
23            'name': config.new_name,
24            'role': config.new_role,
25            'course': config.new_course,
26            'course-role': config.new_course_role,
27            'course-lms-id': config.new_lms_id,
28        },
29    ]
30
31    result = autograder.api.users.upsert.send(config, exit_on_error = True)
32    print(edq.util.json.dumps(result, indent = 4))
33
34    return 0

Run the CLI.

def main() -> int:
36def main() -> int:
37    """ Get a parser, parse the args, and call run. """
38
39    return run_cli(_get_parser().parse_args())

Get a parser, parse the args, and call run.