From a943e69cee1b5b115426c416a7d7cabe206cb7f9 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 12 Nov 2018 17:59:40 +0000 Subject: [PATCH] Change API keys to be hex representations of UUID4s, change their value in the database to be a dictionary ({"comment": , "permissions": }) and change the !apikey command to take a `comment` arg (to note what specific keys are intended for) and vararg `permissions` (a list of endpoints the API key is allowed to hit) --- modules/rest_api.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/rest_api.py b/modules/rest_api.py index 19720445..0bccb793 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -108,13 +108,14 @@ class Module(ModuleManager.BaseModule): def api_key(self, event): """ :help: Generate a new API key - :usage: [comment] + :usage: [permitted endpoints ...] :permission: api-key :prefix: APIKey """ - api_key = str(uuid.uuid4()) - if event["args_split"]: - api_key = "%s-%s" % (event["args_split"][0], api_key) - - self.bot.set_setting("api-key-%s" % api_key, []) - event["stdout"].write(api_key) + api_key = uuid.uuid4().hex + comment = event["args_split"][0] + self.bot.set_setting("api-key-%s" % api_key, { + "comment": comment, + "permissions": event["args_spit"][1:] + }) + event["stdout"].write("New API key ('%s'): %s" % (comment, api_key))