Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download an attachment from an observable #266

Merged

Conversation

mike1796
Copy link
Contributor

Add a method to download an attachment from the observableendpoint class and be able to retrieve a file from an observable's id. The download can also be done with a zip and the parameter as_zip.

@Kamforka Kamforka self-requested a review December 15, 2022 18:59
@Kamforka Kamforka added this to the 2.0.0b4 milestone Dec 15, 2022
@Kamforka Kamforka added the 2.x label Dec 15, 2022
@Kamforka
Copy link
Collaborator

Thanks for the review, gonna review tomorrow!

@Kamforka
Copy link
Collaborator

Could you please rebase it to the latest develop branch to kick in the ci pipeline?

Add a method to download an attachment from the observableendpoint class and be able to retrieve a file from a given observable.
The download can also be done with a zip and the parameter as_zip.
Renaming of the variable attachment_path to observable_path to be better align with the existing name conventions.
@mike1796 mike1796 force-pushed the download-observable-attachment branch from 0f7bd56 to 7e5e54b Compare December 21, 2022 12:41
@mike1796
Copy link
Contributor Author

Could you please rebase it to the latest develop branch to kick in the ci pipeline?

Just rebase to the latest develop branch and fix mistakes and double commit that was there just before

@mike1796 mike1796 requested a review from Kamforka December 21, 2022 12:47
@Kamforka
Copy link
Collaborator

Kamforka commented Jan 3, 2023

Could you please rebase it to the latest develop branch to kick in the ci pipeline?

Just rebase to the latest develop branch and fix mistakes and double commit that was there just before

The rebase seems to be good, can you please fix the ci check issues, then we can merge the change.

Reindent code in order to have lines that have less than 88 characters in order to pass the CI check
@mike1796
Copy link
Contributor Author

mike1796 commented Jan 5, 2023

Both lint issues have been fixed in the last commit.

@Kamforka
Copy link
Collaborator

Kamforka commented Jan 5, 2023

Both lint issues have been fixed in the last commit.

Hey Mike,
I can still see some issues, please verify locally:

flake8 thehive4py/ tests/
black --diff thehive4py/ tests/

Remove space and add a double quote in order to fix flake8 and validate CI
@Kamforka
Copy link
Collaborator

I still have an issue when I set as_zip=False I get back a 500 internal server error which seems like a bug.
Although the endpoint works fine with as_zip=True so I'd suggest to hardcode the params={"asZip": True} query and remove the as_zip argument from the method as a temporary quickfix.

Also please add the above observation as an explanation comment in the method's body.

@mike1796
Copy link
Contributor Author

mike1796 commented Jan 12, 2023

I still have an issue when I set as_zip=False I get back a 500 internal server error which seems like a bug. Although the endpoint works fine with as_zip=True so I'd suggest to hardcode the params={"asZip": True} query and remove the as_zip argument from the method as a temporary quickfix.

Also please add the above observation as an explanation comment in the method's body.

Can you give me your version number of theHive and some of your test ?
For me it works perfectly fine in theHive 5.0.18, I just retried it and don't get any 500 errors.
I also tried on a jpg file.

My test look like this :

thehive = TheHiveApi(thehive_url, api_key)
fetched_observable = thehive.observable.get(observable_id="~44499104")
thehive.observable.download_attachment("~44499104", fetched_observable.get("attachment").get("_id"), "test.jpg", True)

Or

thehive = TheHiveApi(thehive_url, api_key)
fetched_observable = thehive.observable.get(observable_id="~44499104")
thehive.observable.download_attachment("~44499104", fetched_observable.get("attachment").get("_id"), "test.jpg", False)

@Kamforka
Copy link
Collaborator

Kamforka commented Jan 12, 2023

I still have an issue when I set as_zip=False I get back a 500 internal server error which seems like a bug. Although the endpoint works fine with as_zip=True so I'd suggest to hardcode the params={"asZip": True} query and remove the as_zip argument from the method as a temporary quickfix.
Also please add the above observation as an explanation comment in the method's body.

Can you give me your version number of theHive and some of your test ? For me it works perfectly fine in theHive 5.0.18, I just retried it and don't get any 500 errors. I also tried on a jpg file.

My test look like this :

thehive = TheHiveApi(thehive_url, api_key)
fetched_observable = thehive.observable.get(observable_id="~44499104")
thehive.observable.download_attachment("~44499104", fetched_observable.get("attachment").get("_id"), "test.jpg", True)

Or

thehive = TheHiveApi(thehive_url, api_key)
fetched_observable = thehive.observable.get(observable_id="~44499104")
thehive.observable.download_attachment("~44499104", fetched_observable.get("attachment").get("_id"), "test.jpg", False)

I tried it on 5.0.23, maybe it's a bug in the newer versions then. I raised an issue with the core dev team, let's wait for them while they verify and fix.

@Kamforka Kamforka closed this Jan 12, 2023
@Kamforka Kamforka reopened this Jan 12, 2023
@Kamforka Kamforka merged commit bc605a3 into TheHive-Project:develop Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants