aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2018-11-12 17:59:40 +0000
committerGravatar jesopo2018-11-12 17:59:40 +0000
commita943e69cee1b5b115426c416a7d7cabe206cb7f9 (patch)
treee973c6646062117e0bc606d0c5f1c44e1f28fd69 /modules
parentBoldify authors in modules/github.py (diff)
signature
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)
Diffstat (limited to 'modules')
-rw-r--r--modules/rest_api.py15
1 files 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: <comment> [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))