Skip to content
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

Diregapic lro #828

Merged
merged 5 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.1.0](https://www.github.com/googleapis/gapic-generator-java/compare/v2.0.1...v2.1.0) (2021-08-17)


### Features

* enable self signed jwt for gapic clients ([#794](https://www.github.com/googleapis/gapic-generator-java/issues/794)) ([1b7ee1e](https://www.github.com/googleapis/gapic-generator-java/commit/1b7ee1e3911e1c8ecab9a94d68d7a59b437d2449))

### [2.0.1](https://www.github.com/googleapis/gapic-generator-java/compare/v2.0.0...v2.0.1) (2021-08-06)


Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jvm_maven_import_external(
# gapic-generator-java dependencies to match the order in googleapis repository,
# which in its turn, prioritizes actual generated clients runtime dependencies
# over the generator dependencies.
_gax_java_version = "2.2.0"
_gax_java_version = "2.3.0"

http_archive(
name = "com_google_api_gax_java",
Expand Down
10 changes: 6 additions & 4 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ def gapic_generator_java_repositories():
_maybe(
http_archive,
name = "com_google_googleapis",
strip_prefix = "googleapis-efecdbf96311bb705d619459280ffc651b10844a",
strip_prefix = "googleapis-ba30d8097582039ac4cc4e21b4e4baa426423075",
urls = [
"https://github.com/googleapis/googleapis/archive/efecdbf96311bb705d619459280ffc651b10844a.zip",
"https://github.com/googleapis/googleapis/archive/ba30d8097582039ac4cc4e21b4e4baa426423075.zip",
],
)

# TODO: replace with upstream googleapis-discovery link once
# https://github.com/googleapis/googleapis-discovery/pull/59 is merged
_maybe(
http_archive,
name = "com_google_googleapis_discovery",
strip_prefix = "googleapis-discovery-abf4cec1ce9e02e4d7d650bf66137c347cdd0d44",
strip_prefix = "googleapis-discovery-2872d382ff767518e63d59ececf5d6f9224b21b4",
urls = [
"https://github.com/googleapis/googleapis-discovery/archive/abf4cec1ce9e02e4d7d650bf66137c347cdd0d44.zip",
"https://github.com/vam-google/googleapis-discovery/archive/2872d382ff767518e63d59ececf5d6f9224b21b4.zip",
],
)

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/api/generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ java_library(
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/util",
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/cloud:extended_operations_java_proto",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/api/generator/ProtoRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.api.ClientProto;
import com.google.api.FieldBehaviorProto;
import com.google.api.ResourceProto;
import com.google.cloud.ExtendedOperationsProto;
import com.google.longrunning.OperationsProto;
import com.google.protobuf.ExtensionRegistry;

Expand All @@ -29,5 +30,6 @@ public static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
ClientProto.registerAllExtensions(extensionRegistry);
ResourceProto.registerAllExtensions(extensionRegistry);
FieldBehaviorProto.registerAllExtensions(extensionRegistry);
ExtendedOperationsProto.registerAllExtensions(extensionRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ public abstract class AbstractServiceStubSettingsClassComposer implements ClassC

protected static final TypeStore FIXED_TYPESTORE = createStaticTypes();

private static final VariableExpr DEFAULT_SERVICE_SCOPES_VAR_EXPR =
createDefaultServiceScopesVarExpr();
private static final VariableExpr NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR =
createNestedUnaryMethodSettingsBuildersVarExpr();
private static final VariableExpr NESTED_RETRYABLE_CODE_DEFINITIONS_VAR_EXPR =
Expand All @@ -150,6 +148,9 @@ public abstract class AbstractServiceStubSettingsClassComposer implements ClassC

private final TransportContext transportContext;

protected static final VariableExpr DEFAULT_SERVICE_SCOPES_VAR_EXPR =
createDefaultServiceScopesVarExpr();

protected AbstractServiceStubSettingsClassComposer(TransportContext transportContext) {
this.transportContext = transportContext;
}
Expand Down Expand Up @@ -197,6 +198,33 @@ public GapicClass generate(GapicContext context, Service service) {
return GapicClass.create(GapicClass.Kind.STUB, classDef);
}

protected MethodDefinition createDefaultCredentialsProviderBuilderMethod() {
TypeNode returnType =
TypeNode.withReference(
ConcreteReference.withClazz(GoogleCredentialsProvider.Builder.class));
MethodInvocationExpr credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(FIXED_TYPESTORE.get("GoogleCredentialsProvider"))
.setMethodName("newBuilder")
.build();
credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(credsProviderBuilderExpr)
.setMethodName("setScopesToApply")
.setArguments(DEFAULT_SERVICE_SCOPES_VAR_EXPR)
.setReturnType(returnType)
.build();
return MethodDefinition.builder()
.setHeaderCommentStatements(
SettingsCommentComposer.DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT)
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setReturnType(returnType)
.setName("defaultCredentialsProviderBuilder")
.setReturnExpr(credsProviderBuilderExpr)
.build();
}

protected abstract MethodDefinition createDefaultTransportTransportProviderBuilderMethod();

protected abstract MethodDefinition createDefaultApiClientHeaderProviderBuilderMethod(
Expand Down Expand Up @@ -992,33 +1020,7 @@ private List<MethodDefinition> createDefaultHelperAndGetterMethods(
.setReturnExpr(DEFAULT_SERVICE_SCOPES_VAR_EXPR)
.build());

// Create the defaultCredentialsProviderBuilder method.
returnType =
TypeNode.withReference(
ConcreteReference.withClazz(GoogleCredentialsProvider.Builder.class));
MethodInvocationExpr credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(FIXED_TYPESTORE.get("GoogleCredentialsProvider"))
.setMethodName("newBuilder")
.build();
credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(credsProviderBuilderExpr)
.setMethodName("setScopesToApply")
.setArguments(DEFAULT_SERVICE_SCOPES_VAR_EXPR)
.setReturnType(returnType)
.build();
javaMethods.add(
MethodDefinition.builder()
.setHeaderCommentStatements(
SettingsCommentComposer.DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT)
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setReturnType(returnType)
.setName("defaultCredentialsProviderBuilder")
.setReturnExpr(credsProviderBuilderExpr)
.build());

javaMethods.add(createDefaultCredentialsProviderBuilderMethod());
javaMethods.add(createDefaultTransportTransportProviderBuilderMethod());
javaMethods.add(createDefaultTransportChannelProviderMethod());
javaMethods.add(createDefaultApiClientHeaderProviderBuilderMethod(service, typeStore));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.generator.gapic.composer.grpc;

import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
Expand All @@ -22,6 +23,7 @@
import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.MethodDefinition;
import com.google.api.generator.engine.ast.MethodInvocationExpr;
import com.google.api.generator.engine.ast.PrimitiveValue;
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.engine.ast.StringObjectValue;
import com.google.api.generator.engine.ast.TypeNode;
Expand Down Expand Up @@ -94,6 +96,47 @@ protected MethodDefinition createDefaultTransportTransportProviderBuilderMethod(
.build();
}

@Override
protected MethodDefinition createDefaultCredentialsProviderBuilderMethod() {
TypeNode returnType =
TypeNode.withReference(
ConcreteReference.withClazz(GoogleCredentialsProvider.Builder.class));
MethodInvocationExpr credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(FIXED_TYPESTORE.get("GoogleCredentialsProvider"))
.setMethodName("newBuilder")
.build();
credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(credsProviderBuilderExpr)
.setMethodName("setScopesToApply")
.setArguments(DEFAULT_SERVICE_SCOPES_VAR_EXPR)
.setReturnType(returnType)
.build();

// This section is specific to GAPIC clients. It sets UseJwtAccessWithScope value to true to
// enable self signed JWT feature.
credsProviderBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(credsProviderBuilderExpr)
.setMethodName("setUseJwtAccessWithScope")
.setArguments(
ValueExpr.withValue(
PrimitiveValue.builder().setType(TypeNode.BOOLEAN).setValue("true").build()))
.setReturnType(returnType)
.build();

return MethodDefinition.builder()
.setHeaderCommentStatements(
SettingsCommentComposer.DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT)
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setReturnType(returnType)
.setName("defaultCredentialsProviderBuilder")
.setReturnExpr(credsProviderBuilderExpr)
.build();
}

@Override
protected MethodDefinition createDefaultApiClientHeaderProviderBuilderMethod(
Service service, TypeStore typeStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic

/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {

/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S

/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {

/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
Expand Down
Loading