2022-07-21 12:40:01 +00:00
|
|
|
from uuid import uuid4
|
2022-07-21 12:39:59 +00:00
|
|
|
|
2022-07-21 12:40:09 +00:00
|
|
|
from yaml import dump
|
|
|
|
|
|
|
|
import main
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class TokenCommand:
|
2019-03-18 21:01:28 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.token(*args)
|
|
|
|
|
2022-07-21 12:40:01 +00:00
|
|
|
def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
2019-03-18 21:01:28 +00:00
|
|
|
if authed:
|
|
|
|
if length == 2:
|
|
|
|
if spl[1] == "list":
|
|
|
|
info(dump(main.tokens))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("token")
|
|
|
|
return
|
|
|
|
elif length == 3:
|
|
|
|
if spl[1] == "del":
|
|
|
|
if spl[2] in main.tokens.keys():
|
|
|
|
del main.tokens[spl[2]]
|
|
|
|
main.saveConf("tokens")
|
|
|
|
success("Successfully removed token: %s" % spl[2])
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
failure("No such token")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("token")
|
|
|
|
return
|
|
|
|
elif length == 4:
|
|
|
|
if spl[1] == "add":
|
|
|
|
if not spl[2] in main.tokens.keys():
|
2022-07-21 12:40:11 +00:00
|
|
|
if spl[3] in ["relay", "api"]: # more to come!
|
2022-07-21 12:39:41 +00:00
|
|
|
main.tokens[spl[2]] = {
|
|
|
|
"hello": str(uuid4()),
|
|
|
|
"usage": spl[3],
|
|
|
|
"counter": str(uuid4()),
|
|
|
|
}
|
2019-03-18 21:01:28 +00:00
|
|
|
main.saveConf("tokens")
|
|
|
|
success("Successfully created token %s:" % spl[2])
|
|
|
|
info(dump(main.tokens[spl[2]]))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("token")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
failure("Token already exists: %s" % spl[2])
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("token")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("token")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|