mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(s3): name the key and version in NoSuchVersion errors (#7155)
* fix(s3): name the key and version in NoSuchVersion errors Every NoSuchVersion error names the key and the version id, and an annotation request for a missing version answers NoSuchVersion instead of NoSuchKey, as on S3. * test(s3): check annotation put and delete and a missing key for NoSuchVersion
This commit is contained in:
1 parent
c865784540
commit
48b19f76f3
5 files changed
+74
-16
No files matched your search
@@ -3752,11 +3752,12 @@ public class S3Controller {
|
||||
// S3 InvalidArgument responses carry ArgumentName and ArgumentValue so the SDK can
|
||||
// surface which input was rejected, and EntityTooSmall and EntityTooLarge the proposed and
|
||||
// allowed sizes. Multipart size errors also identify the rejected part, MethodNotAllowed
|
||||
// the method and the kind of resource that refused it, and NoSuchKey the key.
|
||||
// the method and the kind of resource that refused it, and NoSuchKey and NoSuchVersion
|
||||
// the key and version that are missing.
|
||||
// They travel through AwsException.extendedData.
|
||||
if (e.getExtendedData() != null) {
|
||||
for (String field : List.of("Key", "Method", "ResourceType", "ProposedSize", "MinSizeAllowed",
|
||||
"MaxSizeAllowed", "PartNumber", "ETag")) {
|
||||
for (String field : List.of("Key", "VersionId", "Method", "ResourceType", "ProposedSize",
|
||||
"MinSizeAllowed", "MaxSizeAllowed", "PartNumber", "ETag")) {
|
||||
Object value = e.getExtendedData().get(field);
|
||||
if (value != null) {
|
||||
xmlBuilder.elem(field, value.toString());
|
||||
|
||||
@@ -1923,8 +1923,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String accountId = ownedBucket.account();
|
||||
for (int attempt = 0; attempt < 10_000; attempt++) {
|
||||
StoredVersion stored = findStoredVersionForAccount(accountId, bucketName, key, "null")
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"NoSuchVersion", "The specified version does not exist.", 404));
|
||||
.orElseThrow(() -> noSuchVersion(key, "null"));
|
||||
if (stored.object().isDeleteMarker()) {
|
||||
throw new S3DeleteMarkerException(stored.object());
|
||||
}
|
||||
@@ -2221,9 +2220,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
"The specified bucket does not exist.", 404));
|
||||
|
||||
S3Object object = findStoredObject(ownedBucket, bucketName, key, versionId)
|
||||
.orElseThrow(() -> versionId != null
|
||||
? new AwsException("NoSuchVersion", "The specified version does not exist.", 404)
|
||||
: noSuchKey(key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(key, versionId) : noSuchKey(key));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw new S3DeleteMarkerException(object);
|
||||
}
|
||||
@@ -2234,6 +2231,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
return new AwsException("NoSuchKey", "The specified key does not exist.", 404, Map.of("Key", key));
|
||||
}
|
||||
|
||||
private static AwsException noSuchVersion(String key, String versionId) {
|
||||
return new AwsException("NoSuchVersion", "The specified version does not exist.", 404,
|
||||
Map.of("Key", key, "VersionId", versionId));
|
||||
}
|
||||
|
||||
/** The stored version {@code versionId} names, the current one when it is null, delete markers included. */
|
||||
private Optional<S3Object> findStoredObject(AccountAwareStorageBackend.OwnedEntry<Bucket> ownedBucket,
|
||||
String bucketName, String key, String versionId) {
|
||||
@@ -3372,12 +3374,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
AccountAwareStorageBackend.OwnedEntry<Bucket> ownedBucket = resolveBucketEntry(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket",
|
||||
"The specified bucket does not exist.", 404));
|
||||
// GetObjectTagging names the key with its bucket.
|
||||
String namedKey = "GET".equals(method) ? bucketName + "/" + key : key;
|
||||
S3Object object = findStoredVersionForAccount(ownedBucket.account(), bucketName, key, versionId)
|
||||
.map(StoredVersion::object)
|
||||
.orElseThrow(() -> versionId != null
|
||||
? new AwsException("NoSuchVersion", "The specified version does not exist.", 404)
|
||||
// GetObjectTagging names the key with its bucket.
|
||||
: noSuchKey("GET".equals(method) ? bucketName + "/" + key : key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(namedKey, versionId) : noSuchKey(namedKey));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw new AwsException("MethodNotAllowed",
|
||||
"The specified method is not allowed against this resource.", 405,
|
||||
@@ -3629,7 +3630,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
private S3Object resolveParentObject(String bucketName, String key, String versionId) {
|
||||
S3Object object = findStoredVersion(bucketName, key, versionId)
|
||||
.map(StoredVersion::object)
|
||||
.orElseThrow(() -> noSuchKey(key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(key, versionId) : noSuchKey(key));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw noSuchKey(key);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user