OpenCTI-Platform / client-python

OpenCTI Python Client
https://www.opencti.io
Apache License 2.0
117 stars 130 forks source link

Consider removing/relaxing dependency of libmagic #547

Open mahmut-the-guy opened 9 months ago

mahmut-the-guy commented 9 months ago

Problem to Solve

Currently, I don't use any file uploading logic in the platform and installing libmagic1 is a burden.

Currently there 7 use cases for magic and 6 of them uses filename to figure out the mime type. I think these cases be handled by following functionality from standard library:

https://docs.python.org/3/library/mimetypes.html#mimetypes.guess_type

The remaining case that uses the actual file buffer is not even a part of core library and found in examples:

https://github.com/OpenCTI-Platform/client-python/blob/c9787572d33dbd3ccf073d988d10181d65bb6787/examples/upload_artifacts.py#L54

Current Workaround

You need to install libmagic1 and relevant Python dependency. I could not find a way to get around this.

Proposed Solution

Remove magic dependency by using guess_type instead from stdlib.

If we really need magic for any reason, I propose making the dependency optional so those who don't do any file operations don't have to install it.

mahmut-the-guy commented 9 months ago

@SamuelHassine what do you think about this? I could draft a PR if it sounds feasible.