Skip to content

Commit cd176e4

Browse files
committed
Fixup 12494: Remove Authz specific abstractions away from the generic headermutations libraries
1 parent 7d3c255 commit cd176e4

File tree

6 files changed

+103
-190
lines changed

6 files changed

+103
-190
lines changed

xds/src/main/java/io/grpc/xds/internal/headermutations/HeaderMutationFilter.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import com.google.common.collect.ImmutableList;
2020
import io.grpc.xds.internal.grpcservice.HeaderValueValidationUtils;
21-
import io.grpc.xds.internal.headermutations.HeaderMutations.RequestHeaderMutations;
22-
import io.grpc.xds.internal.headermutations.HeaderMutations.ResponseHeaderMutations;
2321
import java.util.Collection;
2422
import java.util.Optional;
2523
import java.util.function.Predicate;
@@ -48,18 +46,12 @@ public HeaderMutationFilter(Optional<HeaderMutationRulesConfig> mutationRules) {
4846
*/
4947
public HeaderMutations filter(HeaderMutations mutations)
5048
throws HeaderMutationDisallowedException {
51-
ImmutableList<HeaderValueOption> allowedRequestHeaders =
52-
filterCollection(mutations.requestMutations().headers(),
53-
this::shouldIgnore, this::isHeaderMutationAllowed);
54-
ImmutableList<String> allowedRequestHeadersToRemove =
55-
filterCollection(mutations.requestMutations().headersToRemove(),
56-
this::shouldIgnore, this::isHeaderMutationAllowed);
57-
ImmutableList<HeaderValueOption> allowedResponseHeaders =
58-
filterCollection(mutations.responseMutations().headers(),
59-
this::shouldIgnore, this::isHeaderMutationAllowed);
60-
return HeaderMutations.create(
61-
RequestHeaderMutations.create(allowedRequestHeaders, allowedRequestHeadersToRemove),
62-
ResponseHeaderMutations.create(allowedResponseHeaders));
49+
ImmutableList<HeaderValueOption> allowedHeaders =
50+
filterCollection(mutations.headers(), this::shouldIgnore, this::isHeaderMutationAllowed);
51+
ImmutableList<String> allowedHeadersToRemove =
52+
filterCollection(mutations.headersToRemove(), this::shouldIgnore,
53+
this::isHeaderMutationAllowed);
54+
return HeaderMutations.create(allowedHeaders, allowedHeadersToRemove);
6355
}
6456

6557
/**

xds/src/main/java/io/grpc/xds/internal/headermutations/HeaderMutations.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,16 @@
1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.collect.ImmutableList;
2121

22-
/** A collection of header mutations for both request and response headers. */
22+
/** A collection of header mutations. */
2323
@AutoValue
2424
public abstract class HeaderMutations {
2525

26-
public static HeaderMutations create(RequestHeaderMutations requestMutations,
27-
ResponseHeaderMutations responseMutations) {
28-
return new AutoValue_HeaderMutations(requestMutations, responseMutations);
26+
public static HeaderMutations create(ImmutableList<HeaderValueOption> headers,
27+
ImmutableList<String> headersToRemove) {
28+
return new AutoValue_HeaderMutations(headers, headersToRemove);
2929
}
3030

31-
public abstract RequestHeaderMutations requestMutations();
31+
public abstract ImmutableList<HeaderValueOption> headers();
3232

33-
public abstract ResponseHeaderMutations responseMutations();
34-
35-
/** Represents mutations for request headers. */
36-
@AutoValue
37-
public abstract static class RequestHeaderMutations {
38-
public static RequestHeaderMutations create(ImmutableList<HeaderValueOption> headers,
39-
ImmutableList<String> headersToRemove) {
40-
return new AutoValue_HeaderMutations_RequestHeaderMutations(headers, headersToRemove);
41-
}
42-
43-
public abstract ImmutableList<HeaderValueOption> headers();
44-
45-
public abstract ImmutableList<String> headersToRemove();
46-
}
47-
48-
/** Represents mutations for response headers. */
49-
@AutoValue
50-
public abstract static class ResponseHeaderMutations {
51-
public static ResponseHeaderMutations create(ImmutableList<HeaderValueOption> headers) {
52-
return new AutoValue_HeaderMutations_ResponseHeaderMutations(headers);
53-
}
54-
55-
public abstract ImmutableList<HeaderValueOption> headers();
56-
}
33+
public abstract ImmutableList<String> headersToRemove();
5734
}

xds/src/main/java/io/grpc/xds/internal/headermutations/HeaderMutator.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import io.grpc.Metadata;
2121
import io.grpc.xds.internal.grpcservice.HeaderValue;
22-
import io.grpc.xds.internal.headermutations.HeaderMutations.RequestHeaderMutations;
23-
import io.grpc.xds.internal.headermutations.HeaderMutations.ResponseHeaderMutations;
2422
import io.grpc.xds.internal.headermutations.HeaderValueOption.HeaderAppendAction;
2523
import java.util.logging.Logger;
2624

@@ -47,7 +45,7 @@ public static HeaderMutator create() {
4745
* @param mutations The header mutations to apply.
4846
* @param headers The metadata headers to which the mutations will be applied.
4947
*/
50-
public void applyRequestMutations(final RequestHeaderMutations mutations, Metadata headers) {
48+
public void applyMutations(final HeaderMutations mutations, Metadata headers) {
5149
// TODO(sauravzg): The specification is not clear on order of header removals and additions.
5250
// in case of conflicts. Copying the order from Envoy here, which does removals at the end.
5351
applyHeaderUpdates(mutations.headers(), headers);
@@ -56,16 +54,6 @@ public void applyRequestMutations(final RequestHeaderMutations mutations, Metada
5654
}
5755
}
5856

59-
/**
60-
* Applies the given header mutations to the provided metadata headers.
61-
*
62-
* @param mutations The header mutations to apply.
63-
* @param headers The metadata headers to which the mutations will be applied.
64-
*/
65-
public void applyResponseMutations(final ResponseHeaderMutations mutations, Metadata headers) {
66-
applyHeaderUpdates(mutations.headers(), headers);
67-
}
68-
6957
private void applyHeaderUpdates(final Iterable<HeaderValueOption> headerOptions,
7058
Metadata headers) {
7159
for (HeaderValueOption headerOption : headerOptions) {

0 commit comments

Comments
 (0)