Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: etag for iam policy (#12862)

ecmadaoaee183553aff
diff --git a/backend/api/v1/acl_config.go b/backend/api/v1/acl_config.go
index e271a8444e..8737d7c932 100644
--- a/backend/api/v1/acl_config.go
+++ b/backend/api/v1/acl_config.go
@@ -149,9 +149,8 @@ var methodPermissionMap = map[string]iam.Permission{
v1pb.OrgPolicyService_DeletePolicy_FullMethodName: iam.PermissionPoliciesDelete,
// TODO(p0ny): ensure the permission.
- v1pb.WorkspaceService_GetIamPolicy_FullMethodName: iam.PermissionPoliciesGet,
- v1pb.WorkspaceService_SetIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
- v1pb.WorkspaceService_PatchIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
+ v1pb.WorkspaceService_GetIamPolicy_FullMethodName: iam.PermissionPoliciesGet,
+ v1pb.WorkspaceService_SetIamPolicy_FullMethodName: iam.PermissionPoliciesUpdate,
v1pb.BranchService_GetBranch_FullMethodName: iam.PermissionBranchesGet,
v1pb.BranchService_ListBranches_FullMethodName: iam.PermissionBranchesList,
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 806692eebf..6591f65641 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -448,15 +448,11 @@ func (s *AuthService) DeleteUser(ctx context.Context, request *v1pb.DeleteUserRe
return nil, errors.Wrapf(err, "failed to check admin role")
}
if isAdmin {
- workspaceAdmin, userType := api.WorkspaceAdmin, api.EndUser
- adminUser, err := s.store.ListUsers(ctx, &store.FindUserMessage{
- Role: &workspaceAdmin,
- Type: &userType,
- })
+ adminUsers, err := s.iamManager.GetWorkspaceUsersByRole(ctx, api.WorkspaceAdmin)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to find workspace admin, error: %v", err)
}
- if len(adminUser) == 1 && adminUser[0].ID == userID {
+ if len(adminUsers) == 1 && adminUsers[0].ID == userID {
return nil, status.Errorf(codes.InvalidArgument, "workspace must have at least one admin")
}
}
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index 01bbdc4540..9fad50be98 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -883,7 +883,7 @@ func (s *BranchService) checkProtectionRules(ctx context.Context, project *store
if err != nil {
return err
}
- roles := utils.GetUserFormattedRolesMap(ctx, s.store, user, policy)
+ roles := utils.GetUserFormattedRolesMap(ctx, s.store, user, policy.Policy)
for _, rule := range project.Setting.ProtectionRules {
if rule.Target != storepb.ProtectionRule_BRANCH {
diff --git a/backend/api/v1/common.go b/backend/api/v1/common.go
index a82183bb83..7a69abe41c 100644
--- a/backend/api/v1/common.go
+++ b/backend/api/v1/common.go
@@ -1,9 +1,7 @@
package v1
import (
- "crypto/sha1"
"encoding/base64"
- "fmt"
"regexp"
"strings"
@@ -457,13 +455,6 @@ func isValidUUID(id string) bool {
return uuidMatcher.MatchString(id)
}
-// generateEtag generates etag for the given body.
-func generateEtag(body []byte) string {
- hash := sha1.Sum(body)
- etag := fmt.Sprintf("%x", hash)
- return etag
-}
-
func convertExportFormat(format storepb.ExportFormat) v1pb.ExportFormat {
switch format {
case storepb.ExportFormat_CSV:
diff --git a/backend/api/v1/common_test.go b/backend/api/v1/common_test.go
index dd9eacf8e9..1d76838e12 100644
--- a/backend/api/v1/common_test.go
+++ b/backend/api/v1/common_test.go
@@ -230,28 +230,3 @@ func TestParseOrderBy(t *testing.T) {
}
}
}
-
-func TestGenerateEtag(t *testing.T) {
- tests := []struct {
- statement string
- want string
- }{
- {
- statement: "",
- want: "da39a3ee5e6b4b0d3255bfef95601890afd80709",
- },
- {
- statement: "test",
- want: "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
- },
- {
- statement: "CREATE TABLE test;",
- want: "ecbe3800ad8d24592e2dc963ae63f96c608723db",
- },
- }
-
- for _, test := range tests {
- got := generateEtag([]byte(test.statement))
- require.Equal(t, test.want, got)
- }
-}
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index b3b51eac4b..5456de6b59 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -322,7 +322,7 @@ func filterProjectDatabasesV2(ctx context.Context, s *store.Store, iamManager *i
}
expressionDBsFromAllRoles := make(map[string]bool)
- bindings := utils.GetUserIAMPolicyBindings(ctx, s, user, policy)
+ bindings := utils.GetUserIAMPolicyBindings(ctx, s, user, policy.Policy)
for _, binding := range bindings {
permissions, err := iamManager.GetPermissions(ctx, binding.Role)
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 9ca11eefa6..261c774ee5 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -838,7 +838,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIs
return nil, status.Errorf(codes.Internal, "failed to get project policy, error: %v", err)
}
- canApprove, err := isUserReviewer(ctx, s.store, step, user, policy)
+ canApprove, err := isUserReviewer(ctx, s.store, step, user, policy.Policy)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check if principal can approve step, error: %v", err)
}
@@ -1052,7 +1052,7 @@ func (s *IssueService) RejectIssue(ctx context.Context, request *v1pb.RejectIssu
return nil, status.Errorf(codes.Internal, "failed to get project policy, error: %v", err)
}
- canApprove, err := isUserReviewer(ctx, s.store, step, user, policy)
+ canApprove, err := isUserReviewer(ctx, s.store, step, user, policy.Policy)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check if principal can reject step, error: %v", err)
}
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index c029f5fc68..9d61b4b8bb 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -398,6 +398,14 @@ func (s *ProjectService) SetIamPolicy(ctx context.Context, request *v1pb.SetIamP
return nil, status.Errorf(codes.Internal, err.Error())
}
+ policyMessage, err := s.store.GetProjectIamPolicy(ctx, project.UID)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to find project iam policy with error: %v", err.Error())
+ }
+ if request.Etag != policyMessage.Etag {
+ return nil, status.Errorf(codes.Aborted, "there is concurrent update to the project iam policy, please refresh and try again.")
+ }
+
policyPayload, err := protojson.Marshal(policy)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
@@ -1352,10 +1360,10 @@ func (s *ProjectService) getProjectMessage(ctx context.Context, name string) (*s
return project, nil
}
-func convertToV1IamPolicy(ctx context.Context, stores *store.Store, iamPolicy *storepb.IamPolicy) (*v1pb.IamPolicy, error) {
+func convertToV1IamPolicy(ctx context.Context, stores *store.Store, iamPolicy *store.IamPolicyMessage) (*v1pb.IamPolicy, error) {
var bindings []*v1pb.Binding
- for _, binding := range iamPolicy.Bindings {
+ for _, binding := range iamPolicy.Policy.Bindings {
var members []string
for _, member := range binding.Members {
if strings.HasPrefix(member, common.UserNamePrefix) {
@@ -1410,6 +1418,7 @@ func convertToV1IamPolicy(ctx context.Context, stores *store.Store, iamPolicy *s
return &v1pb.IamPolicy{
Bindings: bindings,
+ Etag: iamPolicy.Etag,
}, nil
}
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 8a932f06b2..bf113d7038 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -1155,7 +1155,7 @@ func (s *RolloutService) canUserRunStageTasks(ctx context.Context, user *store.U
return false, common.Wrapf(err, common.Internal, "failed to get project %d policy", issue.Project.UID)
}
- roles := utils.GetUserFormattedRolesMap(ctx, s.store, user, policy)
+ roles := utils.GetUserFormattedRolesMap(ctx, s.store, user, policy.Policy)
if p.Automatic {
return true, nil
diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.go
index 1d625f262a..02cbc46a8d 100644
--- a/backend/api/v1/sheet_service.go
+++ b/backend/api/v1/sheet_service.go
@@ -313,7 +313,7 @@ func findProjectRoles(ctx context.Context, stores *store.Store, projectUID int,
if err != nil {
return nil, err
}
- return utils.GetUserFormattedRolesMap(ctx, stores, user, policy), nil
+ return utils.GetUserFormattedRolesMap(ctx, stores, user, policy.Policy), nil
}
func (s *SheetService) convertToAPISheetMessage(ctx context.Context, sheet *store.SheetMessage) (*v1pb.Sheet, error) {
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index c2570e7a41..1ea2fcecad 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -981,7 +981,7 @@ func (s *SQLService) accessCheck(
return status.Errorf(codes.Internal, err.Error())
}
- ok, err := s.hasDatabaseAccessRights(ctx, user, projectPolicy, attributes, isExport)
+ ok, err := s.hasDatabaseAccessRights(ctx, user, projectPolicy.Policy, attributes, isExport)
if err != nil {
return status.Errorf(codes.Internal, "failed to check access control for database: %q, error %v", column.Database, err)
}
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 4a42930953..cc3e5e5d51 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -7,13 +7,11 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
- "github.com/pkg/errors"
-
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/iam"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
- storepb "github.com/bytebase/bytebase/proto/generated-go/store"
+ "github.com/bytebase/bytebase/backend/utils"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
@@ -47,10 +45,22 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIa
return nil, err
}
+ policyMessage, err := s.store.GetWorkspaceIamPolicy(ctx)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to find workspace iam policy with error: %v", err.Error())
+ }
+ if request.Etag != policyMessage.Etag {
+ return nil, status.Errorf(codes.Aborted, "there is concurrent update to the workspace iam policy, please refresh and try again.")
+ }
+
iamPolicy, err := convertToStoreIamPolicy(ctx, s.store, request.Policy)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert iam policy with error: %v", err.Error())
}
+ users := utils.GetUsersByRoleInIAMPolicy(ctx, s.store, api.WorkspaceAdmin, iamPolicy)
+ if !containsActiveEndUser(users) {
+ return nil, status.Errorf(codes.InvalidArgument, "workspace must have at least one admin")
+ }
payloadBytes, err := protojson.Marshal(iamPolicy)
if err != nil {
@@ -65,43 +75,27 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIa
Payload: &payloadStr,
}
- updatedPolicy, err := s.store.UpdatePolicyV2(ctx, patch)
- if err != nil {
+ if _, err := s.store.UpdatePolicyV2(ctx, patch); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
- p := &storepb.IamPolicy{}
- if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(updatedPolicy.Payload), p); err != nil {
- return nil, errors.Wrapf(err, "failed to unmarshal iam policy payload")
- }
- return convertToV1IamPolicy(ctx, s.store, p)
-}
+ s.iamManager.ClearCache()
-func (s *WorkspaceService) PatchIamPolicy(ctx context.Context, request *v1pb.PatchIamPolicyRequest) (*v1pb.IamPolicy, error) {
- userUID, err := s.checkUserIsAdmin(ctx)
+ policy, err := s.store.GetWorkspaceIamPolicy(ctx)
if err != nil {
- return nil, err
+ return nil, status.Errorf(codes.Internal, "failed to find iam policy with error: %v", err.Error())
}
- // TODO(ed): Check if the user is the only workspace admin.
- storeMember, err := convertToStoreIamPolicyMember(ctx, s.store, request.Member)
- if err != nil {
- return nil, err
- }
+ return convertToV1IamPolicy(ctx, s.store, policy)
+}
- policy, err := s.store.PatchWorkspaceIamPolicy(ctx, &store.PatchIamPolicyMessage{
- Member: storeMember,
- // TODO(ed): check roles.
- Roles: request.Roles,
- UpdaterUID: userUID,
- })
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to patch iam policy with error: %v", err.Error())
+func containsActiveEndUser(users []*store.UserMessage) bool {
+ for _, user := range users {
+ if user.Type == api.EndUser && !user.MemberDeleted {
+ return true
+ }
}
-
- s.iamManager.RemoveCache(userUID)
-
- return convertToV1IamPolicy(ctx, s.store, policy)
+ return false
}
func (s *WorkspaceService) checkUserIsAdmin(ctx context.Context) (int, error) {
diff --git a/backend/component/iam/manager.go b/backend/component/iam/manager.go
index 70e99e2e61..e09b8e79b4 100644
--- a/backend/component/iam/manager.go
+++ b/backend/component/iam/manager.go
@@ -96,6 +96,14 @@ func (m *Manager) CheckUserContainsWorkspaceRoles(ctx context.Context, user *sto
return false, nil
}
+func (m *Manager) GetWorkspaceUsersByRole(ctx context.Context, role api.Role) ([]*store.UserMessage, error) {
+ policyMessage, err := m.store.GetWorkspaceIamPolicy(ctx)
+ if err != nil {
+ return nil, err
+ }
+ return utils.GetUsersByRoleInIAMPolicy(ctx, m.store, role, policyMessage.Policy), nil
+}
+
// See backfillRoleFromRoles.
func (m *Manager) BackfillWorkspaceRoleForUser(ctx context.Context, user *store.UserMessage) (api.Role, error) {
workspaceRoles, err := m.GetWorkspaceRoles(ctx, user)
@@ -106,8 +114,8 @@ func (m *Manager) BackfillWorkspaceRoleForUser(ctx context.Context, user *store.
return backfillRoleFromRoles(workspaceRoles), nil
}
-func (m *Manager) RemoveCache(userUID int) {
- m.userRoleCache.Remove(userUID)
+func (m *Manager) ClearCache() {
+ m.userRoleCache.Purge()
}
func (m *Manager) doCheckPermission(ctx context.Context, p Permission, user *store.UserMessage, projectIDs ...string) (bool, error) {
@@ -201,11 +209,11 @@ func (m *Manager) GetWorkspaceRoles(ctx context.Context, user *store.UserMessage
if v, ok := m.userRoleCache.Get(user.ID); ok {
return m.getWorkspaceRolesByRBAC(v), nil
}
- workspaceIamPolicy, err := m.store.GetWorkspaceIamPolicy(ctx)
+ policyMessage, err := m.store.GetWorkspaceIamPolicy(ctx)
if err != nil {
return nil, err
}
- roles := utils.GetUserRolesInIamPolicy(ctx, m.store, user, workspaceIamPolicy)
+ roles := utils.GetUserRolesInIamPolicy(ctx, m.store, user, policyMessage.Policy)
m.userRoleCache.Add(user.ID, roles)
return m.getWorkspaceRolesByRBAC(roles), nil
@@ -236,12 +244,12 @@ func (m *Manager) getProjectRoles(ctx context.Context, user *store.UserMessage,
projectUID = project.UID
}
- iamPolicy, err := m.store.GetProjectIamPolicy(ctx, projectUID)
+ policyMessage, err := m.store.GetProjectIamPolicy(ctx, projectUID)
if err != nil {
return nil, errors.Wrapf(err, "failed to get iam policy for project %q", projectID)
}
- projectRoles := utils.GetUserRolesInIamPolicy(ctx, m.store, user, iamPolicy)
+ projectRoles := utils.GetUserRolesInIamPolicy(ctx, m.store, user, policyMessage.Policy)
roles = append(roles, projectRoles)
}
return roles, nil
diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.go
index 5f8627d167..6233028303 100644
--- a/backend/component/webhook/manager.go
+++ b/backend/component/webhook/manager.go
@@ -13,6 +13,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ "github.com/bytebase/bytebase/backend/component/iam"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/webhook"
"github.com/bytebase/bytebase/backend/store"
@@ -24,7 +25,8 @@ import (
// Manager is the webhook manager.
type Manager struct {
- store *store.Store
+ store *store.Store
+ iamManager *iam.Manager
}
// Metadata is the activity metadata.
@@ -33,9 +35,10 @@ type Metadata struct {
}
// NewManager creates an activity manager.
-func NewManager(store *store.Store) *Manager {
+func NewManager(store *store.Store, iamManager *iam.Manager) *Manager {
return &Manager{
- store: store,
+ store: store,
+ iamManager: iamManager,
}
}
@@ -195,7 +198,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, acti
} else {
for _, workspaceRole := range u.RolloutPolicy.GetWorkspaceRoles() {
role := api.Role(strings.TrimPrefix(workspaceRole, "roles/"))
- usersGetters = append(usersGetters, getUsersFromWorkspaceRole(m.store, role))
+ usersGetters = append(usersGetters, m.getUsersFromWorkspaceRole(role))
}
for _, projectRole := range u.RolloutPolicy.GetProjectRoles() {
role := api.Role(strings.TrimPrefix(projectRole, "roles/"))
@@ -259,9 +262,9 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, acti
case storepb.ApprovalNode_GROUP_VALUE_UNSPECIFILED:
return nil, errors.Errorf("invalid group value")
case storepb.ApprovalNode_WORKSPACE_OWNER:
- usersGetter = getUsersFromWorkspaceRole(m.store, api.WorkspaceAdmin)
+ usersGetter = m.getUsersFromWorkspaceRole(api.WorkspaceAdmin)
case storepb.ApprovalNode_WORKSPACE_DBA:
- usersGetter = getUsersFromWorkspaceRole(m.store, api.WorkspaceDBA)
+ usersGetter = m.getUsersFromWorkspaceRole(api.WorkspaceDBA)
case storepb.ApprovalNode_PROJECT_OWNER:
usersGetter = getUsersFromProjectRole(m.store, api.ProjectOwner, e.Project.UID)
case storepb.ApprovalNode_PROJECT_MEMBER:
@@ -375,22 +378,20 @@ func (m *Manager) postWebhookList(ctx context.Context, webhookCtx *webhook.Conte
}
}
-func getUsersFromWorkspaceRole(s *store.Store, role api.Role) func(context.Context) ([]*store.UserMessage, error) {
+func (m *Manager) getUsersFromWorkspaceRole(role api.Role) func(context.Context) ([]*store.UserMessage, error) {
return func(ctx context.Context) ([]*store.UserMessage, error) {
- return s.ListUsers(ctx, &store.FindUserMessage{
- Role: &role,
- })
+ return m.iamManager.GetWorkspaceUsersByRole(ctx, role)
}
}
func getUsersFromProjectRole(s *store.Store, role api.Role, projectUID int) func(context.Context) ([]*store.UserMessage, error) {
return func(ctx context.Context) ([]*store.UserMessage, error) {
- iamPolicy, err := s.GetProjectIamPolicy(ctx, projectUID)
+ policyMessage, err := s.GetProjectIamPolicy(ctx, projectUID)
if err != nil {
return nil, err
}
- return utils.GetUsersByRoleInIAMPolicy(ctx, s, role, iamPolicy), nil
+ return utils.GetUsersByRoleInIAMPolicy(ctx, s, role, policyMessage.Policy), nil
}
}
diff --git a/backend/runner/mail/slow_query_weekly_mail.go b/backend/runner/mail/slow_query_weekly_mail.go
index f3b52558ef..40bad58069 100644
--- a/backend/runner/mail/slow_query_weekly_mail.go
+++ b/backend/runner/mail/slow_query_weekly_mail.go
@@ -16,6 +16,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
+ "github.com/bytebase/bytebase/backend/component/iam"
"github.com/bytebase/bytebase/backend/component/state"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/mail"
@@ -46,17 +47,19 @@ var (
)
// NewSender creates a new slow query weekly mail sender.
-func NewSender(store *store.Store, stateCfg *state.State) *SlowQueryWeeklyMailSender {
+func NewSender(store *store.Store, stateCfg *state.State, iamManager *iam.Manager) *SlowQueryWeeklyMailSender {
return &SlowQueryWeeklyMailSender{
- store: store,
- stateCfg: stateCfg,
+ store: store,
+ stateCfg: stateCfg,
+ iamManager: iamManager,
}
}
// SlowQueryWeeklyMailSender is the slow query weekly mail sender.
type SlowQueryWeeklyMailSender struct {
- store *store.Store
- stateCfg *state.State
+ store *store.Store
+ stateCfg *state.State
+ iamManager *iam.Manager
}
// Run will run the slow query weekly mail sender.
@@ -142,8 +145,7 @@ func (s *SlowQueryWeeklyMailSender) sendEmail(ctx context.Context, now time.Time
}
if len(activePolicies) == 0 {
- dbaRole := api.WorkspaceDBA
- users, err := s.store.ListUsers(ctx, &store.FindUserMessage{Role: &dbaRole})
+ users, err := s.iamManager.GetWorkspaceUsersByRole(ctx, api.WorkspaceDBA)
if err != nil {
slog.Error("Failed to list dba users", log.BBError(err))
} else {
@@ -155,8 +157,7 @@ func (s *SlowQueryWeeklyMailSender) sendEmail(ctx context.Context, now time.Time
}
}
- ownerRole := api.WorkspaceAdmin
- users, err = s.store.ListUsers(ctx, &store.FindUserMessage{Role: &ownerRole})
+ users, err = s.iamManager.GetWorkspaceUsersByRole(ctx, api.WorkspaceAdmin)
if err != nil {
slog.Error("Failed to list owner users", log.BBError(err))
} else {
@@ -171,8 +172,7 @@ func (s *SlowQueryWeeklyMailSender) sendEmail(ctx context.Context, now time.Time
}
if body, err := s.generateWeeklyEmailForDBA(ctx, activePolicies, now, consoleRedirectURL); err == nil {
- dbaRole := api.WorkspaceDBA
- users, err := s.store.ListUsers(ctx, &store.FindUserMessage{Role: &dbaRole})
+ users, err := s.iamManager.GetWorkspaceUsersByRole(ctx, api.WorkspaceDBA)
if err != nil {
slog.Error("Failed to list dba users", log.BBError(err))
} else {
@@ -203,13 +203,13 @@ func (s *SlowQueryWeeklyMailSender) sendEmail(ctx context.Context, now time.Time
continue
}
- projectPolicy, err := s.store.GetProjectIamPolicy(ctx, project.UID)
+ policyMessage, err := s.store.GetProjectIamPolicy(ctx, project.UID)
if err != nil {
slog.Error("Failed to get project policy", log.BBError(err))
continue
}
- users := utils.GetUsersByRoleInIAMPolicy(ctx, s.store, api.ProjectOwner, projectPolicy)
+ users := utils.GetUsersByRoleInIAMPolicy(ctx, s.store, api.ProjectOwner, policyMessage.Policy)
for _, user := range users {
if user.ID == api.SystemBotID {
continue
diff --git a/backend/server/server.go b/backend/server/server.go
index 69913b5680..1633d46d8e 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -231,7 +231,7 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
return nil, errors.Wrap(err, "failed to init config")
}
s.secret = secret
- s.webhookManager = webhook.NewManager(storeInstance)
+ s.webhookManager = webhook.NewManager(storeInstance, s.iamManager)
s.iamManager, err = iam.NewManager(storeInstance, s.licenseService)
if err != nil {
return nil, errors.Wrapf(err, "failed to create iam manager")
@@ -250,7 +250,7 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
s.schemaSyncer = schemasync.NewSyncer(storeInstance, s.dbFactory, s.stateCfg, profile, s.licenseService)
if !profile.Readonly {
s.slowQuerySyncer = slowquerysync.NewSyncer(storeInstance, s.dbFactory, s.stateCfg, profile)
- s.mailSender = mail.NewSender(s.store, s.stateCfg)
+ s.mailSender = mail.NewSender(s.store, s.stateCfg, s.iamManager)
s.relayRunner = relay.NewRunner(storeInstance, s.webhookManager, s.stateCfg)
s.approvalRunner = approval.NewRunner(storeInstance, s.sheetManager, s.dbFactory, s.stateCfg, s.webhookManager, s.relayRunner, s.licenseService)
diff --git a/backend/store/policy.go b/backend/store/policy.go
index e998293da2..55afb012e9 100644
--- a/backend/store/policy.go
+++ b/backend/store/policy.go
@@ -18,7 +18,17 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-func (s *Store) GetWorkspaceIamPolicy(ctx context.Context) (*storepb.IamPolicy, error) {
+type IamPolicyMessage struct {
+ Policy *storepb.IamPolicy
+ Etag string
+}
+
+// generateEtag generates etag for the given body.
+func generateEtag(t time.Time) string {
+ return fmt.Sprintf("%d", t.UnixMilli())
+}
+
+func (s *Store) GetWorkspaceIamPolicy(ctx context.Context) (*IamPolicyMessage, error) {
resourceType := api.PolicyResourceTypeWorkspace
return s.getIamPolicy(ctx, &FindPolicyMessage{
ResourceType: &resourceType,
@@ -32,7 +42,7 @@ type PatchIamPolicyMessage struct {
}
// PatchWorkspaceIamPolicy will set or remove the member for the workspace role.
-func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPolicyMessage) (*storepb.IamPolicy, error) {
+func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPolicyMessage) (*IamPolicyMessage, error) {
workspaceIamPolicy, err := s.GetWorkspaceIamPolicy(ctx)
if err != nil {
return nil, err
@@ -43,7 +53,7 @@ func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPoli
roleMap[role] = true
}
- for _, binding := range workspaceIamPolicy.Bindings {
+ for _, binding := range workspaceIamPolicy.Policy.Bindings {
index := slices.Index(binding.Members, patch.Member)
if !roleMap[binding.Role] {
if index >= 0 {
@@ -59,7 +69,7 @@ func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPoli
}
for role := range roleMap {
- workspaceIamPolicy.Bindings = append(workspaceIamPolicy.Bindings, &storepb.Binding{
+ workspaceIamPolicy.Policy.Bindings = append(workspaceIamPolicy.Policy.Bindings, &storepb.Binding{
Role: role,
Members: []string{
patch.Member,
@@ -67,7 +77,7 @@ func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPoli
})
}
- policyPayload, err := protojson.Marshal(workspaceIamPolicy)
+ policyPayload, err := protojson.Marshal(workspaceIamPolicy.Policy)
if err != nil {
return nil, err
}
@@ -86,19 +96,7 @@ func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPoli
return s.GetWorkspaceIamPolicy(ctx)
}
-func findBindingByRole(policy *storepb.IamPolicy, role api.Role) *storepb.Binding {
- r := common.FormatRole(role.String())
- for _, binding := range policy.Bindings {
- if binding.Role == r {
- return binding
- }
- }
- return &storepb.Binding{
- Role: r,
- }
-}
-
-func (s *Store) GetProjectIamPolicy(ctx context.Context, projectUID int) (*storepb.IamPolicy, error) {
+func (s *Store) GetProjectIamPolicy(ctx context.Context, projectUID int) (*IamPolicyMessage, error) {
resourceType := api.PolicyResourceTypeProject
return s.getIamPolicy(ctx, &FindPolicyMessage{
ResourceType: &resourceType,
@@ -106,7 +104,7 @@ func (s *Store) GetProjectIamPolicy(ctx context.Context, projectUID int) (*store
})
}
-func (s *Store) getIamPolicy(ctx context.Context, find *FindPolicyMessage) (*storepb.IamPolicy, error) {
+func (s *Store) getIamPolicy(ctx context.Context, find *FindPolicyMessage) (*IamPolicyMessage, error) {
pType := api.PolicyTypeIAM
find.Type = &pType
policy, err := s.GetPolicyV2(ctx, find)
@@ -114,7 +112,9 @@ func (s *Store) getIamPolicy(ctx context.Context, find *FindPolicyMessage) (*sto
return nil, err
}
if policy == nil {
- return &storepb.IamPolicy{}, nil
+ return &IamPolicyMessage{
+ Policy: &storepb.IamPolicy{},
+ }, nil
}
p := &storepb.IamPolicy{}
@@ -122,7 +122,10 @@ func (s *Store) getIamPolicy(ctx context.Context, find *FindPolicyMessage) (*sto
return nil, errors.Wrapf(err, "failed to unmarshal iam policy")
}
- return p, nil
+ return &IamPolicyMessage{
+ Policy: p,
+ Etag: generateEtag(policy.UpdatedTime),
+ }, nil
}
func (s *Store) GetRolloutPolicy(ctx context.Context, environmentID int) (*storepb.RolloutPolicy, error) {
@@ -328,7 +331,8 @@ type PolicyMessage struct {
Enforce bool
// Output only.
- UID int
+ UID int
+ UpdatedTime time.Time
}
// FindPolicyMessage is the message for finding policies.
@@ -467,6 +471,8 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
Type: patch.Type,
}
var rowStatus string
+ var updatedTs int64
+
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
UPDATE policy
SET `+strings.Join(set, ", ")+`
@@ -474,13 +480,15 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
RETURNING
payload,
inherit_from_parent,
- row_status
+ row_status,
+ updated_ts
`, len(args)-2, len(args)-1, len(args)),
args...,
).Scan(
&policy.Payload,
&policy.InheritFromParent,
&rowStatus,
+ &updatedTs,
); err != nil {
if err == sql.ErrNoRows {
return nil, nil
@@ -490,6 +498,7 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
if rowStatus == string(api.Normal) {
policy.Enforce = true
}
+ policy.UpdatedTime = time.Unix(updatedTs, 0)
if err := tx.Commit(); err != nil {
return nil, err
@@ -527,6 +536,8 @@ func (s *Store) DeletePolicyV2(ctx context.Context, policy *PolicyMessage) error
func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, creatorID int) (*PolicyMessage, error) {
var uid int
+ var updatedTs int64
+
rowStatus := api.Normal
if !create.Enforce {
rowStatus = api.Archived
@@ -549,7 +560,9 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, crea
updated_ts = extract(epoch from now()),
row_status = EXCLUDED.row_status,
updater_id = EXCLUDED.updater_id
- RETURNING id
+ RETURNING
+ id,
+ updated_ts
`,
creatorID,
creatorID,
@@ -561,10 +574,12 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, crea
rowStatus,
).Scan(
&uid,
+ &updatedTs,
); err != nil {
return nil, err
}
create.UID = uid
+ create.UpdatedTime = time.Unix(updatedTs, 0)
return create, nil
}
@@ -586,6 +601,7 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
rows, err := tx.QueryContext(ctx, `
SELECT
id,
+ updated_ts,
resource_type,
resource_id,
inherit_from_parent,
@@ -605,8 +621,11 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
for rows.Next() {
var policyMessage PolicyMessage
var rowStatus api.RowStatus
+ var updatedTs int64
+
if err := rows.Scan(
&policyMessage.UID,
+ &updatedTs,
&policyMessage.ResourceType,
&policyMessage.ResourceUID,
&policyMessage.InheritFromParent,
@@ -619,6 +638,7 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
if rowStatus == api.Normal {
policyMessage.Enforce = true
}
+ policyMessage.UpdatedTime = time.Unix(updatedTs, 0)
policyList = append(policyList, &policyMessage)
}
if err := rows.Err(); err != nil {
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 83438af477..3a4b67434f 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log/slog"
- "slices"
"strings"
"time"
@@ -28,7 +27,6 @@ var systemBotUser = &UserMessage{
type FindUserMessage struct {
ID *int
Email *string
- Role *api.Role
ShowDeleted bool
Type *api.PrincipalType
Limit *int
@@ -115,7 +113,7 @@ func (s *Store) ListUsers(ctx context.Context, find *FindUserMessage) ([]*UserMe
}
defer tx.Rollback()
- users, err := s.listUserImpl(ctx, tx, find)
+ users, err := listUserImpl(ctx, tx, find)
if err != nil {
return nil, err
}
@@ -139,7 +137,7 @@ func (s *Store) listAndCacheAllUsers(ctx context.Context) ([]*UserMessage, error
}
defer tx.Rollback()
- users, err := s.listUserImpl(ctx, tx, &FindUserMessage{ShowDeleted: true})
+ users, err := listUserImpl(ctx, tx, &FindUserMessage{ShowDeleted: true})
if err != nil {
return nil, err
}
@@ -155,18 +153,7 @@ func (s *Store) listAndCacheAllUsers(ctx context.Context) ([]*UserMessage, error
return users, nil
}
-func (s *Store) listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMessage, error) {
- workspaceIamPolicy, err := s.GetWorkspaceIamPolicy(ctx)
- if err != nil {
- return nil, err
- }
-
- // TODO(ed): deprecate this.
- var binding *storepb.Binding
- if v := find.Role; v != nil {
- binding = findBindingByRole(workspaceIamPolicy, *v)
- }
-
+func listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMessage, error) {
where, args := []string{"TRUE"}, []any{}
if v := find.ID; v != nil {
where, args = append(where, fmt.Sprintf("principal.id = $%d", len(args)+1)), append(args, *v)
@@ -225,12 +212,6 @@ func (s *Store) listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage)
return nil, err
}
- if b := binding; b != nil {
- if !slices.Contains(b.Members, common.FormatUserUID(userMessage.ID)) && !slices.Contains(b.Members, api.AllUsers) {
- continue
- }
- }
-
userMessage.MemberDeleted = convertRowStatusToDeleted(rowStatus)
mfaConfig := storepb.MFAConfig{}
if err := common.ProtojsonUnmarshaler.Unmarshal(mfaConfigBytes, &mfaConfig); err != nil {
diff --git a/backend/utils/utils.go b/backend/utils/utils.go
index 7e3e3a5e8a..c8952c574b 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -542,7 +542,7 @@ func handleApprovalNodeExternalNode(ctx context.Context, s *store.Store, relayCl
// UpdateProjectPolicyFromGrantIssue updates the project policy from grant issue.
func UpdateProjectPolicyFromGrantIssue(ctx context.Context, stores *store.Store, issue *store.IssueMessage, grantRequest *storepb.GrantRequest) error {
- policy, err := stores.GetProjectIamPolicy(ctx, issue.Project.UID)
+ policyMessage, err := stores.GetProjectIamPolicy(ctx, issue.Project.UID)
if err != nil {
return errors.Wrapf(err, "failed to get project policy for project %q", issue.Project.UID)
}
@@ -564,7 +564,7 @@ func UpdateProjectPolicyFromGrantIssue(ctx context.Context, stores *store.Store,
if newUser == nil {
return status.Errorf(codes.Internal, "user %v not found", userID)
}
- for _, binding := range policy.Bindings {
+ for _, binding := range policyMessage.Policy.Bindings {
if binding.Role != grantRequest.Role {
continue
}
@@ -586,14 +586,14 @@ func UpdateProjectPolicyFromGrantIssue(ctx context.Context, stores *store.Store,
condition = &expr.Expr{}
}
condition.Description = fmt.Sprintf("#%d", issue.UID)
- policy.Bindings = append(policy.Bindings, &storepb.Binding{
+ policyMessage.Policy.Bindings = append(policyMessage.Policy.Bindings, &storepb.Binding{
Role: grantRequest.Role,
Members: []string{common.FormatUserUID(newUser.ID)},
Condition: condition,
})
}
- policyPayload, err := protojson.Marshal(policy)
+ policyPayload, err := protojson.Marshal(policyMessage.Policy)
if err != nil {
return err
}
diff --git a/frontend/src/components/User/Settings/CreateUserDrawer.vue b/frontend/src/components/User/Settings/CreateUserDrawer.vue
index 5d64ee64a1..63db6897e4 100644
--- a/frontend/src/components/User/Settings/CreateUserDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateUserDrawer.vue
@@ -300,6 +300,18 @@ const passwordMismatch = computed(() => {
);
});
+const rolesChanged = computed(() => {
+ if (isCreating.value) {
+ return true;
+ }
+
+ return (
+ !isUndefined(state.user.roles) &&
+ state.user.roles.length > 0 &&
+ !isEqual(props.user?.roles, state.user.roles)
+ );
+});
+
const allowConfirm = computed(() => {
if (!state.user.email) {
return false;
@@ -307,7 +319,8 @@ const allowConfirm = computed(() => {
if (
!isCreating.value &&
(passwordMismatch.value ||
- getUpdateMaskFromUsers(props.user!, state.user).length == 0)
+ (getUpdateMaskFromUsers(props.user!, state.user).length == 0 &&
+ !rolesChanged.value))
) {
return false;
}
@@ -396,10 +409,7 @@ const tryCreateOrUpdateUser = async () => {
updateMask: getUpdateMaskFromUsers(props.user!, state.user),
})
);
- if (
- !isUndefined(state.user.roles) &&
- !isEqual(props.user?.roles, state.user.roles)
- ) {
+ if (rolesChanged.value) {
await userStore.updateUserRoles(state.user);
}
pushNotification({
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index 62c78cc718..d5e27df193 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -70,6 +70,7 @@ export const useProjectIamPolicyStore = defineStore(
const updated = await projectServiceClient.setIamPolicy({
resource: project,
policy,
+ etag: policy.etag,
});
policyMap.value.set(project, updated);
diff --git a/frontend/src/store/modules/v1/workspace.ts b/frontend/src/store/modules/v1/workspace.ts
index 9082cda0f8..e0e0681eb9 100644
--- a/frontend/src/store/modules/v1/workspace.ts
+++ b/frontend/src/store/modules/v1/workspace.ts
@@ -1,7 +1,8 @@
+import { cloneDeep } from "lodash-es";
import { defineStore } from "pinia";
-import { computed, ref, watchEffect } from "vue";
+import { ref } from "vue";
import { workspaceServiceClient } from "@/grpcweb";
-import { IamPolicy } from "@/types/proto/v1/iam_policy";
+import { IamPolicy, Binding } from "@/types/proto/v1/iam_policy";
export const useWorkspaceV1Store = defineStore("workspace_v1", () => {
const workspaceIamPolicy = ref<IamPolicy>(IamPolicy.fromPartial({}));
@@ -20,10 +21,37 @@ export const useWorkspaceV1Store = defineStore("workspace_v1", () => {
member: string;
roles: string[];
}) => {
- const policy = await workspaceServiceClient.patchIamPolicy({
+ const newRolesSet = new Set(roles);
+ const workspacePolicy = cloneDeep(workspaceIamPolicy.value);
+
+ for (const binding of workspacePolicy.bindings) {
+ const index = binding.members.findIndex((m) => m === member);
+ if (!newRolesSet.has(binding.role)) {
+ if (index >= 0) {
+ binding.members = binding.members.splice(index, 1);
+ }
+ } else {
+ if (index < 0) {
+ binding.members.push(member);
+ }
+ }
+
+ newRolesSet.delete(binding.role);
+ }
+
+ for (const role of newRolesSet) {
+ workspacePolicy.bindings.push(
+ Binding.fromPartial({
+ role,
+ members: [member],
+ })
+ );
+ }
+
+ const policy = await workspaceServiceClient.setIamPolicy({
resource: "workspaces/-",
- member,
- roles,
+ policy: workspacePolicy,
+ etag: workspacePolicy.etag,
});
workspaceIamPolicy.value = policy;
};
@@ -34,13 +62,3 @@ export const useWorkspaceV1Store = defineStore("workspace_v1", () => {
patchIamPolicy,
};
});
-
-export const useWorkspaceIamPolicy = () => {
- const store = useWorkspaceV1Store();
-
- watchEffect(() => {
- store.fetchIamPolicy();
- });
-
- return computed(() => store.workspaceIamPolicy);
-};
diff --git a/frontend/src/types/proto/v1/iam_policy.ts b/frontend/src/types/proto/v1/iam_policy.ts
index 0bb070ebdc..548e3514f9 100644
--- a/frontend/src/types/proto/v1/iam_policy.ts
+++ b/frontend/src/types/proto/v1/iam_policy.ts
@@ -22,7 +22,11 @@ export interface SetIamPolicyRequest {
* Format: workspaces/{workspace}
*/
resource: string;
- policy: IamPolicy | undefined;
+ policy:
+ | IamPolicy
+ | undefined;
+ /** The current etag of the policy. */
+ etag: string;
}
export interface IamPolicy {
@@ -31,6 +35,12 @@ export interface IamPolicy {
* A binding binds one or more project members to a single project role.
*/
bindings: Binding[];
+ /**
+ * The current etag of the policy.
+ * If an etag is provided and does not match the current etag of the poliy,
+ * the call will be blocked and an ABORTED error will be returned.
+ */
+ etag: string;
}
export interface Binding {
@@ -115,7 +125,7 @@ export const GetIamPolicyRequest = {
};
function createBaseSetIamPolicyRequest(): SetIamPolicyRequest {
- return { resource: "", policy: undefined };
+ return { resource: "", policy: undefined, etag: "" };
}
export const SetIamPolicyRequest = {
@@ -126,6 +136,9 @@ export const SetIamPolicyRequest = {
if (message.policy !== undefined) {
IamPolicy.encode(message.policy, writer.uint32(18).fork()).ldelim();
}
+ if (message.etag !== "") {
+ writer.uint32(26).string(message.etag);
+ }
return writer;
},
@@ -150,6 +163,13 @@ export const SetIamPolicyRequest = {
message.policy = IamPolicy.decode(reader, reader.uint32());
continue;
+ case 3:
+ if (tag !== 26) {
+ break;
+ }
+
+ message.etag = reader.string();
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -163,6 +183,7 @@ export const SetIamPolicyRequest = {
return {
resource: isSet(object.resource) ? globalThis.String(object.resource) : "",
policy: isSet(object.policy) ? IamPolicy.fromJSON(object.policy) : undefined,
+ etag: isSet(object.etag) ? globalThis.String(object.etag) : "",
};
},
@@ -174,6 +195,9 @@ export const SetIamPolicyRequest = {
if (message.policy !== undefined) {
obj.policy = IamPolicy.toJSON(message.policy);
}
+ if (message.etag !== "") {
+ obj.etag = message.etag;
+ }
return obj;
},
@@ -186,12 +210,13 @@ export const SetIamPolicyRequest = {
message.policy = (object.policy !== undefined && object.policy !== null)
? IamPolicy.fromPartial(object.policy)
: undefined;
+ message.etag = object.etag ?? "";
return message;
},
};
function createBaseIamPolicy(): IamPolicy {
- return { bindings: [] };
+ return { bindings: [], etag: "" };
}
export const IamPolicy = {
@@ -199,6 +224,9 @@ export const IamPolicy = {
for (const v of message.bindings) {
Binding.encode(v!, writer.uint32(10).fork()).ldelim();
}
+ if (message.etag !== "") {
+ writer.uint32(18).string(message.etag);
+ }
return writer;
},
@@ -216,6 +244,13 @@ export const IamPolicy = {
message.bindings.push(Binding.decode(reader, reader.uint32()));
continue;
+ case 2:
+ if (tag !== 18) {
+ break;
+ }
+
+ message.etag = reader.string();
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -228,6 +263,7 @@ export const IamPolicy = {
fromJSON(object: any): IamPolicy {
return {
bindings: globalThis.Array.isArray(object?.bindings) ? object.bindings.map((e: any) => Binding.fromJSON(e)) : [],
+ etag: isSet(object.etag) ? globalThis.String(object.etag) : "",
};
},
@@ -236,6 +272,9 @@ export const IamPolicy = {
if (message.bindings?.length) {
obj.bindings = message.bindings.map((e) => Binding.toJSON(e));
}
+ if (message.etag !== "") {
+ obj.etag = message.etag;
+ }
return obj;
},
@@ -245,6 +284,7 @@ export const IamPolicy = {
fromPartial(object: DeepPartial<IamPolicy>): IamPolicy {
const message = createBaseIamPolicy();
message.bindings = object.bindings?.map((e) => Binding.fromPartial(e)) || [];
+ message.etag = object.etag ?? "";
return message;
},
};
diff --git a/frontend/src/types/proto/v1/workspace_service.ts b/frontend/src/types/proto/v1/workspace_service.ts
index f1328c45f0..5b54d0c292 100644
--- a/frontend/src/types/proto/v1/workspace_service.ts
+++ b/frontend/src/types/proto/v1/workspace_service.ts
@@ -1,117 +1,8 @@
/* eslint-disable */
-import Long from "long";
-import _m0 from "protobufjs/minimal";
import { GetIamPolicyRequest, IamPolicy, SetIamPolicyRequest } from "./iam_policy";
export const protobufPackage = "bytebase.v1";
-export interface PatchIamPolicyRequest {
- /**
- * The name of the resource to get the IAM policy.
- * Format: workspaces/{workspace}
- */
- resource: string;
- /**
- * Specifies the principals requesting access for a Bytebase resource.
- * Format: user:{email}
- */
- member: string;
- /**
- * The roles that is assigned to the member.
- * Format: roles/{role}
- */
- roles: string[];
-}
-
-function createBasePatchIamPolicyRequest(): PatchIamPolicyRequest {
- return { resource: "", member: "", roles: [] };
-}
-
-export const PatchIamPolicyRequest = {
- encode(message: PatchIamPolicyRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
- if (message.resource !== "") {
- writer.uint32(10).string(message.resource);
- }
- if (message.member !== "") {
- writer.uint32(18).string(message.member);
- }
- for (const v of message.roles) {
- writer.uint32(26).string(v!);
- }
- return writer;
- },
-
- decode(input: _m0.Reader | Uint8Array, length?: number): PatchIamPolicyRequest {
- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
- let end = length === undefined ? reader.len : reader.pos + length;
- const message = createBasePatchIamPolicyRequest();
- while (reader.pos < end) {
- const tag = reader.uint32();
- switch (tag >>> 3) {
- case 1:
- if (tag !== 10) {
- break;
- }
-
- message.resource = reader.string();
- continue;
- case 2:
- if (tag !== 18) {
- break;
- }
-
- message.member = reader.string();
- continue;
- case 3:
- if (tag !== 26) {
- break;
- }
-
- message.roles.push(reader.string());
- continue;
- }
- if ((tag & 7) === 4 || tag === 0) {
- break;
- }
- reader.skipType(tag & 7);
- }
- return message;
- },
-
- fromJSON(object: any): PatchIamPolicyRequest {
- return {
- resource: isSet(object.resource) ? globalThis.String(object.resource) : "",
- member: isSet(object.member) ? globalThis.String(object.member) : "",
- roles: globalThis.Array.isArray(object?.roles) ? object.roles.map((e: any) => globalThis.String(e)) : [],
- };
- },
-
- toJSON(message: PatchIamPolicyRequest): unknown {
- const obj: any = {};
- if (message.resource !== "") {
- obj.resource = message.resource;
- }
- if (message.member !== "") {
- obj.member = message.member;
- }
- if (message.roles?.length) {
- obj.roles = message.roles;
- }
- return obj;
- },
-
- create(base?: DeepPartial<PatchIamPolicyRequest>): PatchIamPolicyRequest {
- return PatchIamPolicyRequest.fromPartial(base ?? {});
- },
- fromPartial(object: DeepPartial<PatchIamPolicyRequest>): PatchIamPolicyRequest {
- const message = createBasePatchIamPolicyRequest();
- message.resource = object.resource ?? "";
- message.member = object.member ?? "";
- message.roles = object.roles?.map((e) => e) || [];
- return message;
- },
-};
-
export type WorkspaceServiceDefinition = typeof WorkspaceServiceDefinition;
export const WorkspaceServiceDefinition = {
name: "WorkspaceService",
@@ -236,85 +127,5 @@ export const WorkspaceServiceDefinition = {
},
},
},
- patchIamPolicy: {
- name: "PatchIamPolicy",
- requestType: PatchIamPolicyRequest,
- requestStream: false,
- responseType: IamPolicy,
- responseStream: false,
- options: {
- _unknownFields: {
- 578365826: [
- new Uint8Array([
- 47,
- 58,
- 1,
- 42,
- 50,
- 42,
- 47,
- 118,
- 49,
- 47,
- 123,
- 114,
- 101,
- 115,
- 111,
- 117,
- 114,
- 99,
- 101,
- 61,
- 119,
- 111,
- 114,
- 107,
- 115,
- 112,
- 97,
- 99,
- 101,
- 115,
- 47,
- 42,
- 125,
- 58,
- 112,
- 97,
- 116,
- 99,
- 104,
- 73,
- 97,
- 109,
- 80,
- 111,
- 108,
- 105,
- 99,
- 121,
- ]),
- ],
- },
- },
- },
},
} as const;
-
-type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
-
-export type DeepPartial<T> = T extends Builtin ? T
- : T extends Long ? string | number | Long : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
- : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
- : Partial<T>;
-
-if (_m0.util.Long !== Long) {
- _m0.util.Long = Long as any;
- _m0.configure();
-}
-
-function isSet(value: any): boolean {
- return value !== null && value !== undefined;
-}
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index c8a71a8580..8fbda07f57 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -8139,37 +8139,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Status'
- /v1/workspaces/{workspace}:patchIamPolicy:
- patch:
- tags:
- - WorkspaceService
- operationId: WorkspaceService_PatchIamPolicy
- parameters:
- - name: workspace
- in: path
- description: The workspace id.
- required: true
- schema:
- type: string
- requestBody:
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/PatchIamPolicyRequest'
- required: true
- responses:
- "200":
- description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/IamPolicy'
- default:
- description: Default error response
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/Status'
/v1/workspaces/{workspace}:setIamPolicy:
post:
tags:
@@ -11488,28 +11457,6 @@ components:
- $ref: '#/components/schemas/SourceInfo'
description: The source info derived from input that generated the parsed `expr`.
description: An expression together with source information as returned by the parser.
- PatchIamPolicyRequest:
- required:
- - resource
- type: object
- properties:
- resource:
- type: string
- description: |-
- The name of the resource to get the IAM policy.
- Format: workspaces/{workspace}
- member:
- type: string
- description: |-
- Specifies the principals requesting access for a Bytebase resource.
- Format: user:{email}
- roles:
- type: array
- items:
- type: string
- description: |-
- The roles that is assigned to the member.
- Format: roles/{role}
PatchSubscription:
type: object
properties:
@@ -12951,6 +12898,9 @@ components:
Format: workspaces/{workspace}
policy:
$ref: '#/components/schemas/IamPolicy'
+ etag:
+ type: string
+ description: The current etag of the policy.
Setting:
type: object
properties:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 0390663729..a92cc6df2e 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -692,8 +692,6 @@
- [WorksheetService](#bytebase-v1-WorksheetService)
- [v1/workspace_service.proto](#v1_workspace_service-proto)
- - [PatchIamPolicyRequest](#bytebase-v1-PatchIamPolicyRequest)
-
- [WorkspaceService](#bytebase-v1-WorkspaceService)
- [Scalar Value Types](#scalar-value-types)
@@ -4323,6 +4321,7 @@ The environment&#39;s `name` field is used to identify the environment to update
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| bindings | [Binding](#bytebase-v1-Binding) | repeated | Collection of binding. A binding binds one or more project members to a single project role. |
+| etag | [string](#string) | | The current etag of the policy. If an etag is provided and does not match the current etag of the poliy, the call will be blocked and an ABORTED error will be returned. |
@@ -4339,6 +4338,7 @@ The environment&#39;s `name` field is used to identify the environment to update
| ----- | ---- | ----- | ----------- |
| resource | [string](#string) | | The name of the resource to set the IAM policy. Format: projects/{project} Format: workspaces/{workspace} |
| policy | [IamPolicy](#bytebase-v1-IamPolicy) | | |
+| etag | [string](#string) | | The current etag of the policy. |
@@ -11062,23 +11062,6 @@ The worksheet&#39;s `name` field is used to identify the worksheet to update. Fo
## v1/workspace_service.proto
-
-<a name="bytebase-v1-PatchIamPolicyRequest"></a>
-
-### PatchIamPolicyRequest
-
-
-
-| Field | Type | Label | Description |
-| ----- | ---- | ----- | ----------- |
-| resource | [string](#string) | | The name of the resource to get the IAM policy. Format: workspaces/{workspace} |
-| member | [string](#string) | | Specifies the principals requesting access for a Bytebase resource. Format: user:{email} |
-| roles | [string](#string) | repeated | The roles that is assigned to the member. Format: roles/{role} |
-
-
-
-
-
@@ -11095,7 +11078,6 @@ The worksheet&#39;s `name` field is used to identify the worksheet to update. Fo
| ----------- | ------------ | ------------- | ------------|
| GetIamPolicy | [GetIamPolicyRequest](#bytebase-v1-GetIamPolicyRequest) | [IamPolicy](#bytebase-v1-IamPolicy) | |
| SetIamPolicy | [SetIamPolicyRequest](#bytebase-v1-SetIamPolicyRequest) | [IamPolicy](#bytebase-v1-IamPolicy) | |
-| PatchIamPolicy | [PatchIamPolicyRequest](#bytebase-v1-PatchIamPolicyRequest) | [IamPolicy](#bytebase-v1-IamPolicy) | |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 8807803eea..bd7c69a53c 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -2824,10 +2824,6 @@
<a href="#v1%2fworkspace_service.proto">v1/workspace_service.proto</a>
<ul>
- <li>
- <a href="#bytebase.v1.PatchIamPolicyRequest"><span class="badge">M</span>PatchIamPolicyRequest</a>
- </li>
-
@@ -12734,6 +12730,15 @@ Format: workspaces/{workspace} </p></td>
A binding binds one or more project members to a single project role. </p></td>
</tr>
+ <tr>
+ <td>etag</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>The current etag of the policy.
+If an etag is provided and does not match the current etag of the poliy,
+the call will be blocked and an ABORTED error will be returned. </p></td>
+ </tr>
+
</tbody>
</table>
@@ -12767,6 +12772,13 @@ Format: workspaces/{workspace} </p></td>
<td><p> </p></td>
</tr>
+ <tr>
+ <td>etag</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>The current etag of the policy. </p></td>
+ </tr>
+
</tbody>
</table>
@@ -30344,47 +30356,6 @@ Format: worksheets/{worksheet} </p></td>
<p></p>
- <h3 id="bytebase.v1.PatchIamPolicyRequest">PatchIamPolicyRequest</h3>
- <p></p>
-
-
- <table class="field-table">
- <thead>
- <tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
- </thead>
- <tbody>
-
- <tr>
- <td>resource</td>
- <td><a href="#string">string</a></td>
- <td></td>
- <td><p>The name of the resource to get the IAM policy.
-Format: workspaces/{workspace} </p></td>
- </tr>
-
- <tr>
- <td>member</td>
- <td><a href="#string">string</a></td>
- <td></td>
- <td><p>Specifies the principals requesting access for a Bytebase resource.
-Format: user:{email} </p></td>
- </tr>
-
- <tr>
- <td>roles</td>
- <td><a href="#string">string</a></td>
- <td>repeated</td>
- <td><p>The roles that is assigned to the member.
-Format: roles/{role} </p></td>
- </tr>
-
- </tbody>
- </table>
-
-
-
-
-
@@ -30413,13 +30384,6 @@ Format: roles/{role} </p></td>
<td><p></p></td>
</tr>
- <tr>
- <td>PatchIamPolicy</td>
- <td><a href="#bytebase.v1.PatchIamPolicyRequest">PatchIamPolicyRequest</a></td>
- <td><a href="#bytebase.v1.IamPolicy">IamPolicy</a></td>
- <td><p></p></td>
- </tr>
-
</tbody>
</table>
@@ -30458,16 +30422,6 @@ Format: roles/{role} </p></td>
</tr>
-
-
- <tr>
- <td>PatchIamPolicy</td>
- <td>PATCH</td>
- <td>/v1/{resource=workspaces/*}:patchIamPolicy</td>
- <td>*</td>
- </tr>
-
-
</tbody>
</table>
diff --git a/proto/generated-go/v1/iam_policy.pb.go b/proto/generated-go/v1/iam_policy.pb.go
index c7300c64bb..2e283229e6 100644
--- a/proto/generated-go/v1/iam_policy.pb.go
+++ b/proto/generated-go/v1/iam_policy.pb.go
@@ -83,6 +83,8 @@ type SetIamPolicyRequest struct {
// Format: workspaces/{workspace}
Resource string `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"`
Policy *IamPolicy `protobuf:"bytes,2,opt,name=policy,proto3" json:"policy,omitempty"`
+ // The current etag of the policy.
+ Etag string `protobuf:"bytes,3,opt,name=etag,proto3" json:"etag,omitempty"`
}
func (x *SetIamPolicyRequest) Reset() {
@@ -131,6 +133,13 @@ func (x *SetIamPolicyRequest) GetPolicy() *IamPolicy {
return nil
}
+func (x *SetIamPolicyRequest) GetEtag() string {
+ if x != nil {
+ return x.Etag
+ }
+ return ""
+}
+
type IamPolicy struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -139,6 +148,10 @@ type IamPolicy struct {
// Collection of binding.
// A binding binds one or more project members to a single project role.
Bindings []*Binding `protobuf:"bytes,1,rep,name=bindings,proto3" json:"bindings,omitempty"`
+ // The current etag of the policy.
+ // If an etag is provided and does not match the current etag of the poliy,
+ // the call will be blocked and an ABORTED error will be returned.
+ Etag string `protobuf:"bytes,2,opt,name=etag,proto3" json:"etag,omitempty"`
}
func (x *IamPolicy) Reset() {
@@ -180,6 +193,13 @@ func (x *IamPolicy) GetBindings() []*Binding {
return nil
}
+func (x *IamPolicy) GetEtag() string {
+ if x != nil {
+ return x.Etag
+ }
+ return ""
+}
+
type Binding struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -274,31 +294,34 @@ var file_v1_iam_policy_proto_rawDesc = []byte{
0x74, 0x6f, 0x22, 0x37, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69,
0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x08, 0x72, 0x65, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01,
- 0x02, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x6d, 0x0a, 0x13, 0x53,
- 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65,
- 0x73, 0x74, 0x12, 0x20, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01,
- 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f,
- 0x75, 0x72, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x18, 0x02,
- 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,
- 0x76, 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x42, 0x04, 0xe2, 0x41,
- 0x01, 0x02, 0x52, 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x3d, 0x0a, 0x09, 0x49, 0x61,
- 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x30, 0x0a, 0x08, 0x62, 0x69, 0x6e, 0x64, 0x69,
- 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x79, 0x74, 0x65,
- 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x52,
- 0x08, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x73, 0x22, 0xb5, 0x01, 0x0a, 0x07, 0x42, 0x69,
- 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x01, 0x20,
- 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x6d,
- 0x62, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x62,
- 0x65, 0x72, 0x73, 0x12, 0x2f, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e,
- 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
- 0x74, 0x79, 0x70, 0x65, 0x2e, 0x45, 0x78, 0x70, 0x72, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69,
- 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x4b, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x5f, 0x65,
- 0x78, 0x70, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
- 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x65, 0x78, 0x70, 0x72, 0x2e, 0x76, 0x31, 0x61, 0x6c,
- 0x70, 0x68, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x64, 0x45, 0x78, 0x70, 0x72, 0x42,
- 0x04, 0xe2, 0x41, 0x01, 0x03, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x45, 0x78, 0x70,
- 0x72, 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67,
- 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+ 0x02, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x81, 0x01, 0x0a, 0x13,
+ 0x53, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75,
+ 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18,
+ 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x08, 0x72, 0x65, 0x73,
+ 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x18,
+ 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
+ 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x42, 0x04, 0xe2,
+ 0x41, 0x01, 0x02, 0x52, 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x65,
+ 0x74, 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x74, 0x61, 0x67, 0x22,
+ 0x51, 0x0a, 0x09, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x30, 0x0a, 0x08,
+ 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14,
+ 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x69, 0x6e,
+ 0x64, 0x69, 0x6e, 0x67, 0x52, 0x08, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x12,
+ 0x0a, 0x04, 0x65, 0x74, 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x74,
+ 0x61, 0x67, 0x22, 0xb5, 0x01, 0x0a, 0x07, 0x42, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x12,
+ 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f,
+ 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20,
+ 0x03, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x2f, 0x0a, 0x09,
+ 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
+ 0x11, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x45, 0x78,
+ 0x70, 0x72, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x4b, 0x0a,
+ 0x0b, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x5f, 0x65, 0x78, 0x70, 0x72, 0x18, 0x04, 0x20, 0x01,
+ 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
+ 0x65, 0x78, 0x70, 0x72, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x50, 0x61,
+ 0x72, 0x73, 0x65, 0x64, 0x45, 0x78, 0x70, 0x72, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x03, 0x52, 0x0a,
+ 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x45, 0x78, 0x70, 0x72, 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x65,
+ 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70,
+ 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
diff --git a/proto/generated-go/v1/workspace_service.pb.go b/proto/generated-go/v1/workspace_service.pb.go
index 78a9f84b91..74da65646f 100644
--- a/proto/generated-go/v1/workspace_service.pb.go
+++ b/proto/generated-go/v1/workspace_service.pb.go
@@ -11,7 +11,6 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
- sync "sync"
)
const (
@@ -21,75 +20,6 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
-type PatchIamPolicyRequest struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- // The name of the resource to get the IAM policy.
- // Format: workspaces/{workspace}
- Resource string `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"`
- // Specifies the principals requesting access for a Bytebase resource.
- // Format: user:{email}
- Member string `protobuf:"bytes,2,opt,name=member,proto3" json:"member,omitempty"`
- // The roles that is assigned to the member.
- // Format: roles/{role}
- Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"`
-}
-
-func (x *PatchIamPolicyRequest) Reset() {
- *x = PatchIamPolicyRequest{}
- if protoimpl.UnsafeEnabled {
- mi := &file_v1_workspace_service_proto_msgTypes[0]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *PatchIamPolicyRequest) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*PatchIamPolicyRequest) ProtoMessage() {}
-
-func (x *PatchIamPolicyRequest) ProtoReflect() protoreflect.Message {
- mi := &file_v1_workspace_service_proto_msgTypes[0]
- if protoimpl.UnsafeEnabled && x != nil {
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- if ms.LoadMessageInfo() == nil {
- ms.StoreMessageInfo(mi)
- }
- return ms
- }
- return mi.MessageOf(x)
-}
-
-// Deprecated: Use PatchIamPolicyRequest.ProtoReflect.Descriptor instead.
-func (*PatchIamPolicyRequest) Descriptor() ([]byte, []int) {
- return file_v1_workspace_service_proto_rawDescGZIP(), []int{0}
-}
-
-func (x *PatchIamPolicyRequest) GetResource() string {
- if x != nil {
- return x.Resource
- }
- return ""
-}
-
-func (x *PatchIamPolicyRequest) GetMember() string {
- if x != nil {
- return x.Member
- }
- return ""
-}
-
-func (x *PatchIamPolicyRequest) GetRoles() []string {
- if x != nil {
- return x.Roles
- }
- return nil
-}
-
var File_v1_workspace_service_proto protoreflect.FileDescriptor
var file_v1_workspace_service_proto_rawDesc = []byte{
@@ -97,74 +27,41 @@ var file_v1_workspace_service_proto_rawDesc = []byte{
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x62, 0x79,
0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
- 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f,
- 0x61, 0x70, 0x69, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x62, 0x65, 0x68, 0x61, 0x76, 0x69,
- 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x13, 0x76, 0x31, 0x2f, 0x69, 0x61, 0x6d,
- 0x5f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x67, 0x0a,
- 0x15, 0x50, 0x61, 0x74, 0x63, 0x68, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52,
- 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72,
- 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x08,
- 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x62,
- 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72,
- 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52,
- 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x32, 0x93, 0x03, 0x0a, 0x10, 0x57, 0x6f, 0x72, 0x6b, 0x73,
- 0x70, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x7a, 0x0a, 0x0c, 0x47,
- 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x20, 0x2e, 0x62, 0x79,
- 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x61, 0x6d,
- 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
- 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50,
- 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x30, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2a, 0x12, 0x28, 0x2f,
- 0x76, 0x31, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3d, 0x77, 0x6f, 0x72,
- 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x2a, 0x7d, 0x3a, 0x67, 0x65, 0x74, 0x49, 0x61,
- 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x7d, 0x0a, 0x0c, 0x53, 0x65, 0x74, 0x49, 0x61,
- 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x20, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
- 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69,
- 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x62, 0x79, 0x74, 0x65,
- 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63,
- 0x79, 0x22, 0x33, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2d, 0x3a, 0x01, 0x2a, 0x22, 0x28, 0x2f, 0x76,
- 0x31, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3d, 0x77, 0x6f, 0x72, 0x6b,
- 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x2a, 0x7d, 0x3a, 0x73, 0x65, 0x74, 0x49, 0x61, 0x6d,
- 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x83, 0x01, 0x0a, 0x0e, 0x50, 0x61, 0x74, 0x63, 0x68,
- 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x22, 0x2e, 0x62, 0x79, 0x74, 0x65,
- 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x74, 0x63, 0x68, 0x49, 0x61, 0x6d,
- 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
- 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50,
- 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x35, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2f, 0x3a, 0x01, 0x2a,
- 0x32, 0x2a, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3d,
- 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x2a, 0x7d, 0x3a, 0x70, 0x61,
- 0x74, 0x63, 0x68, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x42, 0x11, 0x5a, 0x0f,
+ 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x13, 0x76, 0x31, 0x2f, 0x69, 0x61, 0x6d, 0x5f,
+ 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x8d, 0x02, 0x0a,
+ 0x10, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
+ 0x65, 0x12, 0x7a, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63,
+ 0x79, 0x12, 0x20, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e,
+ 0x47, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75,
+ 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76,
+ 0x31, 0x2e, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x30, 0x82, 0xd3, 0xe4,
+ 0x93, 0x02, 0x2a, 0x12, 0x28, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72,
+ 0x63, 0x65, 0x3d, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x2a, 0x7d,
+ 0x3a, 0x67, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x7d, 0x0a,
+ 0x0c, 0x53, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x20, 0x2e,
+ 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x49,
+ 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
+ 0x16, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x61,
+ 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x33, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2d, 0x3a,
+ 0x01, 0x2a, 0x22, 0x28, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63,
+ 0x65, 0x3d, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x2f, 0x2a, 0x7d, 0x3a,
+ 0x73, 0x65, 0x74, 0x49, 0x61, 0x6d, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x42, 0x11, 0x5a, 0x0f,
0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
-var (
- file_v1_workspace_service_proto_rawDescOnce sync.Once
- file_v1_workspace_service_proto_rawDescData = file_v1_workspace_service_proto_rawDesc
-)
-
-func file_v1_workspace_service_proto_rawDescGZIP() []byte {
- file_v1_workspace_service_proto_rawDescOnce.Do(func() {
- file_v1_workspace_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_v1_workspace_service_proto_rawDescData)
- })
- return file_v1_workspace_service_proto_rawDescData
-}
-
-var file_v1_workspace_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_v1_workspace_service_proto_goTypes = []any{
- (*PatchIamPolicyRequest)(nil), // 0: bytebase.v1.PatchIamPolicyRequest
- (*GetIamPolicyRequest)(nil), // 1: bytebase.v1.GetIamPolicyRequest
- (*SetIamPolicyRequest)(nil), // 2: bytebase.v1.SetIamPolicyRequest
- (*IamPolicy)(nil), // 3: bytebase.v1.IamPolicy
+ (*GetIamPolicyRequest)(nil), // 0: bytebase.v1.GetIamPolicyRequest
+ (*SetIamPolicyRequest)(nil), // 1: bytebase.v1.SetIamPolicyRequest
+ (*IamPolicy)(nil), // 2: bytebase.v1.IamPolicy
}
var file_v1_workspace_service_proto_depIdxs = []int32{
- 1, // 0: bytebase.v1.WorkspaceService.GetIamPolicy:input_type -> bytebase.v1.GetIamPolicyRequest
- 2, // 1: bytebase.v1.WorkspaceService.SetIamPolicy:input_type -> bytebase.v1.SetIamPolicyRequest
- 0, // 2: bytebase.v1.WorkspaceService.PatchIamPolicy:input_type -> bytebase.v1.PatchIamPolicyRequest
- 3, // 3: bytebase.v1.WorkspaceService.GetIamPolicy:output_type -> bytebase.v1.IamPolicy
- 3, // 4: bytebase.v1.WorkspaceService.SetIamPolicy:output_type -> bytebase.v1.IamPolicy
- 3, // 5: bytebase.v1.WorkspaceService.PatchIamPolicy:output_type -> bytebase.v1.IamPolicy
- 3, // [3:6] is the sub-list for method output_type
- 0, // [0:3] is the sub-list for method input_type
+ 0, // 0: bytebase.v1.WorkspaceService.GetIamPolicy:input_type -> bytebase.v1.GetIamPolicyRequest
+ 1, // 1: bytebase.v1.WorkspaceService.SetIamPolicy:input_type -> bytebase.v1.SetIamPolicyRequest
+ 2, // 2: bytebase.v1.WorkspaceService.GetIamPolicy:output_type -> bytebase.v1.IamPolicy
+ 2, // 3: bytebase.v1.WorkspaceService.SetIamPolicy:output_type -> bytebase.v1.IamPolicy
+ 2, // [2:4] is the sub-list for method output_type
+ 0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
@@ -176,33 +73,18 @@ func file_v1_workspace_service_proto_init() {
return
}
file_v1_iam_policy_proto_init()
- if !protoimpl.UnsafeEnabled {
- file_v1_workspace_service_proto_msgTypes[0].Exporter = func(v any, i int) any {
- switch v := v.(*PatchIamPolicyRequest); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- }
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_v1_workspace_service_proto_rawDesc,
NumEnums: 0,
- NumMessages: 1,
+ NumMessages: 0,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_v1_workspace_service_proto_goTypes,
DependencyIndexes: file_v1_workspace_service_proto_depIdxs,
- MessageInfos: file_v1_workspace_service_proto_msgTypes,
}.Build()
File_v1_workspace_service_proto = out.File
file_v1_workspace_service_proto_rawDesc = nil
diff --git a/proto/generated-go/v1/workspace_service.pb.gw.go b/proto/generated-go/v1/workspace_service.pb.gw.go
index b6bd9d0efe..1048eb58e4 100644
--- a/proto/generated-go/v1/workspace_service.pb.gw.go
+++ b/proto/generated-go/v1/workspace_service.pb.gw.go
@@ -143,66 +143,6 @@ func local_request_WorkspaceService_SetIamPolicy_0(ctx context.Context, marshale
}
-func request_WorkspaceService_PatchIamPolicy_0(ctx context.Context, marshaler runtime.Marshaler, client WorkspaceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
- var protoReq PatchIamPolicyRequest
- var metadata runtime.ServerMetadata
-
- if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
- }
-
- var (
- val string
- ok bool
- err error
- _ = err
- )
-
- val, ok = pathParams["resource"]
- if !ok {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "resource")
- }
-
- protoReq.Resource, err = runtime.String(val)
- if err != nil {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "resource", err)
- }
-
- msg, err := client.PatchIamPolicy(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
- return msg, metadata, err
-
-}
-
-func local_request_WorkspaceService_PatchIamPolicy_0(ctx context.Context, marshaler runtime.Marshaler, server WorkspaceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
- var protoReq PatchIamPolicyRequest
- var metadata runtime.ServerMetadata
-
- if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
- }
-
- var (
- val string
- ok bool
- err error
- _ = err
- )
-
- val, ok = pathParams["resource"]
- if !ok {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "resource")
- }
-
- protoReq.Resource, err = runtime.String(val)
- if err != nil {
- return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "resource", err)
- }
-
- msg, err := server.PatchIamPolicy(ctx, &protoReq)
- return msg, metadata, err
-
-}
-
// RegisterWorkspaceServiceHandlerServer registers the http handlers for service WorkspaceService to "mux".
// UnaryRPC :call WorkspaceServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@@ -259,31 +199,6 @@ func RegisterWorkspaceServiceHandlerServer(ctx context.Context, mux *runtime.Ser
})
- mux.Handle("PATCH", pattern_WorkspaceService_PatchIamPolicy_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
- ctx, cancel := context.WithCancel(req.Context())
- defer cancel()
- var stream runtime.ServerTransportStream
- ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
- inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
- var err error
- var annotatedContext context.Context
- annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/PatchIamPolicy", runtime.WithHTTPPathPattern("/v1/{resource=workspaces/*}:patchIamPolicy"))
- if err != nil {
- runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
- return
- }
- resp, md, err := local_request_WorkspaceService_PatchIamPolicy_0(annotatedContext, inboundMarshaler, server, req, pathParams)
- md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
- annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
- if err != nil {
- runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
- return
- }
-
- forward_WorkspaceService_PatchIamPolicy_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
- })
-
return nil
}
@@ -369,28 +284,6 @@ func RegisterWorkspaceServiceHandlerClient(ctx context.Context, mux *runtime.Ser
})
- mux.Handle("PATCH", pattern_WorkspaceService_PatchIamPolicy_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
- ctx, cancel := context.WithCancel(req.Context())
- defer cancel()
- inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
- var err error
- var annotatedContext context.Context
- annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/PatchIamPolicy", runtime.WithHTTPPathPattern("/v1/{resource=workspaces/*}:patchIamPolicy"))
- if err != nil {
- runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
- return
- }
- resp, md, err := request_WorkspaceService_PatchIamPolicy_0(annotatedContext, inboundMarshaler, client, req, pathParams)
- annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
- if err != nil {
- runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
- return
- }
-
- forward_WorkspaceService_PatchIamPolicy_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
-
- })
-
return nil
}
@@ -398,14 +291,10 @@ var (
pattern_WorkspaceService_GetIamPolicy_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2}, []string{"v1", "workspaces", "resource"}, "getIamPolicy"))
pattern_WorkspaceService_SetIamPolicy_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2}, []string{"v1", "workspaces", "resource"}, "setIamPolicy"))
-
- pattern_WorkspaceService_PatchIamPolicy_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2}, []string{"v1", "workspaces", "resource"}, "patchIamPolicy"))
)
var (
forward_WorkspaceService_GetIamPolicy_0 = runtime.ForwardResponseMessage
forward_WorkspaceService_SetIamPolicy_0 = runtime.ForwardResponseMessage
-
- forward_WorkspaceService_PatchIamPolicy_0 = runtime.ForwardResponseMessage
)
diff --git a/proto/generated-go/v1/workspace_service_grpc.pb.go b/proto/generated-go/v1/workspace_service_grpc.pb.go
index 22de3537e8..8fbc6591e0 100644
--- a/proto/generated-go/v1/workspace_service_grpc.pb.go
+++ b/proto/generated-go/v1/workspace_service_grpc.pb.go
@@ -19,9 +19,8 @@ import (
const _ = grpc.SupportPackageIsVersion8
const (
- WorkspaceService_GetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/GetIamPolicy"
- WorkspaceService_SetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/SetIamPolicy"
- WorkspaceService_PatchIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/PatchIamPolicy"
+ WorkspaceService_GetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/GetIamPolicy"
+ WorkspaceService_SetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/SetIamPolicy"
)
// WorkspaceServiceClient is the client API for WorkspaceService service.
@@ -30,7 +29,6 @@ const (
type WorkspaceServiceClient interface {
GetIamPolicy(ctx context.Context, in *GetIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error)
SetIamPolicy(ctx context.Context, in *SetIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error)
- PatchIamPolicy(ctx context.Context, in *PatchIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error)
}
type workspaceServiceClient struct {
@@ -61,23 +59,12 @@ func (c *workspaceServiceClient) SetIamPolicy(ctx context.Context, in *SetIamPol
return out, nil
}
-func (c *workspaceServiceClient) PatchIamPolicy(ctx context.Context, in *PatchIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error) {
- cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
- out := new(IamPolicy)
- err := c.cc.Invoke(ctx, WorkspaceService_PatchIamPolicy_FullMethodName, in, out, cOpts...)
- if err != nil {
- return nil, err
- }
- return out, nil
-}
-
// WorkspaceServiceServer is the server API for WorkspaceService service.
// All implementations must embed UnimplementedWorkspaceServiceServer
// for forward compatibility
type WorkspaceServiceServer interface {
GetIamPolicy(context.Context, *GetIamPolicyRequest) (*IamPolicy, error)
SetIamPolicy(context.Context, *SetIamPolicyRequest) (*IamPolicy, error)
- PatchIamPolicy(context.Context, *PatchIamPolicyRequest) (*IamPolicy, error)
mustEmbedUnimplementedWorkspaceServiceServer()
}
@@ -91,9 +78,6 @@ func (UnimplementedWorkspaceServiceServer) GetIamPolicy(context.Context, *GetIam
func (UnimplementedWorkspaceServiceServer) SetIamPolicy(context.Context, *SetIamPolicyRequest) (*IamPolicy, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetIamPolicy not implemented")
}
-func (UnimplementedWorkspaceServiceServer) PatchIamPolicy(context.Context, *PatchIamPolicyRequest) (*IamPolicy, error) {
- return nil, status.Errorf(codes.Unimplemented, "method PatchIamPolicy not implemented")
-}
func (UnimplementedWorkspaceServiceServer) mustEmbedUnimplementedWorkspaceServiceServer() {}
// UnsafeWorkspaceServiceServer may be embedded to opt out of forward compatibility for this service.
@@ -143,24 +127,6 @@ func _WorkspaceService_SetIamPolicy_Handler(srv interface{}, ctx context.Context
return interceptor(ctx, in, info, handler)
}
-func _WorkspaceService_PatchIamPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
- in := new(PatchIamPolicyRequest)
- if err := dec(in); err != nil {
- return nil, err
- }
- if interceptor == nil {
- return srv.(WorkspaceServiceServer).PatchIamPolicy(ctx, in)
- }
- info := &grpc.UnaryServerInfo{
- Server: srv,
- FullMethod: WorkspaceService_PatchIamPolicy_FullMethodName,
- }
- handler := func(ctx context.Context, req interface{}) (interface{}, error) {
- return srv.(WorkspaceServiceServer).PatchIamPolicy(ctx, req.(*PatchIamPolicyRequest))
- }
- return interceptor(ctx, in, info, handler)
-}
-
// WorkspaceService_ServiceDesc is the grpc.ServiceDesc for WorkspaceService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -176,10 +142,6 @@ var WorkspaceService_ServiceDesc = grpc.ServiceDesc{
MethodName: "SetIamPolicy",
Handler: _WorkspaceService_SetIamPolicy_Handler,
},
- {
- MethodName: "PatchIamPolicy",
- Handler: _WorkspaceService_PatchIamPolicy_Handler,
- },
},
Streams: []grpc.StreamDesc{},
Metadata: "v1/workspace_service.proto",
diff --git a/proto/v1/iam_policy.proto b/proto/v1/iam_policy.proto
index 158ddf369a..568cfb05d0 100644
--- a/proto/v1/iam_policy.proto
+++ b/proto/v1/iam_policy.proto
@@ -22,12 +22,20 @@ message SetIamPolicyRequest {
string resource = 1 [(google.api.field_behavior) = REQUIRED];
IamPolicy policy = 2 [(google.api.field_behavior) = REQUIRED];
+
+ // The current etag of the policy.
+ string etag = 3;
}
message IamPolicy {
// Collection of binding.
// A binding binds one or more project members to a single project role.
repeated Binding bindings = 1;
+
+ // The current etag of the policy.
+ // If an etag is provided and does not match the current etag of the poliy,
+ // the call will be blocked and an ABORTED error will be returned.
+ string etag = 2;
}
message Binding {
diff --git a/proto/v1/workspace_service.proto b/proto/v1/workspace_service.proto
index a5a1e4befb..20a6d1ff88 100644
--- a/proto/v1/workspace_service.proto
+++ b/proto/v1/workspace_service.proto
@@ -3,7 +3,6 @@ syntax = "proto3";
package bytebase.v1;
import "google/api/annotations.proto";
-import "google/api/field_behavior.proto";
import "v1/iam_policy.proto";
option go_package = "generated-go/v1";
@@ -19,25 +18,4 @@ service WorkspaceService {
body: "*"
};
}
-
- rpc PatchIamPolicy(PatchIamPolicyRequest) returns (IamPolicy) {
- option (google.api.http) = {
- patch: "/v1/{resource=workspaces/*}:patchIamPolicy"
- body: "*"
- };
- }
-}
-
-message PatchIamPolicyRequest {
- // The name of the resource to get the IAM policy.
- // Format: workspaces/{workspace}
- string resource = 1 [(google.api.field_behavior) = REQUIRED];
-
- // Specifies the principals requesting access for a Bytebase resource.
- // Format: user:{email}
- string member = 2;
-
- // The roles that is assigned to the member.
- // Format: roles/{role}
- repeated string roles = 3;
}