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 s3 disk validation step #22

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

lehecht
Copy link
Contributor

@lehecht lehecht commented Feb 6, 2025

  • Update Tests
  • Update assets

Closes #4.

@lehecht
Copy link
Contributor Author

lehecht commented Feb 6, 2025

@mzur
Could you give some feedback on my validation method?
I had to use Storage::build() instead of Storage::disk()because disk() makes the update method unnecessarily complex. With disk(), I would need to use DB::transaction() to first save the updated fields, then validating them and maybe rolling everything back if there is an error. Relying solely on the request wasn’t an option because disk() uses the disk from the database, which hadn’t been updated, yet.

@mzur
Copy link
Member

mzur commented Feb 6, 2025

I think using a database transaction for this would be quite elegant! Then you can use disk() too, which should work with other types than S3 in the future.

I would advise against using allFiles() to check the disk. If there are a lot of files, the memory limit could be reached. I recently had a case where a user had 100k files and it crashed. I implemented a more efficient check for content that you could use here, too. I would not throw en error if the disk is empty, though. Maybe users want to prepare the disk before they upload data to it. Use the test only to check for configuration errors.

@mzur
Copy link
Member

mzur commented Feb 6, 2025

It just came to my mind: You can probably use the VolumeUrl validation rule directly here. No need to duplicate code (unless it prevents you from showing a helpful error message).

@lehecht
Copy link
Contributor Author

lehecht commented Feb 7, 2025

@mzur
The code you mentioned is located in passesDiskUrl(), but when I use VolumeUrl with the disk endpoint, it uses passesRemoteUrl().
After duplicating the code, I no longer get an error if the endpoint URL is incorrect; instead, it just returns an empty list.

@lehecht
Copy link
Contributor Author

lehecht commented Feb 7, 2025

I found that an exception is only thrown if the host url is incorrect. If the bucket name is missing or wrong, it just returns an empty list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add validation of new storage disks
2 participants