Skip to content

Commit

Permalink
Add getObject{Acl,Attributes} APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <[email protected]>
  • Loading branch information
balamurugana committed Jan 28, 2025
1 parent 0f533e8 commit df8797a
Show file tree
Hide file tree
Showing 17 changed files with 1,025 additions and 23 deletions.
27 changes: 27 additions & 0 deletions api/src/main/java/io/minio/GetObjectAclArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2025 MinIO, Inc.
*
* 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 io.minio;

/** Argument class of {@link MinioAsyncClient#getObjectAcl} and {@link MinioClient#getObjectAcl}. */
public class GetObjectAclArgs extends ObjectVersionArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link GetObjectAclArgs}. */
public static final class Builder extends ObjectVersionArgs.Builder<Builder, GetObjectAclArgs> {}
}
96 changes: 96 additions & 0 deletions api/src/main/java/io/minio/GetObjectAttributesArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2025 MinIO, Inc.
*
* 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 io.minio;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
* Argument class of {@link MinioAsyncClient#getObjectAttributes} and {@link
* MinioClient#getObjectAttributes}.
*/
public class GetObjectAttributesArgs extends ObjectReadArgs {
private List<String> objectAttributes;
private Integer maxParts;
private Integer partNumberMarker;

public List<String> objectAttributes() {
return objectAttributes;
}

public Integer maxParts() {
return maxParts;
}

public Integer partNumberMarker() {
return partNumberMarker;
}

public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link GetObjectAttributesArgs}. */
public static final class Builder
extends ObjectReadArgs.Builder<Builder, GetObjectAttributesArgs> {
@Override
protected void validate(GetObjectAttributesArgs args) {
super.validate(args);
validateNotNull(args.objectAttributes, "object attributes");
}

public Builder objectAttributes(String[] objectAttributes) {
operations.add(
args ->
args.objectAttributes =
objectAttributes == null ? null : Arrays.asList(objectAttributes));
return this;
}

public Builder objectAttributes(List<String> objectAttributes) {
operations.add(args -> args.objectAttributes = objectAttributes);
return this;
}

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

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GetObjectAttributesArgs)) return false;
if (!super.equals(o)) return false;
GetObjectAttributesArgs that = (GetObjectAttributesArgs) o;
return Objects.equals(objectAttributes, that.objectAttributes)
&& Objects.equals(maxParts, that.maxParts)
&& Objects.equals(partNumberMarker, that.partNumberMarker);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), objectAttributes, maxParts, partNumberMarker);
}
}
42 changes: 42 additions & 0 deletions api/src/main/java/io/minio/GetObjectAttributesResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2025 MinIO, Inc.
*
* 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 io.minio;

import io.minio.messages.GetObjectAttributesOutput;
import okhttp3.Headers;

/**
* Response class of {@link MinioAsyncClient#getObjectAttributes} and {@link
* MinioClient#getObjectAttributes}.
*/
public class GetObjectAttributesResponse extends GenericResponse {
private GetObjectAttributesOutput result;

public GetObjectAttributesResponse(
Headers headers,
String bucket,
String region,
String object,
GetObjectAttributesOutput result) {
super(headers, bucket, region, object);
this.result = result;
}

public GetObjectAttributesOutput result() {
return result;
}
}
108 changes: 108 additions & 0 deletions api/src/main/java/io/minio/MinioAsyncClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
import io.minio.errors.XmlParserException;
import io.minio.http.HttpUtils;
import io.minio.http.Method;
import io.minio.messages.AccessControlPolicy;
import io.minio.messages.Bucket;
import io.minio.messages.CopyObjectResult;
import io.minio.messages.CreateBucketConfiguration;
import io.minio.messages.DeleteError;
import io.minio.messages.DeleteObject;
import io.minio.messages.GetObjectAttributesOutput;
import io.minio.messages.Item;
import io.minio.messages.LegalHold;
import io.minio.messages.LifecycleConfiguration;
Expand Down Expand Up @@ -66,6 +68,7 @@
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -3151,6 +3154,111 @@ public CompletableFuture<Void> deleteObjectTags(DeleteObjectTagsArgs args)
return executeDeleteAsync(args, null, queryParams).thenAccept(response -> response.close());
}

/**
* Gets access control policy of an object.
*
* <pre>Example:{@code
* CompletableFuture<AccessControlPolicy> future =
* minioAsyncClient.getObjectAcl(
* GetObjectAclArgs.builder().bucket("my-bucketname").object("my-objectname").build());
* }</pre>
*
* @param args {@link GetObjectAclArgs} object.
* @return {@link CompletableFuture}&lt;{@link AccessControlPolicy}&gt; object.
* @throws InsufficientDataException thrown to indicate not enough data available in InputStream.
* @throws InternalException thrown to indicate internal library error.
* @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library.
* @throws IOException thrown to indicate I/O error on S3 operation.
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws XmlParserException thrown to indicate XML parsing error.
*/
public CompletableFuture<AccessControlPolicy> getObjectAcl(GetObjectAclArgs args)
throws InsufficientDataException, InternalException, InvalidKeyException, IOException,
NoSuchAlgorithmException, XmlParserException {
checkArgs(args);
Multimap<String, String> queryParams = newMultimap("acl", "");
if (args.versionId() != null) queryParams.put("versionId", args.versionId());
return executeGetAsync(args, null, queryParams)
.thenApply(
response -> {
try {
return Xml.unmarshal(AccessControlPolicy.class, response.body().charStream());
} catch (XmlParserException e) {
throw new CompletionException(e);
} finally {
response.close();
}
});
}

/**
* Gets attributes of an object.
*
* <pre>Example:{@code
* CompletableFuture<GetObjectAttributesResponse> future =
* minioAsyncClient.getObjectAttributes(
* GetObjectAttributesArgs.builder()
* .bucket("my-bucketname")
* .object("my-objectname")
* .objectAttributes(
* new String[] {
* "ETag", "Checksum", "ObjectParts", "StorageClass", "ObjectSize"
* })
* .build());
* }</pre>
*
* @param args {@link GetObjectAttributesArgs} object.
* @return {@link CompletableFuture}&lt;{@link GetObjectAttributesResponse}&gt; object.
* @throws InsufficientDataException thrown to indicate not enough data available in InputStream.
* @throws InternalException thrown to indicate internal library error.
* @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library.
* @throws IOException thrown to indicate I/O error on S3 operation.
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws XmlParserException thrown to indicate XML parsing error.
*/
public CompletableFuture<GetObjectAttributesResponse> getObjectAttributes(
GetObjectAttributesArgs args)
throws InsufficientDataException, InternalException, InvalidKeyException, IOException,
NoSuchAlgorithmException, XmlParserException {
checkArgs(args);

Multimap<String, String> queryParams = newMultimap("attributes", "");
if (args.versionId() != null) queryParams.put("versionId", args.versionId());

Multimap<String, String> headers = HashMultimap.create();
if (args.maxParts() != null) headers.put("x-amz-max-parts", args.maxParts().toString());
if (args.partNumberMarker() != null) {
headers.put("x-amz-part-number-marker", args.partNumberMarker().toString());
}
for (String attribute : args.objectAttributes()) {
if (attribute != null) headers.put("x-amz-object-attributes", attribute);
}

return executeGetAsync(args, headers, queryParams)
.thenApply(
response -> {
try {
GetObjectAttributesOutput result =
Xml.unmarshal(GetObjectAttributesOutput.class, response.body().charStream());

String value = response.headers().get("x-amz-delete-marker");
if (value != null) result.setDeleteMarker(Boolean.valueOf(value));
value = response.headers().get("Last-Modified");
if (value != null) {
result.setLastModified(ZonedDateTime.parse(value, Time.HTTP_HEADER_DATE_FORMAT));
}
result.setVersionId(response.headers().get("x-amz-version-id"));

return new GetObjectAttributesResponse(
response.headers(), args.bucket(), args.region(), args.object(), result);
} catch (XmlParserException e) {
throw new CompletionException(e);
} finally {
response.close();
}
});
}

/**
* Uploads multiple objects in a single put call. It is done by creating intermediate TAR file
* optionally compressed which is uploaded to S3 service.
Expand Down
78 changes: 78 additions & 0 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.minio.errors.InvalidResponseException;
import io.minio.errors.ServerException;
import io.minio.errors.XmlParserException;
import io.minio.messages.AccessControlPolicy;
import io.minio.messages.Bucket;
import io.minio.messages.DeleteError;
import io.minio.messages.Item;
Expand Down Expand Up @@ -2275,6 +2276,83 @@ public void deleteObjectTags(DeleteObjectTagsArgs args)
}
}

/**
* Gets access control policy of an object.
*
* <pre>Example:{@code
* AccessControlPolicy policy =
* minioClient.getObjectAcl(
* GetObjectAclArgs.builder().bucket("my-bucketname").object("my-objectname").build());
* }</pre>
*
* @param args {@link GetObjectAclArgs} object.
* @return {@link AccessControlPolicy} - Access control policy object.
* @throws ErrorResponseException thrown to indicate S3 service returned an error response.
* @throws InsufficientDataException thrown to indicate not enough data available in InputStream.
* @throws InternalException thrown to indicate internal library error.
* @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library.
* @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error
* response.
* @throws IOException thrown to indicate I/O error on S3 operation.
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws XmlParserException thrown to indicate XML parsing error.
*/
public AccessControlPolicy getObjectAcl(GetObjectAclArgs args)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidKeyException, InvalidResponseException, IOException, NoSuchAlgorithmException,
ServerException, XmlParserException {
try {
return asyncClient.getObjectAcl(args).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
asyncClient.throwEncapsulatedException(e);
return null;
}
}

/**
* Gets attributes of an object.
*
* <pre>Example:{@code
* GetObjectAttributesResponse response =
* minioClient.getObjectAttributes(
* GetObjectAttributesArgs.builder()
* .bucket("my-bucketname")
* .object("my-objectname")
* .objectAttributes(
* new String[] {
* "ETag", "Checksum", "ObjectParts", "StorageClass", "ObjectSize"
* })
* .build());
* }</pre>
*
* @param args {@link GetObjectAttributesArgs} object.
* @return {@link GetObjectAttributesResponse} - Response object.
* @throws ErrorResponseException thrown to indicate S3 service returned an error response.
* @throws InsufficientDataException thrown to indicate not enough data available in InputStream.
* @throws InternalException thrown to indicate internal library error.
* @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library.
* @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error
* response.
* @throws IOException thrown to indicate I/O error on S3 operation.
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws XmlParserException thrown to indicate XML parsing error.
*/
public GetObjectAttributesResponse getObjectAttributes(GetObjectAttributesArgs args)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidKeyException, InvalidResponseException, IOException, NoSuchAlgorithmException,
ServerException, XmlParserException {
try {
return asyncClient.getObjectAttributes(args).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
asyncClient.throwEncapsulatedException(e);
return null;
}
}

/**
* Uploads multiple objects in a single put call. It is done by creating intermediate TAR file
* optionally compressed which is uploaded to S3 service.
Expand Down
Loading

0 comments on commit df8797a

Please sign in to comment.