Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
feat: generate sample code in the Java microgenerator (#349)
Browse files Browse the repository at this point in the history
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/83d27b1b-599d-4795-9959-95d65d1baad5/targets

- [ ] To automatically regenerate this PR, check this box.

PiperOrigin-RevId: 356341083
Source-Link: googleapis/googleapis@8d8c008
  • Loading branch information
yoshi-automation authored Feb 9, 2021
1 parent cb66cfa commit af41579
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List<String> delegates = new ArrayList<>();
* List<String> scope = new ArrayList<>();
* Duration lifetime = Duration.newBuilder().build();
* GenerateAccessTokenResponse response =
* iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
* }
* }</pre>
*
* <p>Note: close() needs to be called on the IamCredentialsClient object to clean up resources such
* as threads. In the example above, try-with-resources is used, which automatically calls close().
*
Expand Down Expand Up @@ -145,6 +156,19 @@ public IamCredentialsStub getStub() {
/**
* Generates an OAuth 2.0 access token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List<String> delegates = new ArrayList<>();
* List<String> scope = new ArrayList<>();
* Duration lifetime = Duration.newBuilder().build();
* GenerateAccessTokenResponse response =
* iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -181,6 +205,19 @@ public final GenerateAccessTokenResponse generateAccessToken(
/**
* Generates an OAuth 2.0 access token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
* List<String> delegates = new ArrayList<>();
* List<String> scope = new ArrayList<>();
* Duration lifetime = Duration.newBuilder().build();
* GenerateAccessTokenResponse response =
* iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -217,6 +254,21 @@ public final GenerateAccessTokenResponse generateAccessToken(
/**
* Generates an OAuth 2.0 access token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* GenerateAccessTokenRequest request =
* GenerateAccessTokenRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .addAllScope(new ArrayList<String>())
* .setLifetime(Duration.newBuilder().build())
* .build();
* GenerateAccessTokenResponse response = iamCredentialsClient.generateAccessToken(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -229,6 +281,22 @@ public final GenerateAccessTokenResponse generateAccessToken(GenerateAccessToken
* Generates an OAuth 2.0 access token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* GenerateAccessTokenRequest request =
* GenerateAccessTokenRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .addAllScope(new ArrayList<String>())
* .setLifetime(Duration.newBuilder().build())
* .build();
* ApiFuture<GenerateAccessTokenResponse> future =
* iamCredentialsClient.generateAccessTokenCallable().futureCall(request);
* // Do something.
* GenerateAccessTokenResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<GenerateAccessTokenRequest, GenerateAccessTokenResponse>
generateAccessTokenCallable() {
Expand All @@ -239,6 +307,19 @@ public final GenerateAccessTokenResponse generateAccessToken(GenerateAccessToken
/**
* Generates an OpenID Connect ID token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List<String> delegates = new ArrayList<>();
* String audience = "audience975628804";
* boolean includeEmail = true;
* GenerateIdTokenResponse response =
* iamCredentialsClient.generateIdToken(name, delegates, audience, includeEmail);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -273,6 +354,19 @@ public final GenerateIdTokenResponse generateIdToken(
/**
* Generates an OpenID Connect ID token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
* List<String> delegates = new ArrayList<>();
* String audience = "audience975628804";
* boolean includeEmail = true;
* GenerateIdTokenResponse response =
* iamCredentialsClient.generateIdToken(name, delegates, audience, includeEmail);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -307,6 +401,21 @@ public final GenerateIdTokenResponse generateIdToken(
/**
* Generates an OpenID Connect ID token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* GenerateIdTokenRequest request =
* GenerateIdTokenRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setAudience("audience975628804")
* .setIncludeEmail(true)
* .build();
* GenerateIdTokenResponse response = iamCredentialsClient.generateIdToken(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -319,6 +428,22 @@ public final GenerateIdTokenResponse generateIdToken(GenerateIdTokenRequest requ
* Generates an OpenID Connect ID token for a service account.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* GenerateIdTokenRequest request =
* GenerateIdTokenRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setAudience("audience975628804")
* .setIncludeEmail(true)
* .build();
* ApiFuture<GenerateIdTokenResponse> future =
* iamCredentialsClient.generateIdTokenCallable().futureCall(request);
* // Do something.
* GenerateIdTokenResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<GenerateIdTokenRequest, GenerateIdTokenResponse>
generateIdTokenCallable() {
Expand All @@ -329,6 +454,17 @@ public final GenerateIdTokenResponse generateIdToken(GenerateIdTokenRequest requ
/**
* Signs a blob 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<String> delegates = new ArrayList<>();
* ByteString payload = ByteString.EMPTY;
* SignBlobResponse response = iamCredentialsClient.signBlob(name, delegates, payload);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -359,6 +495,17 @@ public final SignBlobResponse signBlob(
/**
* Signs a blob using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
* List<String> delegates = new ArrayList<>();
* ByteString payload = ByteString.EMPTY;
* SignBlobResponse response = iamCredentialsClient.signBlob(name, delegates, payload);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -388,6 +535,20 @@ public final SignBlobResponse signBlob(String name, List<String> delegates, Byte
/**
* Signs a blob using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* SignBlobRequest request =
* SignBlobRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setPayload(ByteString.EMPTY)
* .build();
* SignBlobResponse response = iamCredentialsClient.signBlob(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -400,6 +561,21 @@ public final SignBlobResponse signBlob(SignBlobRequest request) {
* Signs a blob using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* SignBlobRequest request =
* SignBlobRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setPayload(ByteString.EMPTY)
* .build();
* ApiFuture<SignBlobResponse> future =
* iamCredentialsClient.signBlobCallable().futureCall(request);
* // Do something.
* SignBlobResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<SignBlobRequest, SignBlobResponse> signBlobCallable() {
return stub.signBlobCallable();
Expand All @@ -409,6 +585,17 @@ public final UnaryCallable<SignBlobRequest, SignBlobResponse> signBlobCallable()
/**
* 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<String> delegates = new ArrayList<>();
* String payload = "payload-786701938";
* SignJwtResponse response = iamCredentialsClient.signJwt(name, delegates, payload);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -439,6 +626,17 @@ public final SignJwtResponse signJwt(
/**
* Signs a JWT using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
* List<String> delegates = new ArrayList<>();
* String payload = "payload-786701938";
* SignJwtResponse response = iamCredentialsClient.signJwt(name, delegates, payload);
* }
* }</pre>
*
* @param name Required. The resource name of the service account for which the credentials are
* requested, in the following format:
* `projects/-/serviceAccounts/{ACCOUNT_EMAIL_OR_UNIQUEID}`. The `-` wildcard character is
Expand Down Expand Up @@ -468,6 +666,20 @@ public final SignJwtResponse signJwt(String name, List<String> delegates, String
/**
* Signs a JWT using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* SignJwtRequest request =
* SignJwtRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setPayload("payload-786701938")
* .build();
* SignJwtResponse response = iamCredentialsClient.signJwt(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -480,6 +692,21 @@ public final SignJwtResponse signJwt(SignJwtRequest request) {
* Signs a JWT using a service account's system-managed private key.
*
* <p>Sample code:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* SignJwtRequest request =
* SignJwtRequest.newBuilder()
* .setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString())
* .addAllDelegates(new ArrayList<String>())
* .setPayload("payload-786701938")
* .build();
* ApiFuture<SignJwtResponse> future =
* iamCredentialsClient.signJwtCallable().futureCall(request);
* // Do something.
* SignJwtResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<SignJwtRequest, SignJwtResponse> signJwtCallable() {
return stub.signJwtCallable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
* self-signed JSON Web Tokens (JWTs), and more.
*
* <p>Sample for IamCredentialsClient:
*
* <pre>{@code
* try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
* ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
* List<String> delegates = new ArrayList<>();
* List<String> scope = new ArrayList<>();
* Duration lifetime = Duration.newBuilder().build();
* GenerateAccessTokenResponse response =
* iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
* }
* }</pre>
*/
@Generated("by gapic-generator-java")
package com.google.cloud.iam.credentials.v1;
Expand Down
6 changes: 3 additions & 3 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/java-iamcredentials.git",
"sha": "c0d9424500f8e8def1cedd123cc56012f86020b1"
"sha": "cb66cfad97863983d5fb35a122c9925e7d06908b"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "91e206bcfeaf8948ea03fe3cb1b7616108496cd3",
"internalRef": "350949863"
"sha": "8d8c008e56f1af31d57f75561e0f1848ffb29eeb",
"internalRef": "356341083"
}
},
{
Expand Down

0 comments on commit af41579

Please sign in to comment.