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:
parent
251f65c048
commit
a943e69cee
1 changed files with 8 additions and 7 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue