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

feat: add batchGetEffectiveIamPolicies sample code. #654

Merged
merged 9 commits into from
Sep 2, 2022
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-asset/tree/
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
Expand Down
20 changes: 20 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Export Assets](#export-assets)
* [Export Assets To BigQuery](#export-assets-to-bigquery)
* [Get Batch Asset History](#get-batch-asset-history)
* [Batch Get Effective Iam Policies](#batch-get-effective-iam-policies)
* [Get Feed](#get-feed)
* [List Assets](#list-assets)
* [List Feeds](#list-feeds)
Expand Down Expand Up @@ -195,6 +196,25 @@ __Usage:__



### Batch Get Effective Iam Policies

Batch get effective IAM policies that match a request.

View the [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)

__Usage:__


`node batchGetEffectiveIamPolicies`


-----




### Get Feed

Get Feed.
Expand Down
48 changes: 48 additions & 0 deletions samples/getBatchEffectiveIamPolicies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// sample-metadata:
// title: Batch Get Effective Iam Policies
// description: Batch get effective IAM policies that match a request.
// usage: node batchGetEffectiveIamPolicies

async function main(assetNames) {
// [START asset_quickstart_batch_get_effective_iam_policies]
const {AssetServiceClient} = require('@google-cloud/asset');

const client = new AssetServiceClient();

async function batchGetEffectiveIamPolicies() {
const projectId = await client.getProjectId();
const request = {
scope: `projects/${projectId}`,
names: assetNames.split(','),
};

// Handle the operation using the promise pattern.
const result = await client.batchGetEffectiveIamPolicies(request);
// Handle the the response.
console.dir(result);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, let's add {depth: null} here

Suggested change
console.dir(result);
console.dir(result, {depth: null});

}
// [END asset_quickstart_batch_get_effective_iam_policies]
batchGetEffectiveIamPolicies();
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
6 changes: 6 additions & 0 deletions samples/test/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ describe('quickstart sample tests', () => {
assert.include(stdout, 'relatedAsset');
});

it('should get effective iam policies successfully', async () => {
const assetName = `//storage.googleapis.com/${bucketName}`;
const stdout = execSync(`node getBatchEffectiveIamPolicies ${assetName}`);
assert.include(stdout, assetName);
});

it('should analyze iam policy successfully', async () => {
const stdout = execSync('node analyzeIamPolicy');
assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects');
Expand Down