You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
2 years ago
|
from uuid import uuid4
|
||
2 years ago
|
|
||
2 years ago
|
from yaml import dump
|
||
|
|
||
|
import main
|
||
|
|
||
2 years ago
|
|
||
5 years ago
|
class TokenCommand:
|
||
6 years ago
|
def __init__(self, *args):
|
||
|
self.token(*args)
|
||
|
|
||
2 years ago
|
def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||
6 years ago
|
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():
|
||
2 years ago
|
if spl[3] in ["relay", "api"]: # more to come!
|
||
2 years ago
|
main.tokens[spl[2]] = {
|
||
|
"hello": str(uuid4()),
|
||
|
"usage": spl[3],
|
||
|
"counter": str(uuid4()),
|
||
|
}
|
||
6 years ago
|
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)
|