autograder .cli .users .auth
Authenticate as a user.
usage: python3 -m autograder.cli.users.auth [-h] [--version] [--server SERVER]
[--user USER] [--pass PASS]
[--testing-mode]
[--format {json,table,text}]
[--include-extra-fields]
[--pretty-headers]
[--skip-headers]
Authenticate as a 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.
testing options:
--testing-mode Run as if a test is being run (default: False).
output formatting options:
--format {json,table,text}
The format to display the output as (default: text).
--include-extra-fields
Include uncommon fields in results (default: False).
--pretty-headers When displaying headers, try to make them look
"pretty" (default: False).
--skip-headers Skip headers when outputting results, will not apply
to all formats (default: False).
1""" 2Authenticate as a user. 3""" 4 5import argparse 6import http 7import sys 8 9import autograder.api.users.auth 10import autograder.cli.parser 11import autograder.error 12 13def run_cli(args: argparse.Namespace) -> int: 14 """ Run the CLI. """ 15 16 config = args._config_info.application_config 17 18 try: 19 autograder.api.users.auth.send(config, exit_on_error = False) 20 except autograder.error.APIError as ex: 21 if (ex.code != http.HTTPStatus.UNAUTHORIZED): 22 raise ex 23 24 print("Authentication failed.") 25 return 1 26 27 print("Authentication successful.") 28 return 0 29 30def main() -> int: 31 """ Get a parser, parse the args, and call run. """ 32 33 return run_cli(_get_parser().parse_args()) 34 35def _get_parser() -> argparse.ArgumentParser: 36 """ Get a parser for this operation. """ 37 38 parser = autograder.cli.parser.get_parser( 39 __doc__.strip(), 40 autograder.api.users.auth.API_PARAMS, 41 include_output_format = True) 42 43 return parser 44 45if (__name__ == '__main__'): 46 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 try: 20 autograder.api.users.auth.send(config, exit_on_error = False) 21 except autograder.error.APIError as ex: 22 if (ex.code != http.HTTPStatus.UNAUTHORIZED): 23 raise ex 24 25 print("Authentication failed.") 26 return 1 27 28 print("Authentication successful.") 29 return 0
Run the CLI.
def
main() -> int:
31def main() -> int: 32 """ Get a parser, parse the args, and call run. """ 33 34 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.