-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(iam): Update comments and terminology in IAM samples #13010
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,20 +22,13 @@ def modify_policy_add_member( | |||||
project_id: str, role: str, member: str | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the
Suggested change
|
||||||
) -> policy_pb2.Policy: | ||||||
""" | ||||||
Add a member to certain role in project 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 member need to be added. | ||||||
member: The principals requesting access. | ||||||
|
||||||
Possible format for member: | ||||||
* user:{emailid} | ||||||
* serviceAccount:{emailid} | ||||||
* group:{emailid} | ||||||
* deleted:user:{emailid}?uid={uniqueid} | ||||||
* deleted:serviceAccount:{emailid}?uid={uniqueid} | ||||||
* deleted:group:{emailid}?uid={uniqueid} | ||||||
* domain:{domain} | ||||||
role: role to which principal need to be added. | ||||||
member: The principal requesting access. | ||||||
|
||||||
For principal ID formats, see https://cloud.google.com/iam/docs/principal-identifiers | ||||||
""" | ||||||
policy = get_project_policy(project_id) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,20 +22,13 @@ def modify_policy_remove_member( | |||||
project_id: str, role: str, member: str | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the
Suggested change
|
||||||
) -> policy_pb2.Policy: | ||||||
""" | ||||||
Remove a member from certain role in project policy. | ||||||
Remove a principal from certain role in project policy. | ||||||
|
||||||
project_id: ID or number of the Google Cloud project you want to use. | ||||||
role: role to which member need to be added. | ||||||
member: The principals requesting access. | ||||||
|
||||||
Possible format for member: | ||||||
* user:{emailid} | ||||||
* serviceAccount:{emailid} | ||||||
* group:{emailid} | ||||||
* deleted:user:{emailid}?uid={uniqueid} | ||||||
* deleted:serviceAccount:{emailid}?uid={uniqueid} | ||||||
* deleted:group:{emailid}?uid={uniqueid} | ||||||
* domain:{domain} | ||||||
role: role to revoke. | ||||||
member: The principal to revoke access from. | ||||||
|
||||||
For principal ID formats, see https://cloud.google.com/iam/docs/principal-identifiers | ||||||
""" | ||||||
policy = get_project_policy(project_id) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,28 +19,28 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def quickstart(project_id: str, member: str) -> None: | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a more descriptive docstring, summarizing the steps involved in the quickstart and the purpose of each parameter. For example: """Demonstrates basic IAM operations.
This quickstart shows how to get a project's IAM policy, add a principal to a role, list members of a role, and remove a principal from a role.
Args:
project_id: The ID or number of the Google Cloud project.
member: The principal ID.
"""
Suggested change
|
||||||||||||||||||||||
"""Gets a policy, adds a member, prints their permissions, and removes the member. | ||||||||||||||||||||||
"""Gets a policy, adds a principal, prints their permissions, and removes the principal. | ||||||||||||||||||||||
|
||||||||||||||||||||||
project_id: ID or number of the Google Cloud project you want to use. | ||||||||||||||||||||||
member: The principals requesting the access. | ||||||||||||||||||||||
member: The principal requesting the access. | ||||||||||||||||||||||
""" | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Role to be granted. | ||||||||||||||||||||||
role = "roles/logging.logWriter" | ||||||||||||||||||||||
crm_service = resourcemanager_v3.ProjectsClient() | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Grants your member the 'Log Writer' role for the project. | ||||||||||||||||||||||
# Grants your principal the 'Log Writer' role for the project. | ||||||||||||||||||||||
modify_policy_add_role(crm_service, project_id, role, member) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Gets the project's policy and prints all members with the 'Log Writer' role. | ||||||||||||||||||||||
# Gets the project's policy and prints all principals with the 'Log Writer' role. | ||||||||||||||||||||||
policy = get_policy(crm_service, project_id) | ||||||||||||||||||||||
binding = next(b for b in policy.bindings if b.role == role) | ||||||||||||||||||||||
print(f"Role: {(binding.role)}") | ||||||||||||||||||||||
print("Members: ") | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Google Python Style Guide, prefer using |
||||||||||||||||||||||
for m in binding.members: | ||||||||||||||||||||||
print(f"[{m}]") | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Removes the member from the 'Log Writer' role. | ||||||||||||||||||||||
# Removes the principal from the 'Log Writer' role. | ||||||||||||||||||||||
modify_policy_remove_member(crm_service, project_id, role, member) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -115,7 +115,8 @@ def modify_policy_remove_member( | |||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||
# TODO: replace with your project ID | ||||||||||||||||||||||
project_id = "your-project-id" | ||||||||||||||||||||||
# TODO: Replace with the ID of your member in the form 'user:[email protected]'. | ||||||||||||||||||||||
member = "your-member" | ||||||||||||||||||||||
# TODO: Replace with the ID of your principal. | ||||||||||||||||||||||
# For examples, see https://cloud.google.com/iam/docs/principal-identifiers | ||||||||||||||||||||||
Comment on lines
+118
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the placeholder comment to reflect the change from "member" to "principal". Per Google Python Style Guide, use a complete sentence in your comment.
Suggested change
|
||||||||||||||||||||||
member = "your-principal" | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the variable name to |
||||||||||||||||||||||
quickstart(project_id, member) | ||||||||||||||||||||||
# [END iam_quickstart] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the Google Python Style Guide, there should be two blank lines between top-level functions. Consider adding an extra blank line here.