fix: Cleanup plugin.py
All checks were successful
Build Docker / Build Image (push) Successful in 1m13s

This commit is contained in:
Nathan Woodburn 2024-11-21 19:35:33 +11:00
parent 40f520ba5e
commit 3290240a25
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -5,7 +5,6 @@ import sys
import hashlib import hashlib
def listPlugins(): def listPlugins():
plugins = [] plugins = []
for file in os.listdir("plugins"): for file in os.listdir("plugins"):
@ -27,7 +26,7 @@ def listPlugins():
# Write a new signatures file # Write a new signatures file
with open("plugins/signatures.json", "w") as f: with open("plugins/signatures.json", "w") as f:
json.dump(signatures, f) json.dump(signatures, f)
for plugin in plugins: for plugin in plugins:
# Hash the plugin file # Hash the plugin file
pluginHash = hashPlugin(plugin["link"]) pluginHash = hashPlugin(plugin["link"])
@ -45,6 +44,7 @@ def pluginExists(plugin: str):
return True return True
return False return False
def verifyPlugin(plugin: str): def verifyPlugin(plugin: str):
signatures = [] signatures = []
try: try:
@ -73,12 +73,6 @@ def hashPlugin(plugin: str):
break break
sha256.update(data) sha256.update(data)
return sha256.hexdigest() return sha256.hexdigest()
def getPluginData(pluginStr: str): def getPluginData(pluginStr: str):
@ -101,18 +95,20 @@ def getPluginData(pluginStr: str):
info["verified"] = False info["verified"] = False
else: else:
info["verified"] = True info["verified"] = True
return info return info
def getPluginFunctions(plugin: str): def getPluginFunctions(plugin: str):
plugin = importlib.import_module("plugins."+plugin) plugin = importlib.import_module("plugins."+plugin)
return plugin.functions return plugin.functions
def runPluginFunction(plugin: str, function: str, params: dict, authentication: str): def runPluginFunction(plugin: str, function: str, params: dict, authentication: str):
plugin_module = importlib.import_module("plugins."+plugin) plugin_module = importlib.import_module("plugins."+plugin)
if function not in plugin_module.functions: if function not in plugin_module.functions:
return {"error": "Function not found"} return {"error": "Function not found"}
if not hasattr(plugin_module, function): if not hasattr(plugin_module, function):
return {"error": "Function not found"} return {"error": "Function not found"}
@ -134,7 +130,6 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
if pluginHash not in signatures: if pluginHash not in signatures:
return {"error": "Plugin not verified"} return {"error": "Plugin not verified"}
# Call the function with provided parameters # Call the function with provided parameters
try: try:
result = plugin_function(params, authentication) result = plugin_function(params, authentication)
@ -144,14 +139,17 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
return {"error": str(e)} return {"error": str(e)}
# return plugin.runFunction(function, params, authentication) # return plugin.runFunction(function, params, authentication)
def getPluginFunctionInputs(plugin: str, function: str): def getPluginFunctionInputs(plugin: str, function: str):
plugin = importlib.import_module("plugins."+plugin) plugin = importlib.import_module("plugins."+plugin)
return plugin.functions[function]["params"] return plugin.functions[function]["params"]
def getPluginFunctionReturns(plugin: str, function: str): def getPluginFunctionReturns(plugin: str, function: str):
plugin = importlib.import_module("plugins."+plugin) plugin = importlib.import_module("plugins."+plugin)
return plugin.functions[function]["returns"] return plugin.functions[function]["returns"]
def getDomainFunctions(): def getDomainFunctions():
plugins = listPlugins() plugins = listPlugins()
domainFunctions = [] domainFunctions = []
@ -166,6 +164,7 @@ def getDomainFunctions():
}) })
return domainFunctions return domainFunctions
def getSearchFunctions(): def getSearchFunctions():
plugins = listPlugins() plugins = listPlugins()
searchFunctions = [] searchFunctions = []
@ -180,6 +179,7 @@ def getSearchFunctions():
}) })
return searchFunctions return searchFunctions
def getDashboardFunctions(): def getDashboardFunctions():
plugins = listPlugins() plugins = listPlugins()
dashboardFunctions = [] dashboardFunctions = []
@ -192,4 +192,4 @@ def getDashboardFunctions():
"function": function, "function": function,
"description": functions[function]["description"] "description": functions[function]["description"]
}) })
return dashboardFunctions return dashboardFunctions