Skip to content

Commit 93a5ed3

Browse files
Adding pre-signed URL operation core API and Get Object Request Pojo (#6216)
* Add presigned URL request models and tests * Pre-signed URL API and Get Object Request definitions * JavaDoc changes, String to URL change * Delete services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/presignedurl/DefaultPresignedUrlManager.java * Delete services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/presignedurl/PresignedUrlGetObjectRequestMarshaller.java * Delete services/s3/src/test/java/software/amazon/awssdk/services/s3/presignedurl/model/PresignedUrlTest.java * Format PresignedUrlGetObjectRequestWrapper.java * Format PresignedUrlManager.java * Format PresignedUrlGetObjectRequest.java * Format PresignedUrlGetObjectRequestWrapperTest.java * Format PresignedUrlGetObjectRequestTest.java * sonarcube issues fixed * Delete .idea/codeStyles/Project.xml * added consumer builder, javadoc for builder, assert range value test * removing codestle from gitignore
1 parent cd49f1f commit 93a5ed3

File tree

5 files changed

+613
-0
lines changed

5 files changed

+613
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.internal.presignedurl.model;
17+
18+
import java.net.URL;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Objects;
25+
import java.util.function.Function;
26+
import software.amazon.awssdk.annotations.SdkInternalApi;
27+
import software.amazon.awssdk.core.SdkField;
28+
import software.amazon.awssdk.core.protocol.MarshallLocation;
29+
import software.amazon.awssdk.core.protocol.MarshallingType;
30+
import software.amazon.awssdk.core.traits.LocationTrait;
31+
import software.amazon.awssdk.services.s3.model.S3Request;
32+
33+
/**
34+
* Internal request object for presigned URL GetObject operations.
35+
* <p>
36+
* This class is used internally by the AWS SDK to process presigned URL requests for S3 GetObject operations. It contains minimal
37+
* SdkField definitions needed for custom marshalling and is not intended for direct use by SDK users.
38+
* </p>
39+
* <b>Note:</b> This is an internal implementation class and should not be used
40+
* directly. Use {@code PresignedUrlGetObjectRequest} for public API interactions.
41+
*/
42+
@SdkInternalApi
43+
public final class PresignedUrlGetObjectRequestWrapper extends S3Request {
44+
private static final SdkField<String> RANGE_FIELD = SdkField
45+
.<String>builder(MarshallingType.STRING)
46+
.memberName("Range")
47+
.getter(getter(PresignedUrlGetObjectRequestWrapper::range))
48+
.traits(LocationTrait.builder().location(MarshallLocation.HEADER).locationName("Range")
49+
.unmarshallLocationName("Range").build()).build();
50+
51+
private static final List<SdkField<?>> SDK_FIELDS = Collections.unmodifiableList(
52+
Arrays.asList(RANGE_FIELD));
53+
54+
private static final Map<String, SdkField<?>> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
55+
56+
private final URL url;
57+
private final String range;
58+
59+
private PresignedUrlGetObjectRequestWrapper(Builder builder) {
60+
super(builder);
61+
this.url = builder.url;
62+
this.range = builder.range;
63+
}
64+
65+
public URL url() {
66+
return url;
67+
}
68+
69+
public String range() {
70+
return range;
71+
}
72+
73+
@Override
74+
public List<SdkField<?>> sdkFields() {
75+
return SDK_FIELDS;
76+
}
77+
78+
@Override
79+
public Map<String, SdkField<?>> sdkFieldNameToField() {
80+
return SDK_NAME_TO_FIELD;
81+
}
82+
83+
private static <T> Function<Object, T> getter(Function<PresignedUrlGetObjectRequestWrapper, T> g) {
84+
return obj -> g.apply((PresignedUrlGetObjectRequestWrapper) obj);
85+
}
86+
87+
private static Map<String, SdkField<?>> memberNameToFieldInitializer() {
88+
Map<String, SdkField<?>> map = new HashMap<>();
89+
map.put("Range", RANGE_FIELD);
90+
return Collections.unmodifiableMap(map);
91+
}
92+
93+
@Override
94+
public Builder toBuilder() {
95+
return new Builder(this);
96+
}
97+
98+
public static Builder builder() {
99+
return new Builder();
100+
}
101+
102+
@Override
103+
public boolean equals(Object obj) {
104+
if (this == obj) {
105+
return true;
106+
}
107+
if (obj == null || getClass() != obj.getClass()) {
108+
return false;
109+
}
110+
if (!super.equals(obj)) {
111+
return false;
112+
}
113+
PresignedUrlGetObjectRequestWrapper that = (PresignedUrlGetObjectRequestWrapper) obj;
114+
return Objects.equals(url, that.url) && Objects.equals(range, that.range);
115+
}
116+
117+
@Override
118+
public int hashCode() {
119+
int result = Objects.hashCode(super.hashCode());
120+
result = 31 * result + Objects.hashCode(url);
121+
result = 31 * result + Objects.hashCode(range);
122+
return result;
123+
}
124+
125+
public static final class Builder extends S3Request.BuilderImpl {
126+
private URL url;
127+
private String range;
128+
129+
public Builder() {
130+
}
131+
132+
Builder(PresignedUrlGetObjectRequestWrapper request) {
133+
super(request);
134+
this.url = request.url();
135+
this.range = request.range();
136+
}
137+
138+
public Builder url(URL url) {
139+
this.url = url;
140+
return this;
141+
}
142+
143+
public Builder range(String range) {
144+
this.range = range;
145+
return this;
146+
}
147+
148+
@Override
149+
public PresignedUrlGetObjectRequestWrapper build() {
150+
return new PresignedUrlGetObjectRequestWrapper(this);
151+
}
152+
}
153+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.presignedurl;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.core.exception.SdkClientException;
20+
import software.amazon.awssdk.core.sync.ResponseTransformer;
21+
import software.amazon.awssdk.services.s3.S3Client;
22+
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
23+
import software.amazon.awssdk.services.s3.model.InvalidObjectStateException;
24+
import software.amazon.awssdk.services.s3.model.NoSuchKeyException;
25+
import software.amazon.awssdk.services.s3.model.S3Exception;
26+
import software.amazon.awssdk.services.s3.presignedurl.model.PresignedUrlGetObjectRequest;
27+
28+
/**
29+
* Interface for executing S3 operations using presigned URLs. This can be accessed using {@link S3Client#presignedUrlManager()}.
30+
*/
31+
@SdkPublicApi
32+
public interface PresignedUrlManager {
33+
/**
34+
* <p>
35+
* Downloads an S3 object using a presigned URL.
36+
* </p>
37+
* <p>
38+
* This operation uses a presigned URL that contains all necessary authentication information, eliminating the need for AWS
39+
* credentials at request time. The presigned URL must be valid and not expired.
40+
* </p>
41+
* <dl>
42+
* <dt>Range Requests</dt>
43+
* <dd>
44+
* <p>
45+
* Supports partial object downloads using HTTP Range headers. Specify the range parameter
46+
* in the request to download only a portion of the object (e.g., "bytes=0-1023").
47+
* </p>
48+
* </dd>
49+
* <dt>Storage Classes</dt>
50+
* <dd>
51+
* <p>
52+
* If the object is stored in S3 Glacier Flexible Retrieval, S3 Glacier Deep Archive,
53+
* or S3 Intelligent-Tiering Archive tiers, the object must be restored before retrieval.
54+
* Otherwise, this operation returns an <code>InvalidObjectState</code> error.
55+
* </p>
56+
* </dd>
57+
* </dl>
58+
*
59+
* @param request The presigned URL request containing the URL and optional range parameters
60+
* @param responseTransformer Transforms the response to the desired return type. See
61+
* {@link software.amazon.awssdk.core.sync.ResponseTransformer} for pre-built implementations like
62+
* downloading to a file or converting to bytes.
63+
* @param <ReturnT> The type of the transformed response
64+
* @return The transformed result of the ResponseTransformer
65+
* @throws software.amazon.awssdk.services.s3.model.NoSuchKeyException The specified object does not exist
66+
* @throws software.amazon.awssdk.services.s3.model.InvalidObjectStateException Object is archived and must be restored before
67+
* retrieval
68+
* @throws software.amazon.awssdk.core.exception.SdkClientException If any client side error occurs such as
69+
* network failures or invalid presigned URL
70+
* @throws S3Exception Base class for all S3 service exceptions.
71+
* Unknown exceptions will be thrown as an
72+
* instance of this type.
73+
*/
74+
default <ReturnT> ReturnT getObject(PresignedUrlGetObjectRequest request,
75+
ResponseTransformer<GetObjectResponse,
76+
ReturnT> responseTransformer) throws NoSuchKeyException,
77+
InvalidObjectStateException,
78+
SdkClientException,
79+
S3Exception {
80+
throw new UnsupportedOperationException();
81+
}
82+
83+
//TODO: Add other getObject method flavors
84+
}

0 commit comments

Comments
 (0)