Skip to content

Commit

Permalink
[ggj][iam] feat: handle IAM RPCs in pubsub and KMS APIs (#482)
Browse files Browse the repository at this point in the history
* fix: swap assertEquals args in JavaWriterVisitorTest to match (expected, actusl) order

* fix: swap assertEquals args in ImportWriterVisitorTest to match (expected, actusl) order

* fix: add node validator to refactor/centralize null element checks

* test: update logging integration goldens with gapic.yaml

* feat!: remove gapic.yaml from Bazel and input interface

* feat!: remove all per-RPC batching codegen logic

* fix: update tests

* fix: handle wildcard-only resource_reference

* fix: make service.yaml optional

* fix: remove iam, longrunning from codegen for all non-iam,longrunning APIs

* feat: handle IAM RPCs in pubsub and KMS APIs
  • Loading branch information
miraleung authored Nov 12, 2020
1 parent 4940e77 commit e1b0a66
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -96,6 +98,13 @@ public class GrpcServiceStubClassComposer implements ClassComposer {

private static final Map<String, TypeNode> STATIC_TYPES = createStaticTypes();

// Legacy support for the original reroute_to_grpc_interface option in gapic.yaml. These two APIs
// predate the modern way, which is to add the RPCs directly into the proto.
private static final Set<String> REROUTE_TO_GRPC_INTERFACE_SERVICE_ALLOWLIST =
new HashSet<>(Arrays.asList("google.cloud.kms.v1", "google.pubsub.v1"));
private static final Set<String> REROUTE_TO_GRPC_INTERFACE_IAM_METHOD_ALLOWLIST =
new HashSet<>(Arrays.asList("SetIamPolicy", "GetIamPolicy", "TestIamPermissions"));

private GrpcServiceStubClassComposer() {}

public static GrpcServiceStubClassComposer instance() {
Expand Down Expand Up @@ -218,8 +227,7 @@ private static Statement createMethodDescriptorVariableDecl(
.apply("setType", getMethodDescriptorMethodTypeExpr(protoMethod))
.apply(methodDescriptorMaker);

String codeMethodNameArg =
String.format("%s.%s/%s", service.protoPakkage(), service.name(), protoMethod.name());
String codeMethodNameArg = getProtoRpcFullMethodName(service, protoMethod);
methodDescriptorMaker =
methodMakerFn
.apply(
Expand Down Expand Up @@ -1106,6 +1114,17 @@ private static EnumRefExpr getMethodDescriptorMethodTypeExpr(Method protoMethod)
.build();
}

private static String getProtoRpcFullMethodName(Service protoService, Method protoMethod) {
if (!REROUTE_TO_GRPC_INTERFACE_SERVICE_ALLOWLIST.contains(protoService.protoPakkage())
|| !REROUTE_TO_GRPC_INTERFACE_IAM_METHOD_ALLOWLIST.contains(protoMethod.name())) {
return String.format(
"%s.%s/%s", protoService.protoPakkage(), protoService.name(), protoMethod.name());
}
// This is meant to be a temporary workaround until the allow-listed services come up with a
// long-term solution.
return String.format("google.iam.v1.IAMPolicy/%s", protoMethod.name());
}

private static String getThisClassName(String serviceName) {
return String.format(CLASS_NAME_PATTERN, serviceName);
}
Expand Down

0 comments on commit e1b0a66

Please sign in to comment.