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 versioning support in listObjects API #984

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ functional/.classpath
functional/.project
functional/.settings/
functional/bin/
functional/d1/
functional/.d*/
minio
!minio/
minio.exe
Expand Down
20 changes: 19 additions & 1 deletion api/src/main/java/io/minio/GenericResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,30 @@
/** Generic response class of any APIs. */
public abstract class GenericResponse {
private Headers headers;
private String bucket;
private String region;
private String object;

protected void setHeaders(Headers headers) {
public GenericResponse(Headers headers, String bucket, String region, String object) {
this.headers = headers;
this.bucket = bucket;
this.region = region;
this.object = object;
}

public Headers headers() {
return headers;
}

public String bucket() {
return bucket;
}

public String region() {
return region;
}

public String object() {
return object;
}
}
139 changes: 108 additions & 31 deletions api/src/main/java/io/minio/ListObjectsArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,77 @@

/** Argument class of @see #listObjects(ListObjectsArgs args). */
public class ListObjectsArgs extends BucketArgs {
private String continuationToken;
private String delimiter;
private boolean fetchOwner;
private Integer maxKeys;
private String prefix;
private String startAfter;
private boolean includeUserMetadata;
private String delimiter = "";
private boolean useUrlEncodingType = true;
private String keyMarker; // 'marker' for ListObjectsV1 and 'startAfter' for ListObjectsV2.
private int maxKeys = 1000;
private String prefix = "";
private String continuationToken; // only for ListObjectsV2.
private boolean fetchOwner; // only for ListObjectsV2.
private String versionIdMarker; // only for GetObjectVersions.
private boolean includeUserMetadata; // MinIO extension applicable to ListObjectsV2.
private boolean recursive;
private boolean useVersion1;
private boolean useApiVersion1;
private boolean includeVersions;

public String continuationToken() {
return continuationToken;
public String delimiter() {
if (recursive) {
return "";
}

return (delimiter.isEmpty() ? "/" : delimiter);
}

public boolean includeUserMetadata() {
return includeUserMetadata;
public boolean useUrlEncodingType() {
return useUrlEncodingType;
}

public String keyMarker() {
return keyMarker;
}

public String marker() {
return keyMarker;
}

public String startAfter() {
return startAfter;
return keyMarker;
}

public int maxKeys() {
return maxKeys;
}

public String prefix() {
return prefix;
}

public Integer maxKeys() {
return maxKeys;
public String continuationToken() {
return continuationToken;
}

public boolean fetchOwner() {
return fetchOwner;
}

public String delimiter() {
return delimiter;
public String versionIdMarker() {
return versionIdMarker;
}

public boolean includeUserMetadata() {
return includeUserMetadata;
}

public boolean recursive() {
return recursive;
}

public boolean useVersion1() {
return useVersion1;
public boolean useApiVersion1() {
return useApiVersion1;
}

public boolean includeVersions() {
return includeVersions;
}

public static Builder builder() {
Expand All @@ -70,28 +97,67 @@ public static Builder builder() {

/** Argument builder of @see MinioClient#listObjects(ListObjectArgs args). */
public static final class Builder extends BucketArgs.Builder<Builder, ListObjectsArgs> {
public Builder continuationToken(String continuationToken) {
operations.add(args -> args.continuationToken = continuationToken);
@Override
protected void validate(ListObjectsArgs args) {
super.validate(args);

if (args.useApiVersion1() || args.includeVersions()) {
if (args.continuationToken() != null || args.fetchOwner() || args.includeUserMetadata()) {
throw new IllegalArgumentException(
"continuation token/fetch owner/include metadata are supported only"
+ " for list objects version 2");
}
}

if (args.versionIdMarker != null && args.useApiVersion1()) {
throw new IllegalArgumentException(
"version ID marker is not supported for list objects version 1");
}
}

public Builder delimiter(String delimiter) {
operations.add(args -> args.delimiter = (delimiter == null ? "" : delimiter));
return this;
}

public Builder includeUserMetadata(boolean includeUserMetadata) {
operations.add(args -> args.includeUserMetadata = includeUserMetadata);
public Builder useUrlEncodingType(boolean flag) {
operations.add(args -> args.useUrlEncodingType = flag);
return this;
}

public Builder keyMarker(String keyMarker) {
validateNullOrNotEmptyString(keyMarker, "key marker");
operations.add(args -> args.keyMarker = keyMarker);
return this;
}

public Builder marker(String marker) {
operations.add(args -> args.keyMarker = marker);
return this;
}

public Builder startAfter(String startAfter) {
operations.add(args -> args.startAfter = startAfter);
operations.add(args -> args.keyMarker = startAfter);
return this;
}

public Builder maxKeys(int maxKeys) {
if (maxKeys < 1 || maxKeys > 1000) {
throw new IllegalArgumentException("max keys must be between 1 and 1000");
}

operations.add(args -> args.maxKeys = maxKeys);
return this;
}

public Builder prefix(String prefix) {
operations.add(args -> args.prefix = prefix);
operations.add(args -> args.prefix = (prefix == null ? "" : prefix));
return this;
}

public Builder maxKeys(Integer maxKeys) {
operations.add(args -> args.maxKeys = maxKeys);
public Builder continuationToken(String continuationToken) {
validateNullOrNotEmptyString(continuationToken, "continuation token");
operations.add(args -> args.continuationToken = continuationToken);
return this;
}

Expand All @@ -100,8 +166,14 @@ public Builder fetchOwner(boolean fetchOwner) {
return this;
}

public Builder delimiter(String delimiter) {
operations.add(args -> args.delimiter = delimiter);
public Builder versionIdMarker(String versionIdMarker) {
validateNullOrNotEmptyString(versionIdMarker, "version ID marker");
operations.add(args -> args.versionIdMarker = versionIdMarker);
return this;
}

public Builder includeUserMetadata(boolean includeUserMetadata) {
operations.add(args -> args.includeUserMetadata = includeUserMetadata);
return this;
}

Expand All @@ -110,8 +182,13 @@ public Builder recursive(boolean recursive) {
return this;
}

public Builder useVersion1(boolean useVersion1) {
operations.add(args -> args.useVersion1 = useVersion1);
public Builder useApiVersion1(boolean useApiVersion1) {
operations.add(args -> args.useApiVersion1 = useApiVersion1);
return this;
}

public Builder includeVersions(boolean includeVersions) {
operations.add(args -> args.includeVersions = includeVersions);
return this;
}
}
Expand Down
Loading