Skip to content

Commit 80bc11c

Browse files
committed
Split sync/async interfaces for SignedHttpRequest
And removed `payloadType()` accessor. Also, HttpSignRequest builders take Identity as parameter instead of Class<IdentityT>.
1 parent 74e085b commit 80bc11c

14 files changed

+285
-108
lines changed

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/AsyncHttpSignRequest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ public interface AsyncHttpSignRequest<IdentityT extends Identity> extends HttpSi
3232
/**
3333
* Get a new builder for creating a {@link AsyncHttpSignRequest}.
3434
*/
35-
static <IdentityT extends Identity> Builder<IdentityT> builder(Class<IdentityT> ignoredIdentityType) {
36-
return new DefaultAsyncHttpSignRequest.BuilderImpl<>();
37-
}
38-
39-
@Override
40-
default Class<Publisher<ByteBuffer>> payloadType() {
41-
// TODO: Code Review Note: Note this cast
42-
return (Class) Publisher.class;
35+
static <IdentityT extends Identity> Builder<IdentityT> builder(IdentityT identity) {
36+
return new DefaultAsyncHttpSignRequest.BuilderImpl<>(identity);
4337
}
4438

4539
interface Builder<IdentityT extends Identity> extends HttpSignRequest.Builder<Publisher<ByteBuffer>, IdentityT>,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.http.auth.spi;
17+
18+
import java.nio.ByteBuffer;
19+
import org.reactivestreams.Publisher;
20+
import software.amazon.awssdk.annotations.Immutable;
21+
import software.amazon.awssdk.annotations.SdkPublicApi;
22+
import software.amazon.awssdk.annotations.ThreadSafe;
23+
import software.amazon.awssdk.http.SdkHttpRequest;
24+
import software.amazon.awssdk.http.auth.spi.internal.DefaultAsyncSignedHttpRequest;
25+
import software.amazon.awssdk.utils.builder.SdkBuilder;
26+
27+
/**
28+
* Represents a request that has been signed by {@link HttpSigner}.
29+
** //TODO:
30+
*/
31+
@SdkPublicApi
32+
@Immutable
33+
@ThreadSafe
34+
public interface AsyncSignedHttpRequest extends SignedHttpRequest<Publisher<ByteBuffer>> {
35+
36+
/**
37+
* Get a new builder for creating a {@link SyncSignedHttpRequest}.
38+
*/
39+
static Builder builder() {
40+
return new DefaultAsyncSignedHttpRequest.BuilderImpl();
41+
}
42+
43+
/**
44+
* A builder for a {@link SyncSignedHttpRequest}.
45+
*/
46+
interface Builder extends SignedHttpRequest.Builder<Publisher<ByteBuffer>>, SdkBuilder<Builder, AsyncSignedHttpRequest> {
47+
48+
/**
49+
* Set the HTTP request object, without the request body payload.
50+
*/
51+
@Override
52+
Builder request(SdkHttpRequest request);
53+
54+
/**
55+
* Set the body payload of the request. A payload is optional. By default, the payload will be empty.
56+
*/
57+
@Override
58+
Builder payload(Publisher<ByteBuffer> payload);
59+
}
60+
}

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSignRequest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
@ThreadSafe
3737
public interface HttpSignRequest<PayloadT, IdentityT extends Identity> {
3838

39-
/**
40-
* Returns the type of the payload.
41-
*/
42-
Class<PayloadT> payloadType();
43-
4439
/**
4540
* Returns the HTTP request object, without the request body payload.
4641
*/
@@ -51,6 +46,9 @@ public interface HttpSignRequest<PayloadT, IdentityT extends Identity> {
5146
*/
5247
Optional<PayloadT> payload();
5348

49+
/**
50+
* Returns the identity.
51+
*/
5452
IdentityT identity();
5553

5654
/**

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSigner.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
package software.amazon.awssdk.http.auth.spi;
1717

18-
import java.nio.ByteBuffer;
1918
import java.util.function.Consumer;
20-
import org.reactivestreams.Publisher;
2119
import software.amazon.awssdk.annotations.SdkPublicApi;
22-
import software.amazon.awssdk.http.ContentStreamProvider;
2320
import software.amazon.awssdk.http.auth.spi.internal.DefaultAsyncHttpSignRequest;
2421
import software.amazon.awssdk.http.auth.spi.internal.DefaultSyncHttpSignRequest;
2522
import software.amazon.awssdk.identity.spi.Identity;
@@ -39,18 +36,19 @@ public interface HttpSigner<IdentityT extends Identity> {
3936
* @param request The inputs to sign a request.
4037
* @return A signed version of the request.
4138
*/
42-
SignedHttpRequest<ContentStreamProvider> sign(SyncHttpSignRequest<IdentityT> request);
39+
SyncSignedHttpRequest sign(SyncHttpSignRequest<IdentityT> request);
4340

4441
/**
4542
* Method that takes in inputs to sign a request with sync payload and returns a signed version of the request.
4643
* <p>
4744
* Similar to {@link #sign(SyncHttpSignRequest)}, but takes a lambda to configure a new {@link SyncHttpSignRequest.Builder}.
48-
* This removes the need to call {@link SyncHttpSignRequest#builder(Class)}} and {@link SyncHttpSignRequest.Builder#build()}.
45+
* This removes the need to call {@link SyncHttpSignRequest#builder(IdentityT)}} and
46+
* {@link SyncHttpSignRequest.Builder#build()}.
4947
*
5048
* @param consumer A {@link Consumer} to which an empty {@link SyncHttpSignRequest.Builder} will be given.
5149
* @return A signed version of the request.
5250
*/
53-
default SignedHttpRequest<ContentStreamProvider> sign(Consumer<SyncHttpSignRequest.Builder<IdentityT>> consumer) {
51+
default SyncSignedHttpRequest sign(Consumer<SyncHttpSignRequest.Builder<IdentityT>> consumer) {
5452
return sign(new DefaultSyncHttpSignRequest.BuilderImpl<IdentityT>().applyMutation(consumer).build());
5553
}
5654

@@ -60,19 +58,19 @@ default SignedHttpRequest<ContentStreamProvider> sign(Consumer<SyncHttpSignReque
6058
* @param request The inputs to sign a request.
6159
* @return A signed version of the request.
6260
*/
63-
SignedHttpRequest<Publisher<ByteBuffer>> signAsync(AsyncHttpSignRequest<IdentityT> request);
61+
AsyncSignedHttpRequest signAsync(AsyncHttpSignRequest<IdentityT> request);
6462

6563
/**
6664
* Method that takes in inputs to sign a request with async payload and returns a signed version of the request.
6765
* <p>
6866
* Similar to {@link #signAsync(AsyncHttpSignRequest)}, but takes a lambda to configure a new
69-
* {@link AsyncHttpSignRequest.Builder}. This removes the need to call {@link AsyncHttpSignRequest#builder(Class)}} and
67+
* {@link AsyncHttpSignRequest.Builder}. This removes the need to call {@link AsyncHttpSignRequest#builder(IdentityT)}} and
7068
* {@link AsyncHttpSignRequest.Builder#build()}.
7169
*
7270
* @param consumer A {@link Consumer} to which an empty {@link HttpSignRequest.Builder} will be given.
7371
* @return A signed version of the request.
7472
*/
75-
default SignedHttpRequest<Publisher<ByteBuffer>> signAsync(Consumer<AsyncHttpSignRequest.Builder<IdentityT>> consumer) {
73+
default AsyncSignedHttpRequest signAsync(Consumer<AsyncHttpSignRequest.Builder<IdentityT>> consumer) {
7674
return signAsync(new DefaultAsyncHttpSignRequest.BuilderImpl<IdentityT>().applyMutation(consumer).build());
7775
}
7876
}

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/SignedHttpRequest.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import software.amazon.awssdk.annotations.SdkPublicApi;
2121
import software.amazon.awssdk.annotations.ThreadSafe;
2222
import software.amazon.awssdk.http.SdkHttpRequest;
23-
import software.amazon.awssdk.http.auth.spi.internal.DefaultSignedHttpRequest;
24-
import software.amazon.awssdk.utils.builder.SdkBuilder;
2523

2624
/**
2725
* Represents a request that has been signed by {@link HttpSigner}.
@@ -33,18 +31,6 @@
3331
@ThreadSafe
3432
public interface SignedHttpRequest<PayloadT> {
3533

36-
/**
37-
* Get a new builder for creating a {@link SignedHttpRequest}.
38-
*/
39-
static <T> Builder<T> builder(Class<T> payloadType) {
40-
return new DefaultSignedHttpRequest.BuilderImpl<>(payloadType);
41-
}
42-
43-
/**
44-
* Returns the type of the payload.
45-
*/
46-
Class<PayloadT> payloadType();
47-
4834
/**
4935
* Returns the HTTP request object, without the request body payload.
5036
*/
@@ -58,7 +44,7 @@ static <T> Builder<T> builder(Class<T> payloadType) {
5844
/**
5945
* A builder for a {@link SignedHttpRequest}.
6046
*/
61-
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, SignedHttpRequest<PayloadT>> {
47+
interface Builder<PayloadT> {
6248

6349
/**
6450
* Set the HTTP request object, without the request body payload.

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/SyncHttpSignRequest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ public interface SyncHttpSignRequest<IdentityT extends Identity> extends HttpSig
3131
/**
3232
* Get a new builder for creating a {@link SyncHttpSignRequest}.
3333
*/
34-
static <IdentityT extends Identity> Builder<IdentityT> builder(Class<IdentityT> ignoredIdentityType) {
35-
return new DefaultSyncHttpSignRequest.BuilderImpl<>();
36-
}
37-
38-
@Override
39-
default Class<ContentStreamProvider> payloadType() {
40-
return ContentStreamProvider.class;
34+
static <IdentityT extends Identity> Builder<IdentityT> builder(IdentityT identity) {
35+
return new DefaultSyncHttpSignRequest.BuilderImpl<>(identity);
4136
}
4237

4338
interface Builder<IdentityT extends Identity> extends HttpSignRequest.Builder<ContentStreamProvider, IdentityT>,
@@ -48,9 +43,6 @@ interface Builder<IdentityT extends Identity> extends HttpSignRequest.Builder<Co
4843
@Override
4944
Builder<IdentityT> payload(ContentStreamProvider payload);
5045

51-
@Override
52-
Builder<IdentityT> identity(IdentityT identity);
53-
5446
@Override
5547
<T> Builder<IdentityT> putProperty(SignerProperty<T> key, T value);
5648
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.http.auth.spi;
17+
18+
import software.amazon.awssdk.annotations.Immutable;
19+
import software.amazon.awssdk.annotations.SdkPublicApi;
20+
import software.amazon.awssdk.annotations.ThreadSafe;
21+
import software.amazon.awssdk.http.ContentStreamProvider;
22+
import software.amazon.awssdk.http.SdkHttpRequest;
23+
import software.amazon.awssdk.http.auth.spi.internal.DefaultSyncSignedHttpRequest;
24+
import software.amazon.awssdk.utils.builder.SdkBuilder;
25+
26+
/**
27+
* Represents a request that has been signed by {@link HttpSigner}.
28+
* //TODO:
29+
*/
30+
@SdkPublicApi
31+
@Immutable
32+
@ThreadSafe
33+
public interface SyncSignedHttpRequest extends SignedHttpRequest<ContentStreamProvider> {
34+
35+
/**
36+
* Get a new builder for creating a {@link SyncSignedHttpRequest}.
37+
*/
38+
static Builder builder() {
39+
return new DefaultSyncSignedHttpRequest.BuilderImpl();
40+
}
41+
42+
/**
43+
* A builder for a {@link SyncSignedHttpRequest}.
44+
*/
45+
interface Builder extends SignedHttpRequest.Builder<ContentStreamProvider>, SdkBuilder<Builder, SyncSignedHttpRequest> {
46+
47+
/**
48+
* Set the HTTP request object, without the request body payload.
49+
*/
50+
@Override
51+
Builder request(SdkHttpRequest request);
52+
53+
/**
54+
* Set the body payload of the request. A payload is optional. By default, the payload will be empty.
55+
*/
56+
@Override
57+
Builder payload(ContentStreamProvider payload);
58+
}
59+
}

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/internal/DefaultAsyncHttpSignRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public static final class BuilderImpl<IdentityT extends Identity>
4343
extends DefaultHttpSignRequest.BuilderImpl<BuilderImpl<IdentityT>, Publisher<ByteBuffer>, IdentityT>
4444
implements AsyncHttpSignRequest.Builder<IdentityT> {
4545

46+
public BuilderImpl() {
47+
}
48+
49+
public BuilderImpl(IdentityT identity) {
50+
super(identity);
51+
}
52+
4653
@Override
4754
public AsyncHttpSignRequest<IdentityT> build() {
4855
return new DefaultAsyncHttpSignRequest<>(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.http.auth.spi.internal;
17+
18+
import java.nio.ByteBuffer;
19+
import org.reactivestreams.Publisher;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
21+
import software.amazon.awssdk.http.auth.spi.AsyncSignedHttpRequest;
22+
import software.amazon.awssdk.utils.ToString;
23+
24+
@SdkInternalApi
25+
public final class DefaultAsyncSignedHttpRequest
26+
extends DefaultSignedHttpRequest<Publisher<ByteBuffer>> implements AsyncSignedHttpRequest {
27+
28+
private DefaultAsyncSignedHttpRequest(BuilderImpl builder) {
29+
super(builder);
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return ToString.builder("SyncSignedHttpRequest")
35+
.add("request", request)
36+
.build();
37+
}
38+
39+
@SdkInternalApi
40+
public static final class BuilderImpl
41+
extends DefaultSignedHttpRequest.BuilderImpl<BuilderImpl, Publisher<ByteBuffer>>
42+
implements AsyncSignedHttpRequest.Builder {
43+
44+
@Override
45+
public AsyncSignedHttpRequest build() {
46+
return new DefaultAsyncSignedHttpRequest(this);
47+
}
48+
}
49+
}

core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/internal/DefaultHttpSignRequest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ public <T> T property(SignerProperty<T> property) {
6262

6363
@SdkInternalApi
6464
protected static class BuilderImpl<B extends BuilderImpl<B, PayloadT, IdentityT>, PayloadT, IdentityT extends Identity>
65-
implements HttpSignRequest.Builder<PayloadT, IdentityT> {
65+
implements Builder<PayloadT, IdentityT> {
6666
private SdkHttpRequest request;
6767
private PayloadT payload;
6868
private IdentityT identity;
6969
private final Map<SignerProperty<?>, Object> properties = new HashMap<>();
7070

71+
protected BuilderImpl() {
72+
}
73+
74+
protected BuilderImpl(IdentityT identity) {
75+
this.identity = identity;
76+
}
77+
7178
@Override
7279
public B request(SdkHttpRequest request) {
7380
this.request = request;

0 commit comments

Comments
 (0)