Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 11160b0

Browse files
feat: add batchGetEffectiveIamPolicies sample code. (#654)
* feat: add batchGetEffectiveIamPolicies sample code. Add batchGetEffectiveIamPolicies sample code and also lint the protobuf imports. * chore: fix the Copyright year for getBatchEffectiveIamPolicies.js * chore: refactor logging and remove loop for checking results * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: modify the logging to print nested Object. Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent af56ac6 commit 11160b0

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-asset/tree/
102102
| Export Assets | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/exportAssets.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/exportAssets.js,samples/README.md) |
103103
| Export Assets To BigQuery | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/exportAssetsBigquery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/exportAssetsBigquery.js,samples/README.md) |
104104
| Get Batch Asset History | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/getBatchAssetHistory.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/getBatchAssetHistory.js,samples/README.md) |
105+
| Batch Get Effective Iam Policies | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/getBatchEffectiveIamPolicies.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/getBatchEffectiveIamPolicies.js,samples/README.md) |
105106
| Get Feed | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/getFeed.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/getFeed.js,samples/README.md) |
106107
| List Assets | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/listAssets.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/listAssets.js,samples/README.md) |
107108
| List Feeds | [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/listFeeds.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/listFeeds.js,samples/README.md) |

samples/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [Export Assets](#export-assets)
2121
* [Export Assets To BigQuery](#export-assets-to-bigquery)
2222
* [Get Batch Asset History](#get-batch-asset-history)
23+
* [Batch Get Effective Iam Policies](#batch-get-effective-iam-policies)
2324
* [Get Feed](#get-feed)
2425
* [List Assets](#list-assets)
2526
* [List Feeds](#list-feeds)
@@ -195,6 +196,25 @@ __Usage:__
195196

196197

197198

199+
### Batch Get Effective Iam Policies
200+
201+
Batch get effective IAM policies that match a request.
202+
203+
View the [source code](https://github.com/googleapis/nodejs-asset/blob/main/samples/getBatchEffectiveIamPolicies.js).
204+
205+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-asset&page=editor&open_in_editor=samples/getBatchEffectiveIamPolicies.js,samples/README.md)
206+
207+
__Usage:__
208+
209+
210+
`node batchGetEffectiveIamPolicies`
211+
212+
213+
-----
214+
215+
216+
217+
198218
### Get Feed
199219

200220
Get Feed.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// sample-metadata:
18+
// title: Batch Get Effective Iam Policies
19+
// description: Batch get effective IAM policies that match a request.
20+
// usage: node batchGetEffectiveIamPolicies
21+
22+
async function main(assetNames) {
23+
// [START asset_quickstart_batch_get_effective_iam_policies]
24+
const {AssetServiceClient} = require('@google-cloud/asset');
25+
26+
const client = new AssetServiceClient();
27+
28+
async function batchGetEffectiveIamPolicies() {
29+
const projectId = await client.getProjectId();
30+
const request = {
31+
scope: `projects/${projectId}`,
32+
names: assetNames.split(','),
33+
};
34+
35+
// Handle the operation using the promise pattern.
36+
const result = await client.batchGetEffectiveIamPolicies(request);
37+
// Handle the response.
38+
console.dir(result, {depth: null});
39+
}
40+
// [END asset_quickstart_batch_get_effective_iam_policies]
41+
batchGetEffectiveIamPolicies();
42+
}
43+
44+
process.on('unhandledRejection', err => {
45+
console.error(err.message);
46+
process.exitCode = 1;
47+
});
48+
main(...process.argv.slice(2));

samples/test/sample.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ describe('quickstart sample tests', () => {
186186
assert.include(stdout, 'relatedAsset');
187187
});
188188

189+
it('should get effective iam policies successfully', async () => {
190+
const assetName = `//storage.googleapis.com/${bucketName}`;
191+
const stdout = execSync(`node getBatchEffectiveIamPolicies ${assetName}`);
192+
assert.include(stdout, assetName);
193+
});
194+
189195
it('should analyze iam policy successfully', async () => {
190196
const stdout = execSync('node analyzeIamPolicy');
191197
assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects');

0 commit comments

Comments
 (0)