Skip to content

Commit

Permalink
Update quickstart.go comments
Browse files Browse the repository at this point in the history
Includes changing "member" to "principal" and linking to principal identifiers page instead of specifying recommended format.
  • Loading branch information
melaniedejong authored Dec 20, 2024
1 parent 3744b4e commit c458e1e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions iam/quickstart/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
func main() {
// TODO: Add your project ID
projectID := flag.String("project_id", "", "Cloud Project ID")
// TODO: Add the ID of your member in the form "user:[email protected]"
member := flag.String("member_id", "", "Your member ID")
// TODO: Add the ID of your principal.
// For examples, see https://cloud.google.com/iam/docs/principal-identifiers
member := flag.String("member_id", "", "Your principal ID")
flag.Parse()

// The role to be granted
Expand All @@ -44,10 +45,10 @@ func main() {
log.Fatalf("cloudresourcemanager.NewService: %v", err)
}

// Grants your member the "Log writer" role for your project
// Grants your principal the "Log writer" role for your project
addBinding(crmService, *projectID, *member, role)

// 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 := getPolicy(crmService, *projectID)
// Find the policy binding for role. Only one binding can have the role.
var binding *cloudresourcemanager.Binding
Expand All @@ -65,7 +66,7 @@ func main() {

}

// addBinding adds the member to the project's IAM policy
// addBinding adds the principal to the project's IAM policy
func addBinding(crmService *cloudresourcemanager.Service, projectID, member, role string) {

policy := getPolicy(crmService, projectID)
Expand All @@ -80,7 +81,7 @@ func addBinding(crmService *cloudresourcemanager.Service, projectID, member, rol
}

if binding != nil {
// If the binding exists, adds the member to the binding
// If the binding exists, adds the principal to the binding
binding.Members = append(binding.Members, member)
} else {
// If the binding does not exist, adds a new binding to the policy
Expand All @@ -95,7 +96,7 @@ func addBinding(crmService *cloudresourcemanager.Service, projectID, member, rol

}

// removeMember removes the member from the project's IAM policy
// removeMember removes the principal from the project's IAM policy
func removeMember(crmService *cloudresourcemanager.Service, projectID, member, role string) {

policy := getPolicy(crmService, projectID)
Expand All @@ -114,12 +115,12 @@ func removeMember(crmService *cloudresourcemanager.Service, projectID, member, r
// Order doesn't matter for bindings or members, so to remove, move the last item
// into the removed spot and shrink the slice.
if len(binding.Members) == 1 {
// If the member is the only member in the binding, removes the binding
// If the principal is the only member in the binding, removes the binding
last := len(policy.Bindings) - 1
policy.Bindings[bindingIndex] = policy.Bindings[last]
policy.Bindings = policy.Bindings[:last]
} else {
// If there is more than one member in the binding, removes the member
// If there is more than one member in the binding, removes the principal
var memberIndex int
for i, mm := range binding.Members {
if mm == member {
Expand Down

0 comments on commit c458e1e

Please sign in to comment.