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

Add post endpoint for attachments #11 #12

Merged
merged 25 commits into from
Oct 2, 2024
Merged

Conversation

joelvdavies
Copy link
Collaborator

@joelvdavies joelvdavies commented Sep 20, 2024

Description

Adds an endpoint /attachments for creating new attachments.

Notes

  • Creates the pre-signed url before the database insert to avoid needing transactions
  • For the post response I had to create the response schema in the service layer rather than routers as is typically done in IMS
  • I have attempted to implement a different style of error handling on the InvalidObjectId errors, although these are the trickiest to do and has resulted in the need for re-raising an error anyway. There might be a way to modify the validator to include the field_name in the exception rather than having to do this. I attempted it but could not get it to work at the time.
  • We may wish to have another repo at some point with the following (copied from IMS and slightly modified due to slightly different error handling) - would probably have complications around versioning of that repo, but can be done with https://stackoverflow.com/questions/73274808/add-private-github-repo-to-pyproject-toml-as-new-dependency with tags)
    • core/custom_object_id.py
    • some of core/exceptions.py
    • models/custom_object_id_data_types.py
    • test/unit/core/test_custom_object.py
    • models/mixins.py
    • schemas/mixins.py
    • Any other future duplicate code - the auth middleware for example
  • Only empty buckets may be deleted, also if a bucket is already in existence it will error on creation (like when a previous test run failed) so while I was initially going to get the e2e tests to create & delete the bucket, I have resorted to emptying its contents instead
  • MinIO now uses host networking as avoids having to replace the docker hostname in presigned URLs to localhost in e2e tests

Testing instructions

Add a set up instructions describing how the reviewer should test the code

  • Review code
  • Check Actions build
  • Review changes to test coverage

Agile board tracking

Closes #11

@joelvdavies joelvdavies added the enhancement New feature or request label Sep 20, 2024
@joelvdavies joelvdavies self-assigned this Sep 20, 2024
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 3008389 to 4535f0c Compare September 20, 2024 13:50
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 4535f0c to 3e4c409 Compare September 20, 2024 13:52
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from c04870b to a6bf857 Compare September 20, 2024 15:11
Base automatically changed from setup-monogo-db-and-s3-clients-#4 to develop September 23, 2024 13:38
@joelvdavies
Copy link
Collaborator Author

@VKTB The core functionality is done, I will look at the tests next. Feel free to have a look - especially at the error handling.

@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch 2 times, most recently from f6be5f5 to 7d7433b Compare September 24, 2024 12:39
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 7d7433b to 98f3e41 Compare September 24, 2024 12:46
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch 2 times, most recently from e78fd7e to e31b832 Compare September 25, 2024 10:04
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch 5 times, most recently from 8738ad3 to b0d0c0c Compare September 25, 2024 10:30
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch 2 times, most recently from 31ac96b to 544107d Compare September 26, 2024 08:20
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 544107d to e715eb7 Compare September 26, 2024 08:23
@joelvdavies joelvdavies requested a review from VKTB September 26, 2024 09:05
@joelvdavies joelvdavies marked this pull request as ready for review September 26, 2024 09:05
Copy link
Collaborator

@VKTB VKTB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments from me. Not sure if you want to keep the TODOs in or remove them, I will leave it to you to decide.

object_storage_api/.env.example Outdated Show resolved Hide resolved
object_storage_api/models/attachment.py Show resolved Hide resolved
object_storage_api/repositories/attachment.py Outdated Show resolved Hide resolved
object_storage_api/stores/attachment.py Outdated Show resolved Hide resolved
test/e2e/conftest.py Outdated Show resolved Hide resolved
object_storage_api/core/config.py Outdated Show resolved Hide resolved
test/pytest.ini Outdated Show resolved Hide resolved
AttachmentServiceDep = Annotated[AttachmentService, Depends(AttachmentService)]


@router.post(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should ask ourselves here if it is clear enough that this endpoint (given its prefix and path) is used for getting a pre-signed URL rather than posting an actual attachment. It might help if we look from a perspective of how this router would look like if we also had another endpoint that allows for posting of actual attachments - i.e. how the endpoints would differ.

Copy link
Collaborator Author

@joelvdavies joelvdavies Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point. I would think

  • /attachments for upload of metadata and data
  • /attachments/metadata for submitting just the metadata about the attachment

We can also argue the same issue for GETs, we will not be downloading an attachment, only its metadata. There I would end up with

  • /attachments/metadata for listing all attachment metadata
  • /attachments/metadata/<id> for getting the information about an individual one (potentially with a presigned url?)

But I am not sure on that second point, nothing about it screams 'will return a presigned download url'. Equally I don't like /attachments/<id>/download as again its not downloading its just getting a presigned url. This would allow for an upload one if the initial upload failed some how (not something I think we need to worry about now though).

We could also have /download-url or something, but the upload doesn't make sense there. So I'm not sure there are any nice all round solutions unless you have any suggestions?

Right now I am essentially considering the attachment to be created when the metadata of it is posted, and I would expect it to be created when posting to /attachments.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you have any suggestions?

I am not sure I do at this point, especially given your thoughts on this. I might do further down the line, I will let you know. Probably merge it as it is for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will make an issue to look at it again a bit later, the endpoints should be easy to change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#23

@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 27374cd to 2064e4d Compare September 30, 2024 15:29
@joelvdavies joelvdavies force-pushed the add-attachment-post-#11 branch from 2064e4d to 88ce418 Compare September 30, 2024 15:31
@joelvdavies joelvdavies requested a review from VKTB September 30, 2024 15:33
@joelvdavies joelvdavies merged commit 865016b into develop Oct 2, 2024
3 checks passed
@joelvdavies joelvdavies deleted the add-attachment-post-#11 branch October 2, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an endpoint for creating attachments
2 participants