serve: Add ability to get all types of keys in /keys

This commit is contained in:
rlaphoenix 2022-08-01 23:07:59 +01:00
parent 64ae5709d3
commit 290da707ea
1 changed files with 14 additions and 11 deletions

View File

@ -150,16 +150,19 @@ async def keys(request: web.Request) -> web.Response:
# get key type # get key type
key_type = request.match_info["key_type"] key_type = request.match_info["key_type"]
try: if key_type == "ALL":
if key_type.isdigit(): key_type = None
key_type = License.KeyContainer.KeyType.Name(int(key_type)) else:
else: try:
License.KeyContainer.KeyType.Value(key_type) # only test if key_type.isdigit():
except ValueError as e: key_type = License.KeyContainer.KeyType.Name(int(key_type))
return web.json_response({ else:
"status": 400, License.KeyContainer.KeyType.Value(key_type) # only test
"message": f"The Key Type value is invalid, {e}" except ValueError as e:
}, status=400) return web.json_response({
"status": 400,
"message": f"The Key Type value is invalid, {e}"
}, status=400)
# get cdm # get cdm
if session_id not in request.app["sessions"]: if session_id not in request.app["sessions"]:
@ -183,7 +186,7 @@ async def keys(request: web.Request) -> web.Response:
"permissions": key.permissions, "permissions": key.permissions,
} }
for key in cdm._sessions[session_id].keys for key in cdm._sessions[session_id].keys
if key.type == key_type if not key_type or key.type == key_type
] ]
return web.json_response({ return web.json_response({