Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions iam/cloud-client/snippets/modify_policy_add_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@


def modify_policy_add_member(
project_id: str, role: str, member: str
project_id: str, role: str, principal: str
Copy link

Choose a reason for hiding this comment

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

low

Per the Google Python Style Guide, there should be two blank lines between top-level functions. Add a blank line after the import statements to improve readability.

22:

) -> policy_pb2.Policy:
"""
Add a principal to certain role in project policy.

project_id: ID or number of the Google Cloud project you want to use.
role: role to which principal need to be added.
member: The principal requesting access.
principal: The principal requesting access.

For principal ID formats, see https://cloud.google.com/iam/docs/principal-identifiers
"""
policy = get_project_policy(project_id)

for bind in policy.bindings:
if bind.role == role:
bind.members.append(member)
bind.members.append(principal)
break

return set_project_policy(project_id, policy)
Expand All @@ -52,4 +52,4 @@ def modify_policy_add_member(
role = "roles/viewer"
member = f"serviceAccount:test-service-account@{project_id}.iam.gserviceaccount.com"

modify_policy_add_member(project_id, role, member)
modify_policy_add_member(project_id, role, principal)
Copy link

Choose a reason for hiding this comment

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

high

The variable principal is not defined in this scope. It seems like this should be member based on the previous version of the code. Consider renaming member to principal consistently throughout the code if that's the intended change.

55:    modify_policy_add_member(project_id, role, member)