Skip to content

Commit

Permalink
feature: add plugin authors and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jerlendds committed Jul 19, 2023
1 parent 3481b1e commit e9ac737
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/osintbuddy/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def __init__(cls, name, bases, attrs):
if name != 'OBPlugin' and name != 'Plugin' and issubclass(cls, OBPlugin):
label = cls.label.strip()
if cls.show_label is True:
OBRegistry.ui_labels.append(label)
if isinstance(cls.author, list):
cls.author = ', '.join(cls.author)
OBRegistry.ui_labels.append({
'label': label,
'description': cls.description,
'author': cls.author
})
else:
OBRegistry.ui_labels.append(None)
OBRegistry.labels.append(label)
Expand Down Expand Up @@ -81,7 +87,7 @@ def discover_plugins(
return OBRegistry.plugins


def transform(label, icon='list', prompt=None, edge_label='transformed_to'):
def transform(label, icon='list', edge_label='transformed_to'):
"""
A decorator add transforms to an osintbuddy plugin.
Expand All @@ -96,15 +102,12 @@ def transform_to_ip(self, node, **kwargs):
displayed by the transform label. Default is "list".
:return: A decorator for the plugin transform method.
"""
def decorator_transform(func):
def decorator_transform(func, edge_label=edge_label):
async def wrapper(self, node, **kwargs):
return await func(self=self, node=node, **kwargs)
wrapper.label = label
wrapper.icon = icon
wrapper.edge_label = edge_label
if prompt is not None:
wrapper.prompt = prompt

return wrapper
return decorator_transform

Expand All @@ -121,13 +124,19 @@ class OBPlugin(object, metaclass=OBRegistry):
show_label = True
style: dict = {}

author = 'Unknown'
description = 'No description.'

def __init__(self):
transforms = self.__class__.__dict__.values()
self.transforms = {
to_snake_case(func.label): func for func in transforms if hasattr(func, 'label')
}
self.transform_labels = [
{'label': func.label, 'icon': func.icon} for func in transforms
{
'label': func.label,
'icon': func.icon,
} for func in transforms
if hasattr(func, 'icon') and hasattr(func, 'label')
]

Expand Down
2 changes: 1 addition & 1 deletion src/osintbuddy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_camel_case(value: str):


def to_snake_case(name):
name = to_camel_case(name)
name = to_camel_case(name.replace('-', '_'))
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
name = re.sub('__([A-Z])', r'_\1', name)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name)
Expand Down

0 comments on commit e9ac737

Please sign in to comment.