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

feat: enable self signed JWT for http #850

Merged
merged 4 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ protected MethodDefinition createDefaultCredentialsProviderBuilderMethod() {
.setArguments(DEFAULT_SERVICE_SCOPES_VAR_EXPR)
.setReturnType(returnType)
.build();
// enable self signed JWT.
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@

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;
import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.Expr;
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.TypeNode;
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.comment.SettingsCommentComposer;
import com.google.api.generator.gapic.composer.common.AbstractServiceStubSettingsClassComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.model.Service;
Expand Down Expand Up @@ -74,47 +69,6 @@ protected Expr initializeTransportProviderBuilder(
.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 List<MethodDefinition> createApiClientHeaderProviderBuilderMethods(
Service service, TypeStore typeStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>

/** 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 @@ -287,7 +287,9 @@ public static List<String> getDefaultServiceScopes() {

/** 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 @@ -125,7 +125,9 @@ public static List<String> getDefaultServiceScopes() {

/** 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