detect-secrets icon indicating copy to clipboard operation
detect-secrets copied to clipboard

No proper documentation regarding the plugin and context variable in filters

Open HelloGit-ty opened this issue 3 years ago • 2 comments

Hey, it's not exactly a code issue but more of a info lack. So I'm making a custom filter with ML and keyword match to reduce FPs since I'm using a low base64 entropy value (3.0).

Now I need the name of the plugin which finds the secret so I'm using the plugin variable and the documentation is really lacking in that area. It took me a day to scour the code and understand exactly how to use it. But it seems I'm still misunderstanding something. Can you help me out with how I can get the plugin name in my filter function in string format?

PS - I tried plugin.secret_type and as far as the base plugin code it looks like that function should return a string but my filter is not working as expected. What am I doing wrong? Thank you for your time and lemme know if more detail is needed.

HelloGit-ty avatar Aug 25 '22 21:08 HelloGit-ty

@HelloGit-ty

Can you help me out with how I can get the plugin name in my filter function in string format?

You just need to declare the needed variables in the filter arguments and it'll be available (refs). FWIU, you're on the right track and might just be missing some minor details. (pluging.secret_type is the correct variable to get the filter's class name)

Please see below sample.

~/git/detect-secrets (master)$ cat detect_secrets/filters/custom_filter.py
from typing import Optional

from detect_secrets.plugins.base import BasePlugin

def test_custom_filter2(secret: str, line: str, filename: str, plugin: Optional[BasePlugin] = None) -> bool:
    print("---- custom filter 2 ---- " + plugin.secret_type + "  filename : "+ filename)
    print(plugin)
    raise Exception('test custom filter 2') # force-stop; ToDo remove

def test_custom_filter(secret: str, line: str, plugin: Optional[BasePlugin] = None) -> bool:
    print("---- custom filter ---- " + plugin.secret_type)
    raise Exception('test custom filter') # force-stop; ToDo remove

~/git/detect-secrets (master)$ python -m detect_secrets scan --filter detect_secrets.filters.custom_filter.test_custom_filter

If above doesn't solve your issue, feel free to share your custom filter and we'll take a look.

Chandra158 avatar Oct 05 '22 18:10 Chandra158

Will give this a try and let you know. Thank you!

HelloGit-ty avatar Oct 05 '22 18:10 HelloGit-ty

We're going to close this issue as it hasn't received any update in a very long time. Feel free to re-open it if you think it's still relevant.

lorenzodb1 avatar May 16 '24 17:05 lorenzodb1