-
Notifications
You must be signed in to change notification settings - Fork 916
HttpSigner interface changes #4018
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
HttpSigner interface changes #4018
Conversation
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSigner.java
Outdated
Show resolved
Hide resolved
They have default implementation that rely on new DefaultHttpSignRequest.BuilderImpl constructor that relies on the generic IdentityT without knowing the Class of that type. This class is @SdkInternalApi so this constructor is considered private. Also, make HttpSignRequest.builder take Class<IdentityT> as parameter. Also, make IdentityT type extends Identity in HttpSignRequest.
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSigner.java
Outdated
Show resolved
Hide resolved
core/http-auth-spi/src/test/java/software/amazon/awssdk/http/auth/spi/HttpSignerTest.java
Outdated
Show resolved
Hide resolved
This fixes HttpSignerTest.signAsync_usingRequest_works test.
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/AsyncHttpSignRequest.java
Show resolved
Hide resolved
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/AsyncHttpSignRequest.java
Outdated
Show resolved
Hide resolved
static <T> Builder<T> builder(Class<T> payloadType) { | ||
return new DefaultHttpSignRequest.BuilderImpl(payloadType); | ||
} | ||
public interface HttpSignRequest<PayloadT, IdentityT extends Identity> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo, this should implement ToCopyableBuilder
and its builder should implement CopyableBuilder
. That prevents some issues here, like needing to remember to override every parent method in the child class.
Unfortunately it makes the parameters on this type even crazier.
To make the room, we could change IdentityT identity()
to Identity identity()
and Optional<PayloadT> payload()
to Optional<? extends Object> payload()
, and then override them in the child types to return the exact types. Even better, we might just remove the getters from here entirely and rely on the subtype. I don't expect it to be a major problem to need to use the subtype to get access to the payload or identity.
We'd also need to remove the payload
and identity
setters from this base builder, but that's probably okay - we can just put them in the child types. It should be very rare that someone needs to set the identity or payload using the base builder type...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That prevents some issues here, like needing to remember to override every parent method in the child class.
Without using To/CopyableBuilder, I was able to remove the overriding of methods in the builder sub-interfaces to return the sub-type by adding a generic type parameter for the builder, in these commits de704e7 and 3e24cc4.
I'm not sure if we'll really need to mutate these objects, so I think we can defer making these To/CopyableBuilder until needed?
@@ -58,16 +58,16 @@ static <T> Builder<T> builder(Class<T> payloadType) { | |||
/** | |||
* A builder for a {@link SignedHttpRequest}. | |||
*/ | |||
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, SignedHttpRequest> { | |||
interface Builder<PayloadT> extends SdkBuilder<Builder<PayloadT>, SignedHttpRequest<PayloadT>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here. CopyableBuilder
?
...-spi/src/main/java/software/amazon/awssdk/http/auth/spi/internal/DefaultHttpSignRequest.java
Outdated
Show resolved
Hide resolved
And removed `payloadType()` accessor. Also, HttpSignRequest builders take Identity as parameter instead of Class<IdentityT>.
* Added missing Builder method override for identity * Fixed javadocs * Fixed toString
Optional<PayloadT> payload(); | ||
|
||
/** | ||
* Returns the property that the {@link HttpSigner} can use during signing. | ||
* Returns the identity. | ||
*/ | ||
IdentityT identity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo, I'd rather not parameterize this types and just do Optional<?> payload()
and Identity identity()
here. Subtypes would override them with the more-specific return type.
This makes it so that code that deal with the base sign request can just deal with a SignRequest
instead of a SignRequest<?, ?>
, and the base builder can just deal with a Builder<?> instead of a Builder<?, ?, ?>
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think code that deals with base sign request, might benefit from the type, atleast the IdentityT. So the BearerTokenSigner can extract the token from HttpSignRequest<?, TokenIdentity identity>
. Though I can see removing the PayloadT (will reduce it by one), but means the subtypes have to (re)define the payload()
method instead of specifying the generic in type definition. And as an interface, having a HttpSignRequest that has a payload()
accessor but doesn't know it's type doesn't feel great to me, so I'm in favor of keeping them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. And we can reassess at the surface area review as well, once we can see the impact on the signers, etc.
/** | ||
* Set the body payload of the request. A payload is optional. By default, the payload will be empty. | ||
*/ | ||
Builder payload(PayloadT payload); | ||
B payload(PayloadT payload); | ||
|
||
/** | ||
* Set the identity of the request. | ||
*/ | ||
B identity(IdentityT identity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with the suggestion I have above, we'd remove these from the base builder and put it in the subtypes.
core/http-auth-spi/src/main/java/software/amazon/awssdk/http/auth/spi/HttpSigner.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor nit, otherwise lgtm.
*/ | ||
@SdkPublicApi | ||
@SdkProtectedApi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a public api.
Optional<PayloadT> payload(); | ||
|
||
/** | ||
* Returns the property that the {@link HttpSigner} can use during signing. | ||
* Returns the identity. | ||
*/ | ||
IdentityT identity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. And we can reassess at the surface area review as well, once we can see the impact on the signers, etc.
SonarCloud Quality Gate failed.
|
Motivation and Context
Modifications
Other fixes:
Usage is shown in HttpSignerTest included in this PR.
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License