MCPcopy Index your code
hub / github.com/bytebase/bytebase / addMemberToWorkspaceIAM

Method addMemberToWorkspaceIAM

backend/tests/tests.go:371–404  ·  view source on GitHub ↗

signupAndLogin will signup and login as user demo@example.com. addMemberToWorkspaceIAM adds a member as workspace role to the current workspace.

(ctx context.Context, workspace, member, role string)

Source from the content-addressed store, hash-verified

369// signupAndLogin will signup and login as user demo@example.com.
370// addMemberToWorkspaceIAM adds a member as workspace role to the current workspace.
371func (ctl *controller) addMemberToWorkspaceIAM(ctx context.Context, workspace, member, role string) (*v1pb.IamPolicy, error) {
372 policyResp, err := ctl.workspaceServiceClient.GetIamPolicy(ctx, connect.NewRequest(&v1pb.GetIamPolicyRequest{
373 Resource: workspace,
374 }))
375 if err != nil {
376 return nil, err
377 }
378
379 policy := policyResp.Msg
380 found := false
381 for _, binding := range policy.Bindings {
382 if binding.Role == role {
383 binding.Members = append(binding.Members, member)
384 found = true
385 break
386 }
387 }
388 if !found {
389 policy.Bindings = append(policy.Bindings, &v1pb.Binding{
390 Role: role,
391 Members: []string{member},
392 })
393 }
394
395 updated, err := ctl.workspaceServiceClient.SetIamPolicy(ctx, connect.NewRequest(&v1pb.SetIamPolicyRequest{
396 Etag: policy.Etag,
397 Policy: policy,
398 Resource: workspace,
399 }))
400 if err != nil {
401 return nil, err
402 }
403 return updated.Msg, nil
404}
405
406func (ctl *controller) signupAndLogin(ctx context.Context) (string, error) {
407 // Use Signup API (creates principal + workspace) then Login to get a token.

Calls 2

GetIamPolicyMethod · 0.65
SetIamPolicyMethod · 0.65