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)
This commit is contained in:
jesopo 2018-11-12 17:59:40 +00:00
parent 251f65c048
commit a943e69cee

View file

@ -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))