-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): add batch_get_effective_iam_policies sample code (#480)
- Loading branch information
1 parent
094e6d9
commit a08ab03
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
asset/snippets/snippets/quickstart_batchgeteffectiveiampolicy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2022 Google LLC. All Rights Reserved. | ||
# | ||
# 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. | ||
|
||
|
||
import argparse | ||
|
||
|
||
def batch_get_effective_iam_policies(resource_names, scope): | ||
# [START asset_quickstart_batch_get_effective_iam_policies] | ||
from google.cloud import asset_v1 | ||
|
||
# TODO scope = 'Scope for resource names' | ||
# TODO resource_names = 'List of resource names' | ||
|
||
client = asset_v1.AssetServiceClient() | ||
|
||
response = client.batch_get_effective_iam_policies( | ||
request={"scope": scope, "names": resource_names} | ||
) | ||
print(response) | ||
# [END asset_quickstart_batch_get_effective_iam_policies] | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter | ||
) | ||
parser.add_argument("resource_names", help="Your specified accessible " | ||
"scope, such as a project, " | ||
"folder or organization") | ||
parser.add_argument("scope", help="Your specified list of resource names") | ||
|
||
args = parser.parse_args() | ||
|
||
batch_get_effective_iam_policies(args.resource_names, args.scope) |
31 changes: 31 additions & 0 deletions
31
asset/snippets/snippets/quickstart_batchgeteffectiveiampolicy_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
|
||
# 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. | ||
|
||
import os | ||
|
||
import quickstart_batchgeteffectiveiampolicy | ||
|
||
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] | ||
|
||
|
||
def test_batch_get_effective_iam_policies(capsys): | ||
scope = "projects/{}".format(PROJECT) | ||
resource_names = [ | ||
"//cloudresourcemanager.googleapis.com/projects/{}".format(PROJECT)] | ||
quickstart_batchgeteffectiveiampolicy.batch_get_effective_iam_policies( | ||
resource_names, scope) | ||
out, _ = capsys.readouterr() | ||
assert resource_names[0] in out |