-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1316 from adobe/1215-add-listobjectversions
Add ListObjectVersions API
- Loading branch information
Showing
9 changed files
with
447 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/ListObjectVersionsV2IT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2017-2023 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.its | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.groups.Tuple | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInfo | ||
import software.amazon.awssdk.core.sync.RequestBody | ||
import software.amazon.awssdk.services.s3.model.ChecksumAlgorithm | ||
import software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest | ||
import software.amazon.awssdk.services.s3.model.ObjectVersion | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest | ||
import java.io.File | ||
|
||
internal class ListObjectVersionsV2IT : S3TestBase() { | ||
|
||
@Test | ||
fun testPutObjects_listObjectVersions(testInfo: TestInfo) { | ||
val uploadFile = File(UPLOAD_FILE_NAME) | ||
val bucketName = givenBucketV2(testInfo) | ||
|
||
s3ClientV2.putObject( | ||
PutObjectRequest.builder() | ||
.bucket(bucketName).key("$UPLOAD_FILE_NAME-1") | ||
.checksumAlgorithm(ChecksumAlgorithm.SHA256) | ||
.build(), | ||
RequestBody.fromFile(uploadFile) | ||
) | ||
|
||
s3ClientV2.putObject( | ||
PutObjectRequest.builder() | ||
.bucket(bucketName).key("$UPLOAD_FILE_NAME-2") | ||
.checksumAlgorithm(ChecksumAlgorithm.SHA256) | ||
.build(), | ||
RequestBody.fromFile(uploadFile) | ||
) | ||
|
||
val listObjectVersionsResponse = s3ClientV2.listObjectVersions( | ||
ListObjectVersionsRequest.builder() | ||
.bucket(bucketName) | ||
.build() | ||
) | ||
|
||
assertThat(listObjectVersionsResponse.versions()) | ||
.hasSize(2) | ||
.extracting(ObjectVersion::checksumAlgorithm) | ||
.containsOnly( | ||
Tuple(arrayListOf(ChecksumAlgorithm.SHA256)), | ||
Tuple(arrayListOf(ChecksumAlgorithm.SHA256)) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/src/main/java/com/adobe/testing/s3mock/dto/DeleteMarkerEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2017-2023 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteMarkerEntry.html">API Reference</a>. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record DeleteMarkerEntry( | ||
@JsonProperty("IsLatest") | ||
Boolean isLatest, | ||
@JsonProperty("Key") | ||
String key, | ||
@JsonProperty("LastModified") | ||
String lastModified, | ||
@JsonProperty("Owner") | ||
Owner owner, | ||
@JsonProperty("VersionId") | ||
String versionId | ||
) { | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
server/src/main/java/com/adobe/testing/s3mock/dto/ListVersionsResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2017-2023 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonRootName; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents a result of listing object versions that reside in a Bucket. | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectVersions.html">API Reference</a> | ||
*/ | ||
@JsonRootName("ListBucketResult") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record ListVersionsResult( | ||
@JsonProperty("Name") | ||
String name, | ||
@JsonProperty("Prefix") | ||
String prefix, | ||
@JsonProperty("MaxKeys") | ||
int maxKeys, | ||
@JsonProperty("IsTruncated") | ||
boolean isTruncated, | ||
@JsonProperty("CommonPrefixes") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
List<Prefix> commonPrefixes, | ||
@JsonProperty("Delimiter") | ||
String delimiter, | ||
@JsonProperty("EncodingType") | ||
String encodingType, | ||
@JsonProperty("KeyMarker") | ||
String keyMarker, | ||
@JsonProperty("VersionIdMarker") | ||
String versionIdMarker, | ||
@JsonProperty("NextKeyMarker") | ||
String nextKeyMarker, | ||
@JsonProperty("NextVersionIdMarker") | ||
String nextVersionIdMarker, | ||
@JsonProperty("Version") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
List<ObjectVersion> objectVersions, | ||
@JsonProperty("DeleteMarker") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
List<DeleteMarkerEntry> deleteMarkers | ||
|
||
) { | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
server/src/main/java/com/adobe/testing/s3mock/dto/ObjectVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2017-2023 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import static com.adobe.testing.s3mock.util.EtagUtil.normalizeEtag; | ||
|
||
import com.adobe.testing.s3mock.store.S3ObjectMetadata; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_ObjectVersion.html">API Reference</a>. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record ObjectVersion( | ||
@JsonProperty("Key") | ||
String key, | ||
@JsonProperty("LastModified") | ||
String lastModified, | ||
@JsonProperty("ETag") | ||
String etag, | ||
@JsonProperty("Size") | ||
String size, | ||
@JsonProperty("StorageClass") | ||
StorageClass storageClass, | ||
@JsonProperty("Owner") | ||
Owner owner, | ||
@JsonProperty("ChecksumAlgorithm") | ||
ChecksumAlgorithm checksumAlgorithm, | ||
@JsonProperty("IsLatest") | ||
Boolean isLatest, | ||
@JsonProperty("VersionId") | ||
String versionId | ||
) { | ||
|
||
public ObjectVersion { | ||
etag = normalizeEtag(etag); | ||
} | ||
|
||
public static ObjectVersion from(S3ObjectMetadata s3ObjectMetadata) { | ||
return new ObjectVersion(s3ObjectMetadata.key(), | ||
s3ObjectMetadata.modificationDate(), s3ObjectMetadata.etag(), | ||
s3ObjectMetadata.size(), StorageClass.STANDARD, Owner.DEFAULT_OWNER, | ||
s3ObjectMetadata.checksumAlgorithm(), true, "staticVersion"); | ||
} | ||
|
||
public static ObjectVersion from(S3Object s3Object) { | ||
return new ObjectVersion(s3Object.key(), | ||
s3Object.lastModified(), s3Object.etag(), | ||
s3Object.size(), StorageClass.STANDARD, Owner.DEFAULT_OWNER, | ||
s3Object.checksumAlgorithm(), true, "staticVersion"); | ||
} | ||
} |
Oops, something went wrong.