Commit 4fe34cbd authored by Martin Mareš's avatar Martin Mareš
Browse files

New CLI command for creating API keys

parent f333257a
......@@ -1619,6 +1619,27 @@ def cli_add_teacher(course_ident, student):
db_connection.commit()
@app.cli.command("add-api-key")
@click.argument("course_ident")
@click.argument("teacher")
def cli_add_api_key(course_ident, teacher):
"""Create an API key for access to a given course."""
teacher_user = cli_find_user(teacher)
course = cli_find_course(course_ident)
key = secrets.token_hex(16)
db_query("""
INSERT INTO owl_api_keys(uid, cid, key)
VALUES (%s, %s, %s)
""",
(teacher_user.uid, course.cid, key))
db_connection.commit()
print(f'{teacher_user.uid}-{course.cid}-{key}')
### Sending notifications ###
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment