Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Mareš
Postal Owl
Commits
4fe34cbd
Commit
4fe34cbd
authored
Dec 09, 2021
by
Martin Mareš
Browse files
New CLI command for creating API keys
parent
f333257a
Changes
1
Hide whitespace changes
Inline
Side-by-side
owl.py
View file @
4fe34cbd
...
...
@@ -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 ###
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment