Skip to content

Commit

Permalink
feature: add new plugin loading method
Browse files Browse the repository at this point in the history
  • Loading branch information
jerlendds committed Jul 30, 2023
1 parent f5ed5d2 commit 2fbc920
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

selenium>=4.9.0
pydantic>=1.10.8
httpx>=0.24.1
httpx>=0.23.3
SQLAlchemy>=2.0.12
gremlinpy @ git+https://github.com/jerlendds/gremlinpy.git@7d3033e6a55ed9cb1f982ec3b58ca233e01c58e3
4 changes: 3 additions & 1 deletion src/osintbuddy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
OBPlugin as Plugin,
OBAuthorUse as PluginUse,
discover_plugins,
transform
transform,
load_plugin,
load_plugins
)

__version__ = "0.0.4"
4 changes: 0 additions & 4 deletions src/osintbuddy/entities/INDEX.md

This file was deleted.

59 changes: 51 additions & 8 deletions src/osintbuddy/plugins.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import os
import importlib
import os, imp, importlib, sys
from typing import List, Any, Callable
from collections import defaultdict
from pydantic import create_model, BaseModel
import undetected_chromedriver as uc
# from osintbuddy.utils import slugify
from osintbuddy.elements.base import BaseElement
from osintbuddy.errors import OBPluginError
from osintbuddy.utils import to_snake_case

def driver() -> uc.Chrome:
pass

# @todo add permission system and display what parts of system plugin can access
class OBAuthorUse(BaseModel):
get_driver: Callable[[], uc.Chrome]
get_graph: Callable[[], None] # @todo
# @todo
get_driver: Callable[[], None]
get_graph: Callable[[], None]


class OBRegistry(type):
Expand Down Expand Up @@ -57,8 +54,54 @@ async def get_plugin(cls, plugin_label: str):
return cls.plugins[idx]
return None

@classmethod
def get_plug(cls, plugin_label: str):
"""
Returns the corresponding plugin class for a given plugin_label or
'None' if not found.
:param plugin_label: The label of the plugin to be returned.
:return: The plugin class or None if not found.
"""
for idx, label in enumerate(cls.labels):
if to_snake_case(label) == to_snake_case(plugin_label):
return cls.plugins[idx]
return None

def __getitem__(self, i):
return self.get_plugin[i]
return self.get_plug[i]

# https://stackoverflow.com/a/7548190
def load_plugin(
mod_name: str,
plugin_code: str,
):
"""
Load plugins from a string of code
:param module_name: The desired module name of the plugin.
:param plugin_code: The code of the plugin.
:return:
"""
new_mod = imp.new_module(mod_name)
exec(plugin_code, new_mod.__dict__)
return OBRegistry.plugins


def load_plugins(
entities: list
):
"""
Loads plugins from the osintbuddy db
:param entities: list of entities from the db
:return:
"""
for entity in entities:
mod_name = to_snake_case(entity.label)
new_mod = imp.new_module(mod_name)
exec(entity.source, new_mod.__dict__)
return OBRegistry.plugins


def discover_plugins(
Expand Down

0 comments on commit 2fbc920

Please sign in to comment.