-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: doesObjectExist and doesBucketExist v2 #2424
Conversation
src/S3/S3ClientTrait.php
Outdated
$this->execute($command); | ||
return true; | ||
} catch (S3Exception $e) { | ||
if (($accept403 && $e->getStatusCode() === 403) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be a newline after the first parenthesis
src/S3/S3ClientTrait.php
Outdated
$response = $e->getResponse(); | ||
|
||
if ($includeDeleteMarkers | ||
&& (!empty($response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract this into a hasDeleteMarker method that checks if a response exists and returns whether or not that header is there? Condense a a bit of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totally agree. just took a second glance and that looks pretty ugly
Issue #, if available:
Implements #1561, closes #2342
Description of changes:
New object/bucket existence helper methods with changed exception handling behavior. Previously,
false
was returned any time an exception was thrown by the underlying S3 APIs (headObject
andheadBucket
) unless the exception's status code was >=500
(then exception was thrown) or the exception's error code wasAccessDenied
(true
was returned). This was problematic becausefalse
could be returned in the cases of an unresolvable endpoint, expired credentials, invalid credentials, or if bucket permissions were not granted to the calling entity and resources did in fact exist.This implementation makes fewer assumptions in cases where status codes are ambiguous, namely
403
status codes. a403
status code can signify bad credentials or incorrect bucket-level permissions— this causes issues withheadObject
/doesObjectExist
calls in particular because a 403 will be returned whether or not an object exists. In this implementation, exceptions will be thrown in all cases when an exception is thrown by the underlying API, unless the exception has a404
status code (returns false) or in the case ofDoesBucketExist
, a user can specify if they want to accept403
status codes, as a 403 will be thrown if a bucket exists, but an entity doesn't have correct bucket-level permissions.Other changes include accepting bucket redirects (incorrectly specified region) as a
true
case forDoesBucketExist
, the$accept403
flag fordoesBucketExist
and the$includeDeleteMarkers
flag fordoesObjectExist
, which counts a404
response with the presence of a delete marker header as atrue
case.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.