biigle / user-disks

:m: BIIGLE module to offer private storage disks for users
GNU General Public License v3.0
0 stars 0 forks source link

Add validation of new storage disks #4

Open mzur opened 1 year ago

mzur commented 1 year ago

We had an error Unable to list contents for an S3 disk. Maybe there was a typo in the URL. We should add a validation with a "list contents" call to check if any files can be listed with a new storage disk. If not, throw a vaildation error.

mzur commented 1 year ago

The validation could be done with the created user disk here:

https://github.com/biigle/user-disks/blob/0b425ef618a4f8525a39b9dec7652f369558ef5b/src/Http/Controllers/Api/UserDiskController.php#L45

and here:

https://github.com/biigle/user-disks/blob/0b425ef618a4f8525a39b9dec7652f369558ef5b/src/Http/Controllers/Api/UserDiskController.php#L87

If the validation failed, the changes should be reverted.

The validation can probably only be done after the disk is created because it needs an ID to create the "temporary storage disk", so the validation cannot be done in the form request classes.

mzur commented 10 months ago

There was this error with an incorrectly entered endpoint URL (missing the bucket name):

"message" => """
    Unable to list contents for '', shallow listing
Reason: Error executing "ListObjectsV2" on "https://s3.us-east-005.backblazeb2.com/?list-type=2&prefix=&delimiter=%2F"; AWS HTTP error: Client error: `GET https ▶
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Error>
        <Code>AccessDenied</Code>
        <Message>not entitled< (truncated...)
     AccessDenied (client): not entitled - <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Error>
        <Code>AccessDenied</Code>
        <Message>not entitled</Message>
    </Error>
    """
  "context" => array:2 [▼
    "userId" => xxx
    "exception" => array:6 [▶]
  ]
  "level" => 400
  "level_name" => "ERROR"
  "channel" => "production"
  "datetime" => "2023-09-06T19:26:08.359622+02:00"
  "extra" => []

Errors like these should produce a meaningful error message to the user, too (e.g. "access denied" in this case).