Begin work on API endpoint

This commit is contained in:
Mark Veidemanis 2022-07-21 13:40:11 +01:00
parent 80c016761f
commit 4a8605626a
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 27 additions and 4 deletions

12
api/views.py Normal file
View File

@ -0,0 +1,12 @@
from klein import Klein
class API(object):
"""
Our API webapp.
"""
app = Klein()
@app.route("/test", methods=["GET"])
def hello(self, request):
return "Hello"

View File

@ -34,7 +34,7 @@ class TokenCommand:
elif length == 4: elif length == 4:
if spl[1] == "add": if spl[1] == "add":
if not spl[2] in main.tokens.keys(): if not spl[2] in main.tokens.keys():
if spl[3] in ["relay"]: # more to come! if spl[3] in ["relay", "api"]: # more to come!
main.tokens[spl[2]] = { main.tokens[spl[2]] = {
"hello": str(uuid4()), "hello": str(uuid4()),
"usage": spl[3], "usage": spl[3],

View File

@ -20,7 +20,7 @@
"alias": "alias [<add|del>] [<num>]", "alias": "alias [<add|del>] [<num>]",
"auto": "auto [<network>]", "auto": "auto [<network>]",
"cmd": "cmd <relay> <user> <entity> <text ...>", "cmd": "cmd <relay> <user> <entity> <text ...>",
"token": "token <add|del|list> [<key>] [<relay>]", "token": "token <add|del|list> [<key>] [relay|api]",
"all": "all <entity> <text ...>", "all": "all <entity> <text ...>",
"allc": "allc <network|alias> <(network)|(alias)> <entity> <text ...>", "allc": "allc <network|alias> <(network)|(alias)> <entity> <text ...>",
"admall": "admall <entity> <text ...>", "admall": "admall <entity> <text ...>",

View File

@ -452,7 +452,8 @@ class IRCBot(IRCClient):
def got_list(self, listinfo): def got_list(self, listinfo):
if len(listinfo) == 0: # probably ngircd not supporting LIST >0 if len(listinfo) == 0: # probably ngircd not supporting LIST >0
return return
chankeep.initialList(self.net, self.num, listinfo, self.chanlimit) if main.config["ChanKeep"]["Enabled"]:
chankeep.initialList(self.net, self.num, listinfo, self.chanlimit)
def recheckList(self): def recheckList(self):
allRelays = chankeep.allRelaysActive(self.net) allRelays = chankeep.allRelaysActive(self.net)

View File

@ -5,17 +5,23 @@ from signal import SIGINT, signal
from sys import stderr, stdout from sys import stderr, stdout
from twisted.internet import reactor from twisted.internet import reactor
# Webapp stuff
from twisted.internet.protocol import Factory
from twisted.internet.ssl import DefaultOpenSSLContextFactory from twisted.internet.ssl import DefaultOpenSSLContextFactory
import core.logstash import core.logstash
import main import main
import modules.counters import modules.counters
from api.views import API
from core.relay import RelayFactory from core.relay import RelayFactory
from core.server import ServerFactory from core.server import ServerFactory
from utils.cleanup import handler from utils.cleanup import handler
from utils.loaders.command_loader import loadCommands from utils.loaders.command_loader import loadCommands
from utils.logging.log import log from utils.logging.log import log
Factory.noisy = False
main.initMain() main.initMain()
if "--debug" in sys.argv: # yes really if "--debug" in sys.argv: # yes really
@ -84,4 +90,8 @@ if __name__ == "__main__":
for net in main.network.keys(): for net in main.network.keys():
main.network[net].start_bots() main.network[net].start_bots()
modules.counters.setupCounterLoop() modules.counters.setupCounterLoop()
reactor.run() if main.config["API"]["Enabled"]:
api = API()
api.app.run(main.config["API"]["Address"], main.config["API"]["Port"])
else:
reactor.run()