Skip to content

Commit

Permalink
samples: Refactor the sample test to avoid direct reference the Analy…
Browse files Browse the repository at this point in the history
…zeIamPolicyLongrunning metadata field (#829)

* Refactor to remove the direct reference to the metadata field of AnalyzeIamPolicyLongrunning operation.

* Refactor to remove the direct reference to the metadata field of AnalyzeIamPolicyLongrunning operation for Bigquery, also reformat the file.
  • Loading branch information
aaronlichen-hp authored Aug 10, 2021
1 parent eb60b17 commit 7f5dbe7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package com.example.asset;

// [START asset_quickstart_analyze_iam_policy_longrunning_bigquery]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest;
import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse;
import com.google.cloud.asset.v1.AssetServiceClient;
import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig;
import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.BigQueryDestination;
Expand Down Expand Up @@ -71,9 +69,9 @@ public static void analyzeIamPolicyLongrunning(
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
OperationFuture<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest>
future = client.analyzeIamPolicyLongrunningAsync(request);
System.out.println("Analyze completed successfully:\n" + future.getMetadata().get());
System.out.println(
"Analyze completed successfully:\n"
+ client.analyzeIamPolicyLongrunningAsync(request).getMetadata().get());
} catch (IOException e) {
System.out.println("Failed to create client:\n" + e.toString());
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package com.example.asset;

// [START asset_quickstart_analyze_iam_policy_longrunning_gcs]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest;
import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse;
import com.google.cloud.asset.v1.AssetServiceClient;
import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig;
import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.GcsDestination;
Expand Down Expand Up @@ -69,9 +67,9 @@ public static void analyzeIamPolicyLongrunning(
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
OperationFuture<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest>
future = client.analyzeIamPolicyLongrunningAsync(request);
System.out.println("Analyze completed successfully:\n" + future.getMetadata().get());
System.out.println(
"Analyze completed successfully:\n"
+ client.analyzeIamPolicyLongrunningAsync(request).getMetadata().get());
} catch (IOException e) {
System.out.println("Failed to create client:\n" + e.toString());
} catch (InterruptedException e) {
Expand Down

0 comments on commit 7f5dbe7

Please sign in to comment.