Skip to content

Commit a032c09

Browse files
mtdowlingrhernandez35
authored andcommitted
Remove AuthProperties and just use Context
Rather than essentially recreate Context for Auth and Identity related properties, we can just use Context. AuthProperties already used Context.Key, but recreated most of Context in order to be immutable. This isn't strictly necessary given Context can be made immutable using Context.unmodifiableView(ctx). In order to make this change, we needed to add a few missing methods to Context that are good additions: merge (merge two contexts and return a new context), getOrDefault, and Context.empty (return an immutable and empty context).
1 parent 4ead4d8 commit a032c09

File tree

36 files changed

+169
-313
lines changed

36 files changed

+169
-313
lines changed

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/AuthProperties.java

-177
This file was deleted.

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/NullSigner.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.concurrent.CompletableFuture;
99
import software.amazon.smithy.java.auth.api.identity.Identity;
10+
import software.amazon.smithy.java.context.Context;
1011

1112
/**
1213
* A signer that does nothing.
@@ -30,7 +31,7 @@ private NullSigner() {}
3031
* @return the request as-is.
3132
*/
3233
@Override
33-
public CompletableFuture<Object> sign(Object request, Identity identity, AuthProperties properties) {
34+
public CompletableFuture<Object> sign(Object request, Identity identity, Context properties) {
3435
return CompletableFuture.completedFuture(request);
3536
}
3637
}

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/Signer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.concurrent.CompletableFuture;
99
import software.amazon.smithy.java.auth.api.identity.Identity;
10+
import software.amazon.smithy.java.context.Context;
1011

1112
/**
1213
* Signs the given request using the given identity and returns a signed request.
@@ -24,7 +25,7 @@ public interface Signer<RequestT, IdentityT extends Identity> extends AutoClosea
2425
* @param properties Signing properties.
2526
* @return the signed request.
2627
*/
27-
CompletableFuture<RequestT> sign(RequestT request, IdentityT identity, AuthProperties properties);
28+
CompletableFuture<RequestT> sign(RequestT request, IdentityT identity, Context properties);
2829

2930
@SuppressWarnings("unchecked")
3031
static <RequestT, IdentityT extends Identity> Signer<RequestT, IdentityT> nullSigner() {

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/identity/IdentityResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.util.List;
99
import java.util.concurrent.CompletableFuture;
10-
import software.amazon.smithy.java.auth.api.AuthProperties;
10+
import software.amazon.smithy.java.context.Context;
1111

1212
/**
1313
* Interface for loading {@link Identity} that is used for authentication.
@@ -22,7 +22,7 @@ public interface IdentityResolver<IdentityT extends Identity> {
2222
* @param requestProperties The request properties used to resolve an Identity.
2323
* @return a CompletableFuture for the resolved identity result.
2424
*/
25-
CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(AuthProperties requestProperties);
25+
CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(Context requestProperties);
2626

2727
/**
2828
* Retrieve the class of the identity resolved by this identity resolver.

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/identity/IdentityResolverChain.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Objects;
1111
import java.util.concurrent.CompletableFuture;
12-
import software.amazon.smithy.java.auth.api.AuthProperties;
12+
import software.amazon.smithy.java.context.Context;
1313

1414
final class IdentityResolverChain<IdentityT extends Identity> implements IdentityResolver<IdentityT> {
1515
private final Class<IdentityT> identityClass;
@@ -29,14 +29,14 @@ public Class<IdentityT> identityType() {
2929
}
3030

3131
@Override
32-
public CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(AuthProperties requestProperties) {
32+
public CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(Context requestProperties) {
3333
List<IdentityResult<?>> errors = new ArrayList<>();
3434
return executeChain(resolvers.get(0), requestProperties, errors, 0);
3535
}
3636

3737
private CompletableFuture<IdentityResult<IdentityT>> executeChain(
3838
IdentityResolver<IdentityT> resolver,
39-
AuthProperties requestProperties,
39+
Context requestProperties,
4040
List<IdentityResult<?>> errors,
4141
int idx
4242
) {

Diff for: auth-api/src/main/java/software/amazon/smithy/java/auth/api/identity/StaticIdentityResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.util.Objects;
99
import java.util.concurrent.CompletableFuture;
10-
import software.amazon.smithy.java.auth.api.AuthProperties;
10+
import software.amazon.smithy.java.context.Context;
1111

1212
final class StaticIdentityResolver<IdentityT extends Identity> implements IdentityResolver<IdentityT> {
1313

@@ -20,7 +20,7 @@ public StaticIdentityResolver(IdentityT identity) {
2020
}
2121

2222
@Override
23-
public CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(AuthProperties requestProperties) {
23+
public CompletableFuture<IdentityResult<IdentityT>> resolveIdentity(Context requestProperties) {
2424
return result;
2525
}
2626

Diff for: aws/aws-sigv4/src/jmh/java/software/amazon/smithy/java/aws/client/auth/scheme/sigv4/SigV4SignerTrials.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.openjdk.jmh.annotations.Scope;
2323
import org.openjdk.jmh.annotations.Setup;
2424
import org.openjdk.jmh.annotations.State;
25-
import software.amazon.smithy.java.auth.api.AuthProperties;
2625
import software.amazon.smithy.java.auth.api.Signer;
2726
import software.amazon.smithy.java.aws.auth.api.identity.AwsCredentialsIdentity;
27+
import software.amazon.smithy.java.context.Context;
2828
import software.amazon.smithy.java.http.api.HttpHeaders;
2929
import software.amazon.smithy.java.http.api.HttpRequest;
3030
import software.amazon.smithy.java.http.api.HttpVersion;
@@ -38,10 +38,15 @@ public class SigV4SignerTrials {
3838
private static final AwsCredentialsIdentity TEST_IDENTITY = AwsCredentialsIdentity.create(
3939
"access-key",
4040
"secret-key");
41-
private static final AuthProperties TEST_PROPERTIES = AuthProperties.builder()
42-
.put(SigV4Settings.SIGNING_NAME, "service")
43-
.put(SigV4Settings.REGION, "us-east-1")
44-
.build();
41+
42+
private static final Context TEST_PROPERTIES;
43+
static {
44+
var ctx = Context.create();
45+
ctx.put(SigV4Settings.SIGNING_NAME, "service");
46+
ctx.put(SigV4Settings.REGION, "us-east-1");
47+
TEST_PROPERTIES = Context.unmodifiableView(ctx);
48+
}
49+
4550
private static final Map<String, HttpRequest> CASES = Map.ofEntries(
4651
Map.entry(
4752
"put_no_headers_no_query_no_body",

Diff for: aws/aws-sigv4/src/main/java/software/amazon/smithy/java/aws/client/auth/scheme/sigv4/SigV4AuthScheme.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package software.amazon.smithy.java.aws.client.auth.scheme.sigv4;
77

88
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
9-
import software.amazon.smithy.java.auth.api.AuthProperties;
109
import software.amazon.smithy.java.auth.api.Signer;
1110
import software.amazon.smithy.java.aws.auth.api.identity.AwsCredentialsIdentity;
1211
import software.amazon.smithy.java.client.core.auth.scheme.AuthScheme;
@@ -57,15 +56,15 @@ public Class<AwsCredentialsIdentity> identityClass() {
5756
}
5857

5958
@Override
60-
public AuthProperties getSignerProperties(Context context) {
61-
var builder = AuthProperties.builder()
62-
.put(SigV4Settings.SIGNING_NAME, signingName)
63-
.put(SigV4Settings.REGION, context.expect(SigV4Settings.REGION));
59+
public Context getSignerProperties(Context context) {
60+
var ctx = Context.create();
61+
ctx.put(SigV4Settings.SIGNING_NAME, signingName);
62+
ctx.put(SigV4Settings.REGION, context.expect(SigV4Settings.REGION));
6463
var clock = context.get(SigV4Settings.CLOCK);
6564
if (clock != null) {
66-
builder.put(SigV4Settings.CLOCK, clock);
65+
ctx.put(SigV4Settings.CLOCK, clock);
6766
}
68-
return builder.build();
67+
return Context.unmodifiableView(ctx);
6968
}
7069

7170
@Override

Diff for: aws/aws-sigv4/src/main/java/software/amazon/smithy/java/aws/client/auth/scheme/sigv4/SigV4Signer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.util.concurrent.CompletableFuture;
2626
import javax.crypto.Mac;
2727
import javax.crypto.spec.SecretKeySpec;
28-
import software.amazon.smithy.java.auth.api.AuthProperties;
2928
import software.amazon.smithy.java.auth.api.Signer;
3029
import software.amazon.smithy.java.aws.auth.api.identity.AwsCredentialsIdentity;
30+
import software.amazon.smithy.java.context.Context;
3131
import software.amazon.smithy.java.http.api.HttpHeaders;
3232
import software.amazon.smithy.java.http.api.HttpRequest;
3333
import software.amazon.smithy.java.io.datastream.DataStream;
@@ -101,7 +101,7 @@ public void close() {
101101
public CompletableFuture<HttpRequest> sign(
102102
HttpRequest request,
103103
AwsCredentialsIdentity identity,
104-
AuthProperties properties
104+
Context properties
105105
) {
106106
var region = properties.expect(SigV4Settings.REGION);
107107
var name = properties.expect(SigV4Settings.SIGNING_NAME);

0 commit comments

Comments
 (0)