Skip to content

Commit

Permalink
Regenerate iamcredentials client (#4768)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and Praful Makani committed Mar 28, 2019
1 parent 9b0156b commit 00fcb69
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,49 @@ public final UnaryCallable<SignBlobRequest, SignBlobResponse> signBlobCallable()
*
* <pre><code>
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String formattedName = ServiceAccountName.format("[PROJECT]", "[SERVICE_ACCOUNT]");
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List&lt;String&gt; delegates = new ArrayList&lt;&gt;();
* String payload = "";
* SignJwtResponse response = iamCredentialsClient.signJwt(formattedName, delegates, payload);
* SignJwtResponse response = iamCredentialsClient.signJwt(name, delegates, payload);
* }
* </code></pre>
*
* @param name The resource name of the service account for which the credentials are requested,
* in the following format: `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`.
* @param delegates The sequence of service accounts in a delegation chain. Each service account
* must be granted the `roles/iam.serviceAccountTokenCreator` role on its next service account
* in the chain. The last service account in the chain must be granted the
* `roles/iam.serviceAccountTokenCreator` role on the service account that is specified in the
* `name` field of the request.
* <p>The delegates must have the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`
* @param payload The JWT payload to sign: a JSON object that contains a JWT Claims Set.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final SignJwtResponse signJwt(
ServiceAccountName name, List<String> delegates, String payload) {

SignJwtRequest request =
SignJwtRequest.newBuilder()
.setName(name == null ? null : name.toString())
.addAllDelegates(delegates)
.setPayload(payload)
.build();
return signJwt(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Signs a JWT using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre><code>
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List&lt;String&gt; delegates = new ArrayList&lt;&gt;();
* String payload = "";
* SignJwtResponse response = iamCredentialsClient.signJwt(name.toString(), delegates, payload);
* }
* </code></pre>
*
Expand Down Expand Up @@ -609,10 +648,10 @@ public final SignJwtResponse signJwt(String name, List<String> delegates, String
*
* <pre><code>
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String formattedName = ServiceAccountName.format("[PROJECT]", "[SERVICE_ACCOUNT]");
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* String payload = "";
* SignJwtRequest request = SignJwtRequest.newBuilder()
* .setName(formattedName)
* .setName(name.toString())
* .setPayload(payload)
* .build();
* SignJwtResponse response = iamCredentialsClient.signJwt(request);
Expand All @@ -634,10 +673,10 @@ public final SignJwtResponse signJwt(SignJwtRequest request) {
*
* <pre><code>
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String formattedName = ServiceAccountName.format("[PROJECT]", "[SERVICE_ACCOUNT]");
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* String payload = "";
* SignJwtRequest request = SignJwtRequest.newBuilder()
* .setName(formattedName)
* .setName(name.toString())
* .setPayload(payload)
* .build();
* ApiFuture&lt;SignJwtResponse&gt; future = iamCredentialsClient.signJwtCallable().futureCall(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.RequestParamsExtractor;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.iam.credentials.v1.GenerateAccessTokenRequest;
import com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse;
Expand All @@ -32,9 +33,11 @@
import com.google.cloud.iam.credentials.v1.SignBlobResponse;
import com.google.cloud.iam.credentials.v1.SignJwtRequest;
import com.google.cloud.iam.credentials.v1.SignJwtResponse;
import com.google.common.collect.ImmutableMap;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

Expand Down Expand Up @@ -158,19 +161,55 @@ protected GrpcIamCredentialsStub(
generateAccessTokenTransportSettings =
GrpcCallSettings.<GenerateAccessTokenRequest, GenerateAccessTokenResponse>newBuilder()
.setMethodDescriptor(generateAccessTokenMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<GenerateAccessTokenRequest>() {
@Override
public Map<String, String> extract(GenerateAccessTokenRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
}
})
.build();
GrpcCallSettings<GenerateIdTokenRequest, GenerateIdTokenResponse>
generateIdTokenTransportSettings =
GrpcCallSettings.<GenerateIdTokenRequest, GenerateIdTokenResponse>newBuilder()
.setMethodDescriptor(generateIdTokenMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<GenerateIdTokenRequest>() {
@Override
public Map<String, String> extract(GenerateIdTokenRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
}
})
.build();
GrpcCallSettings<SignBlobRequest, SignBlobResponse> signBlobTransportSettings =
GrpcCallSettings.<SignBlobRequest, SignBlobResponse>newBuilder()
.setMethodDescriptor(signBlobMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<SignBlobRequest>() {
@Override
public Map<String, String> extract(SignBlobRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
}
})
.build();
GrpcCallSettings<SignJwtRequest, SignJwtResponse> signJwtTransportSettings =
GrpcCallSettings.<SignJwtRequest, SignJwtResponse>newBuilder()
.setMethodDescriptor(signJwtMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<SignJwtRequest>() {
@Override
public Map<String, String> extract(SignJwtRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
}
})
.build();
GrpcCallSettings<
GenerateIdentityBindingAccessTokenRequest, GenerateIdentityBindingAccessTokenResponse>
Expand All @@ -180,6 +219,16 @@ protected GrpcIamCredentialsStub(
GenerateIdentityBindingAccessTokenResponse>
newBuilder()
.setMethodDescriptor(generateIdentityBindingAccessTokenMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<GenerateIdentityBindingAccessTokenRequest>() {
@Override
public Map<String, String> extract(
GenerateIdentityBindingAccessTokenRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
}
})
.build();

this.generateAccessTokenCallable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,18 @@ public void signJwtTest() {
SignJwtResponse.newBuilder().setKeyId(keyId).setSignedJwt(signedJwt).build();
mockIAMCredentials.addResponse(expectedResponse);

String formattedName = ServiceAccountName.format("[PROJECT]", "[SERVICE_ACCOUNT]");
ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
List<String> delegates = new ArrayList<>();
String payload = "-114";

SignJwtResponse actualResponse = client.signJwt(formattedName, delegates, payload);
SignJwtResponse actualResponse = client.signJwt(name, delegates, payload);
Assert.assertEquals(expectedResponse, actualResponse);

List<GeneratedMessageV3> actualRequests = mockIAMCredentials.getRequests();
Assert.assertEquals(1, actualRequests.size());
SignJwtRequest actualRequest = (SignJwtRequest) actualRequests.get(0);

Assert.assertEquals(formattedName, actualRequest.getName());
Assert.assertEquals(name, ServiceAccountName.parse(actualRequest.getName()));
Assert.assertEquals(delegates, actualRequest.getDelegatesList());
Assert.assertEquals(payload, actualRequest.getPayload());
Assert.assertTrue(
Expand All @@ -258,11 +258,11 @@ public void signJwtExceptionTest() throws Exception {
mockIAMCredentials.addException(exception);

try {
String formattedName = ServiceAccountName.format("[PROJECT]", "[SERVICE_ACCOUNT]");
ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
List<String> delegates = new ArrayList<>();
String payload = "-114";

client.signJwt(formattedName, delegates, payload);
client.signJwt(name, delegates, payload);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
Expand Down
10 changes: 5 additions & 5 deletions google-cloud-clients/google-cloud-iamcredentials/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-03-27T07:47:22.536681Z",
"updateTime": "2019-03-28T07:46:30.745415Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.16.19",
"dockerImage": "googleapis/artman@sha256:70ba28fda87e032ae44e6df41b7fc342c1b0cce1ed90658c4890eb4f613038c2"
"version": "0.16.20",
"dockerImage": "googleapis/artman@sha256:e3c054a2fb85a12481c722af616c7fb6f1d02d862248385eecbec3e4240ebd1e"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "d4d57d766601105478c661132f2687e6984b92d5",
"internalRef": "240469931"
"sha": "6a84b3267b0a95e922608b9891219075047eee29",
"internalRef": "240640999"
}
}
],
Expand Down

0 comments on commit 00fcb69

Please sign in to comment.