Skip to content

Commit e0f4257

Browse files
docs(samples): add batch_get_effective_iam_policies sample code (#480)
1 parent 76c0765 commit e0f4257

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2022 Google LLC. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
import argparse
19+
20+
21+
def batch_get_effective_iam_policies(resource_names, scope):
22+
# [START asset_quickstart_batch_get_effective_iam_policies]
23+
from google.cloud import asset_v1
24+
25+
# TODO scope = 'Scope for resource names'
26+
# TODO resource_names = 'List of resource names'
27+
28+
client = asset_v1.AssetServiceClient()
29+
30+
response = client.batch_get_effective_iam_policies(
31+
request={"scope": scope, "names": resource_names}
32+
)
33+
print(response)
34+
# [END asset_quickstart_batch_get_effective_iam_policies]
35+
36+
37+
if __name__ == "__main__":
38+
parser = argparse.ArgumentParser(
39+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
40+
)
41+
parser.add_argument("resource_names", help="Your specified accessible "
42+
"scope, such as a project, "
43+
"folder or organization")
44+
parser.add_argument("scope", help="Your specified list of resource names")
45+
46+
args = parser.parse_args()
47+
48+
batch_get_effective_iam_policies(args.resource_names, args.scope)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2022 Google LLC.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
19+
import quickstart_batchgeteffectiveiampolicy
20+
21+
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
22+
23+
24+
def test_batch_get_effective_iam_policies(capsys):
25+
scope = "projects/{}".format(PROJECT)
26+
resource_names = [
27+
"//cloudresourcemanager.googleapis.com/projects/{}".format(PROJECT)]
28+
quickstart_batchgeteffectiveiampolicy.batch_get_effective_iam_policies(
29+
resource_names, scope)
30+
out, _ = capsys.readouterr()
31+
assert resource_names[0] in out

0 commit comments

Comments
 (0)