|
| 1 | +/* |
| 2 | + * Copyright 2022 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.asset; |
| 18 | + |
| 19 | +// [START asset_quickstart_batch_get_effective_iam_policy] |
| 20 | +// Imports the Google Cloud client library |
| 21 | + |
| 22 | +import com.google.api.gax.rpc.ApiException; |
| 23 | +import com.google.cloud.asset.v1.AssetServiceClient; |
| 24 | +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesRequest; |
| 25 | +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesResponse; |
| 26 | +import java.io.IOException; |
| 27 | +import java.util.Arrays; |
| 28 | + |
| 29 | +/** Batch get effective iam policy example. */ |
| 30 | +public class BatchGetEffectiveIamPolicyExample { |
| 31 | + |
| 32 | + /** |
| 33 | + * Batch get effective iam policies specified list of resources within accessible scope, such as a |
| 34 | + * project, folder or organization. |
| 35 | + * |
| 36 | + * @param resourceNames a string array denoting full resource names. |
| 37 | + * @param scope a string denoting scope, which can be a Project, Folder or Organization. |
| 38 | + */ |
| 39 | + public static void batchGetEffectiveIamPolicies(String[] resourceNames, String scope) { |
| 40 | + BatchGetEffectiveIamPoliciesRequest request = |
| 41 | + BatchGetEffectiveIamPoliciesRequest.newBuilder() |
| 42 | + .setScope(scope) |
| 43 | + .addAllNames(Arrays.asList(resourceNames)) |
| 44 | + .build(); |
| 45 | + try (AssetServiceClient client = AssetServiceClient.create()) { |
| 46 | + BatchGetEffectiveIamPoliciesResponse response = client.batchGetEffectiveIamPolicies(request); |
| 47 | + System.out.println("BatchGetEffectiveIamPolicies completed successfully:\n" + response); |
| 48 | + } catch (IOException e) { |
| 49 | + System.out.println("Failed to create client:\n" + e); |
| 50 | + } catch (ApiException e) { |
| 51 | + System.out.println("Error during BatchGetEffectiveIamPolicies:\n" + e); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | +// [END asset_quickstart_batch_get_effective_iam_policy] |
0 commit comments