TheHive4py
TheHive4py copied to clipboard
File handle remains open
Problem Description
When creating a file observable the file object remains open, file cannot be deleted.
Steps to Reproduce
- Create CaseObservable with type 'file'
- Push this observable to TH (TheHiveApi.create_case_observable)
- delete file => error, file is used by another process
The CaseObservable opens the file named by the caller, and saves the open file within its self.data. This file object is later passed to requests.post by TheHiveApi.create_case_observable, so it has to stay open till after that. To close it there, in a different scope from where it was opened, would be unwise.
(Incidentally it looks like create_task_log also opens a file without closing it. That could be more easily fixed than this, by putting a with statement there. This should probably be filed as its own issue, and perhaps I'll get around to that, but this text box is before me in tgis moment, so here I type.)
#35 asks for the capability to send in a file-like object in one place in the API. If every caller had to do that, everywhere in this API, even when passing in real files, they'd be responsible both for opening and closing their file, and they could easily do so using a with statement. But that would be a breaking change and it isn't my call.
We are closing this issue as it pertains to the 1.x version of thehive4py, which is no longer supported. We recommend upgrading to the latest release for continued support or issue resolution. Thank you for your understanding!