Skip to content

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

feat(API): workspace listing, switching, and update APIs (#19688)

ecmadaob95b52bb06cc
diff --git a/backend/api/auth/header.go b/backend/api/auth/header.go
index 7123282de3..b5b4156925 100644
--- a/backend/api/auth/header.go
+++ b/backend/api/auth/header.go
@@ -26,12 +26,9 @@ func GetTokenCookie(ctx context.Context, stores *store.Store, licenseService *en
return &http.Cookie{
Name: AccessTokenCookieName,
Value: token,
- // CookieExpDuration expires slightly earlier than the jwt expiration. Client would be logged out if the user
- // cookie expires, thus the client would always logout first before attempting to make a request with the expired jwt.
- // Suppose we have a valid refresh token, we will refresh the token in 2 cases:
- // 1. The access token is about to expire in <<refreshThresholdDuration>>
- // 2. The access token has already expired, we refresh the token so that the ongoing request can pass through.
- Expires: time.Now().Add(tokenDuration - 1*time.Second),
+ // Cookie outlives the JWT so that Refresh() can extract the workspace from the expired token.
+ // The auth middleware rejects expired JWTs, so an expired JWT in the cookie is harmless.
+ Expires: time.Now().Add(tokenDuration + 30*time.Second),
Path: "/",
// Http-only helps mitigate the risk of client side script accessing the protected cookie.
HttpOnly: true,
diff --git a/backend/api/auth/tokens.go b/backend/api/auth/tokens.go
index 9e3d46a01c..51cd96bebb 100644
--- a/backend/api/auth/tokens.go
+++ b/backend/api/auth/tokens.go
@@ -82,6 +82,37 @@ func GenerateOAuth2AccessToken(userEmail, clientID, workspaceID, secret string,
return generateOAuth2Token(userEmail, clientID, workspaceID, OAuth2AccessTokenAudience, expirationTime, []byte(secret))
}
+// ExpiredTokenClaims holds the claims extracted from an expired JWT.
+type ExpiredTokenClaims struct {
+ Subject string
+ WorkspaceID string
+ Audience []string
+}
+
+// ExtractClaimsFromExpiredToken parses a JWT (even if expired) and returns key claims.
+// Signature is still verified. Used by the Refresh endpoint to bind workspace to the session.
+func ExtractClaimsFromExpiredToken(tokenString, secret string) (*ExpiredTokenClaims, error) {
+ claims := &claimsMessage{}
+ parser := jwt.NewParser(jwt.WithoutClaimsValidation())
+ token, err := parser.ParseWithClaims(tokenString, claims, func(t *jwt.Token) (any, error) {
+ if t.Method.Alg() != jwt.SigningMethodHS256.Alg() {
+ return nil, jwt.ErrSignatureInvalid
+ }
+ return []byte(secret), nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ if !token.Valid {
+ return nil, jwt.ErrSignatureInvalid
+ }
+ return &ExpiredTokenClaims{
+ Subject: claims.Subject,
+ WorkspaceID: claims.WorkspaceID,
+ Audience: claims.Audience,
+ }, nil
+}
+
// generateOAuth2Token creates a JWT token with OAuth2-specific claims including client_id.
func generateOAuth2Token(userEmail, clientID, workspaceID, aud string, expirationTime time.Time, secret []byte) (string, error) {
claims := &oauth2ClaimsMessage{
diff --git a/backend/api/mcp/gen/openapi.yaml b/backend/api/mcp/gen/openapi.yaml
index 5bb6ba1679..ecc3a842dd 100644
--- a/backend/api/mcp/gen/openapi.yaml
+++ b/backend/api/mcp/gen/openapi.yaml
@@ -712,6 +712,44 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/bytebase.v1.LoginResponse'
+ /bytebase.v1.AuthService/SwitchWorkspace:
+ post:
+ tags:
+ - bytebase.v1.AuthService
+ summary: SwitchWorkspace
+ description: |-
+ Switches the current user's active workspace and issues new tokens.
+ The user must be a member of the target workspace.
+ operationId: bytebase.v1.AuthService.SwitchWorkspace
+ parameters:
+ - name: Connect-Protocol-Version
+ in: header
+ required: true
+ schema:
+ $ref: '#/components/schemas/connect-protocol-version'
+ - name: Connect-Timeout-Ms
+ in: header
+ schema:
+ $ref: '#/components/schemas/connect-timeout-header'
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.SwitchWorkspaceRequest'
+ required: true
+ responses:
+ default:
+ description: Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/connect.error'
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.LoginResponse'
/bytebase.v1.CelService/BatchDeparse:
post:
tags:
@@ -6941,6 +6979,42 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/bytebase.v1.IamPolicy'
+ /bytebase.v1.WorkspaceService/ListWorkspaces:
+ post:
+ tags:
+ - bytebase.v1.WorkspaceService
+ summary: ListWorkspaces
+ description: Lists all workspaces the current user is a member of.
+ operationId: bytebase.v1.WorkspaceService.ListWorkspaces
+ parameters:
+ - name: Connect-Protocol-Version
+ in: header
+ required: true
+ schema:
+ $ref: '#/components/schemas/connect-protocol-version'
+ - name: Connect-Timeout-Ms
+ in: header
+ schema:
+ $ref: '#/components/schemas/connect-timeout-header'
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.ListWorkspacesRequest'
+ required: true
+ responses:
+ default:
+ description: Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/connect.error'
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.ListWorkspacesResponse'
/bytebase.v1.WorkspaceService/SetIamPolicy:
post:
tags:
@@ -6979,6 +7053,42 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/bytebase.v1.IamPolicy'
+ /bytebase.v1.WorkspaceService/UpdateWorkspace:
+ post:
+ tags:
+ - bytebase.v1.WorkspaceService
+ summary: UpdateWorkspace
+ description: Updates a workspace. Currently only title can be updated.
+ operationId: bytebase.v1.WorkspaceService.UpdateWorkspace
+ parameters:
+ - name: Connect-Protocol-Version
+ in: header
+ required: true
+ schema:
+ $ref: '#/components/schemas/connect-protocol-version'
+ - name: Connect-Timeout-Ms
+ in: header
+ schema:
+ $ref: '#/components/schemas/connect-timeout-header'
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.UpdateWorkspaceRequest'
+ required: true
+ responses:
+ default:
+ description: Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/connect.error'
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
components:
schemas:
bytebase.v1.AIChatMessage:
@@ -13377,6 +13487,20 @@ components:
title: ListWorkloadIdentitiesResponse
additionalProperties: false
description: Response message for listing workload identities.
+ bytebase.v1.ListWorkspacesRequest:
+ type: object
+ title: ListWorkspacesRequest
+ additionalProperties: false
+ bytebase.v1.ListWorkspacesResponse:
+ type: object
+ properties:
+ workspaces:
+ type: array
+ items:
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
+ title: workspaces
+ title: ListWorkspacesResponse
+ additionalProperties: false
bytebase.v1.LoginRequest:
type: object
properties:
@@ -16962,6 +17086,39 @@ components:
description: Whether high availability (multiple replicas) is enabled.
title: Subscription
additionalProperties: false
+ bytebase.v1.SwitchWorkspaceRequest:
+ type: object
+ properties:
+ workspace:
+ type: string
+ title: workspace
+ description: |-
+ The target workspace to switch to.
+ Format: workspaces/{workspace}
+ web:
+ type: boolean
+ title: web
+ description: If true, sets tokens as HTTP-only cookies (browser clients).
+ otpCode:
+ type:
+ - string
+ - "null"
+ title: otp_code
+ description: OTP code for MFA verification. Required if the target workspace enforces MFA.
+ recoveryCode:
+ type:
+ - string
+ - "null"
+ title: recovery_code
+ description: Recovery code for MFA verification (alternative to otp_code).
+ mfaTempToken:
+ type:
+ - string
+ - "null"
+ title: mfa_temp_token
+ description: Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token.
+ title: SwitchWorkspaceRequest
+ additionalProperties: false
bytebase.v1.SyncDatabaseRequest:
type: object
properties:
@@ -18806,6 +18963,17 @@ components:
$ref: '#/components/schemas/google.protobuf.FieldMask'
title: UpdateWorksheetRequest
additionalProperties: false
+ bytebase.v1.UpdateWorkspaceRequest:
+ type: object
+ properties:
+ workspace:
+ title: workspace
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
+ updateMask:
+ title: update_mask
+ $ref: '#/components/schemas/google.protobuf.FieldMask'
+ title: UpdateWorkspaceRequest
+ additionalProperties: false
bytebase.v1.User:
type: object
properties:
@@ -19172,6 +19340,18 @@ components:
title: folders
title: WorksheetOrganizer
additionalProperties: false
+ bytebase.v1.Workspace:
+ type: object
+ properties:
+ name:
+ type: string
+ title: name
+ description: 'Format: workspaces/{workspace}'
+ title:
+ type: string
+ title: title
+ title: Workspace
+ additionalProperties: false
bytebase.v1.WorkspaceApprovalSetting:
type: object
properties:
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 725cfbc997..91ca57e3a8 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -195,16 +195,18 @@ func (s *AuthService) Signup(ctx context.Context, req *connect.Request[v1pb.Sign
}
// Step 1: Resolve workspace — check if user belongs to an existing workspace.
- memberName := common.FormatUserEmail(request.Email)
- workspaces, err := s.store.FindWorkspacesByMemberEmail(ctx, memberName, !s.profile.SaaS)
+ existingWS, err := s.store.FindWorkspace(ctx, &store.FindWorkspaceMessage{
+ Email: request.Email,
+ IncludeAllUser: !s.profile.SaaS,
+ })
if err != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to find workspaces"))
}
var workspaceID string
- isMember := len(workspaces) > 0
+ isMember := existingWS != nil
if isMember {
- workspaceID = workspaces[0].ResourceID
+ workspaceID = existingWS.ResourceID
} else if !s.profile.SaaS {
// Self-hosted: join the existing workspace (will be added as member in step 3).
// No workspace membership found. Check if any workspace exists.
@@ -380,11 +382,39 @@ func (s *AuthService) Refresh(ctx context.Context, req *connect.Request[v1pb.Ref
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("user not found"))
}
- // 5. Issue new tokens — preserve the workspace from the original login session.
- workspaceID, err := s.resolveWorkspaceForRefresh(ctx, user)
+ // 5. Extract workspace from the access token cookie (still present because cookie
+ // outlives the JWT by 30 seconds). This ensures per-session workspace isolation.
+ // Also verify the token's subject matches the refresh token's user to prevent
+ // pairing a refresh token with an access token from a different session.
+ accessTokenStr, err := auth.GetTokenFromHeaders(req.Header())
+ if err != nil {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.Wrap(err, "invalid access token header"))
+ }
+ if accessTokenStr == "" {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("access token cookie required for refresh"))
+ }
+ tokenClaims, err := auth.ExtractClaimsFromExpiredToken(accessTokenStr, s.secret)
+ if err != nil || tokenClaims.WorkspaceID == "" {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("failed to extract workspace from access token"))
+ }
+ if tokenClaims.Subject != stored.UserEmail {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("access token does not match refresh token"))
+ }
+ workspaceID := tokenClaims.WorkspaceID
+
+ // Verify the user is still a member of the workspace.
+ ws, err := s.store.FindWorkspace(ctx, &store.FindWorkspaceMessage{
+ WorkspaceID: &workspaceID,
+ Email: user.Email,
+ IncludeAllUser: !s.profile.SaaS,
+ })
if err != nil {
- return nil, connect.NewError(connect.CodeUnauthenticated, errors.Wrap(err, "failed to resolve workspace"))
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to verify workspace membership"))
}
+ if ws == nil {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.Errorf("user %q is no longer a member of workspace %q", user.Email, workspaceID))
+ }
+
accessTokenDuration := auth.GetAccessTokenDuration(ctx, s.store, s.licenseService, workspaceID)
accessToken, err := auth.GenerateAccessToken(user.Email, workspaceID, s.secret, accessTokenDuration)
if err != nil {
@@ -924,7 +954,6 @@ func (s *AuthService) generateLoginToken(ctx context.Context, user *store.UserMe
// otherwise falls back to the first workspace from IAM membership.
func (s *AuthService) resolveWorkspaceForLogin(ctx context.Context, user *store.UserMessage) (string, error) {
// Determine member name format based on user type.
- var memberName string
switch user.Type {
case storepb.PrincipalType_SERVICE_ACCOUNT:
// SA has workspace on its record — look it up directly.
@@ -937,59 +966,200 @@ func (s *AuthService) resolveWorkspaceForLogin(ctx context.Context, user *store.
}
return "", errors.Errorf("service account %q not found", user.Email)
case storepb.PrincipalType_END_USER:
- memberName = common.FormatUserEmail(user.Email)
+ includeAllUser := !s.profile.SaaS
+
+ // Prefer the last login workspace if it's still valid.
+ if lastWS := user.Profile.GetLastLoginWorkspace(); lastWS != "" {
+ ws, err := s.store.FindWorkspace(ctx, &store.FindWorkspaceMessage{
+ WorkspaceID: &lastWS,
+ Email: user.Email,
+ IncludeAllUser: includeAllUser,
+ })
+ if err != nil {
+ return "", errors.Wrap(err, "failed to find workspace")
+ }
+ if ws != nil {
+ return ws.ResourceID, nil
+ }
+ // Last login workspace no longer valid — fall through to default.
+ }
+
+ // Use the first workspace the user is a member of.
+ ws, err := s.store.FindWorkspace(ctx, &store.FindWorkspaceMessage{
+ Email: user.Email,
+ IncludeAllUser: includeAllUser,
+ })
+ if err != nil {
+ return "", errors.Wrap(err, "failed to find workspace")
+ }
+ if ws == nil {
+ return "", errors.Errorf("%q is not a member of any workspace", user.Email)
+ }
+ return ws.ResourceID, nil
default:
return "", errors.Errorf("unsupported user type %s for login", user.Type)
}
+}
+
+// SwitchWorkspace switches the current user's active workspace and issues new tokens.
+func (s *AuthService) SwitchWorkspace(ctx context.Context, req *connect.Request[v1pb.SwitchWorkspaceRequest]) (*connect.Response[v1pb.LoginResponse], error) {
+ request := req.Msg
+ if request.Workspace == "" {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("workspace is required"))
+ }
- includeAllUser := !s.profile.SaaS
+ workspaceID, err := common.GetWorkspaceID(request.Workspace)
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Wrap(err, "invalid workspace name"))
+ }
+
+ user, ok := GetUserFromContext(ctx)
+ if !ok || user == nil {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("user not found"))
+ }
+ if user.Type != storepb.PrincipalType_END_USER {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("only end users can switch workspaces"))
+ }
+
+ // Reject OAuth2 tokens — they are bound to a specific workspace via the OAuth client
+ // and must not be used to mint plain user tokens for other workspaces.
+ accessTokenStr, _ := auth.GetTokenFromHeaders(req.Header())
+ if accessTokenStr != "" {
+ tokenClaims, err := auth.ExtractClaimsFromExpiredToken(accessTokenStr, s.secret)
+ if err == nil && slices.Contains(tokenClaims.Audience, auth.OAuth2AccessTokenAudience) {
+ return nil, connect.NewError(connect.CodePermissionDenied, errors.New("OAuth2 tokens cannot be used to switch workspaces"))
+ }
+ }
+
+ // Verify the user is a member of the target workspace.
+ ws, err := s.store.FindWorkspace(ctx, &store.FindWorkspaceMessage{
+ WorkspaceID: &workspaceID,
+ Email: user.Email,
+ IncludeAllUser: !s.profile.SaaS,
+ })
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to find workspace"))
+ }
+ if ws == nil {
+ return nil, connect.NewError(connect.CodePermissionDenied, errors.Errorf("not a member of workspace %q", workspaceID))
+ }
+
+ // Validate the target workspace's sign-in policies.
+ if user.MemberDeleted {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("user has been deactivated"))
+ }
+ if err := validateEmailWithDomains(ctx, s.licenseService, s.store, workspaceID, user.Email, false); err != nil {
+ return nil, err
+ }
- // Prefer the last login workspace if it's still valid.
- if lastWS := user.Profile.GetLastLoginWorkspace(); lastWS != "" {
- workspaces, err := s.store.FindWorkspacesByMemberEmail(ctx, memberName, includeAllUser)
+ // Check MFA requirement for the target workspace.
+ mfaSecondStep := request.GetMfaTempToken() != ""
+ if mfaSecondStep {
+ // Check MFA lockout before verifying.
+ if err := s.checkMFALockout(ctx, user.Email); err != nil {
+ return nil, err
+ }
+ // Verify the MFA temp token and OTP/recovery code.
+ mfaEmail, err := auth.GetUserEmailFromMFATempToken(*request.MfaTempToken, s.secret)
if err != nil {
- return "", errors.Wrap(err, "failed to find workspaces for user")
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("invalid MFA temp token"))
+ }
+ if mfaEmail != user.Email {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("MFA token does not match user"))
}
- for _, ws := range workspaces {
- if ws.ResourceID == lastWS {
- return lastWS, nil
+ if request.OtpCode != nil {
+ if err := challengeMFACode(user, *request.OtpCode); err != nil {
+ return nil, err
}
+ } else if request.RecoveryCode != nil {
+ if err := s.challengeRecoveryCode(ctx, user, *request.RecoveryCode); err != nil {
+ return nil, err
+ }
+ } else {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("OTP or recovery code required"))
}
- // Last login workspace no longer valid (removed from membership or deleted).
- // Fall through to default selection.
- if len(workspaces) > 0 {
- return workspaces[0].ResourceID, nil
+ } else {
+ // First step: check if MFA is required for the target workspace.
+ if resp, err := s.checkMFARequired(ctx, user, workspaceID, false); err != nil {
+ return nil, err
+ } else if resp != nil {
+ return resp, nil
}
- return "", errors.Errorf("%q is not a member of any workspace", memberName)
}
- // No last login workspace — use the first one.
- return s.store.FindWorkspaceIDByMemberEmail(ctx, memberName, includeAllUser)
-}
-
-// resolveWorkspaceForRefresh returns the workspace for a token refresh.
-// It must return the same workspace as the original login session.
-// If the user is no longer a member of that workspace, the refresh fails.
-func (s *AuthService) resolveWorkspaceForRefresh(ctx context.Context, user *store.UserMessage) (string, error) {
- workspaceID := user.Profile.GetLastLoginWorkspace()
- if workspaceID == "" {
- // Fallback for users who logged in before last_login_workspace was implemented.
- return s.resolveWorkspaceForLogin(ctx, user)
+ // Generate new token with target workspace.
+ token, err := s.generateLoginToken(ctx, user, workspaceID)
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to generate token"))
}
- // Verify the user is still a member of the workspace.
- includeAllUser := !s.profile.SaaS
- memberName := common.FormatUserEmail(user.Email)
- workspaces, err := s.store.FindWorkspacesByMemberEmail(ctx, memberName, includeAllUser)
- if err != nil {
- return "", errors.Wrap(err, "failed to find workspaces for user")
+ // Update last login workspace.
+ if _, err := s.store.UpdateUser(ctx, user, &store.UpdateUserMessage{
+ Profile: &storepb.UserProfile{
+ LastLoginTime: user.Profile.GetLastLoginTime(),
+ LastChangePasswordTime: user.Profile.GetLastChangePasswordTime(),
+ Source: user.Profile.GetSource(),
+ LastLoginWorkspace: workspaceID,
+ },
+ }); err != nil {
+ slog.Error("failed to update user profile", log.BBError(err))
}
- for _, ws := range workspaces {
- if ws.ResourceID == workspaceID {
- return workspaceID, nil
+
+ // Build response.
+ response := &v1pb.LoginResponse{}
+ resp := connect.NewResponse(response)
+
+ if request.Web {
+ // Require a valid refresh token cookie — prevents non-web clients from
+ // upgrading a short-lived bearer token into a long-lived web session.
+ oldRefreshToken := auth.GetRefreshTokenFromCookie(req.Header())
+ if oldRefreshToken == "" {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("refresh token cookie required for web workspace switch"))
+ }
+ oldStored, err := s.store.GetAndDeleteWebRefreshToken(ctx, auth.HashToken(oldRefreshToken))
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to consume refresh token"))
+ }
+ if oldStored == nil {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("invalid or expired refresh token"))
+ }
+ if oldStored.UserEmail != user.Email {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("refresh token does not belong to current user"))
+ }
+ sessionExpiresAt := oldStored.ExpiresAt
+ if sessionExpiresAt.IsZero() {
+ sessionExpiresAt = time.Now().Add(auth.GetRefreshTokenDuration(ctx, s.store, s.licenseService, workspaceID))
}
+
+ origin := req.Header().Get("Origin")
+ cookie := auth.GetTokenCookie(ctx, s.store, s.licenseService, workspaceID, origin, token)
+ resp.Header().Add("Set-Cookie", cookie.String())
+
+ newRefreshToken, err := auth.GenerateOpaqueToken()
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to generate refresh token"))
+ }
+ if err := s.store.CreateWebRefreshToken(ctx, &store.WebRefreshTokenMessage{
+ TokenHash: auth.HashToken(newRefreshToken),
+ UserEmail: user.Email,
+ ExpiresAt: sessionExpiresAt,
+ }); err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to create refresh token"))
+ }
+ refreshCookie := auth.GetRefreshTokenCookie(origin, newRefreshToken, time.Until(sessionExpiresAt))
+ resp.Header().Add("Set-Cookie", refreshCookie.String())
+ } else {
+ response.Token = token
+ }
+
+ v1User, err := convertToUser(ctx, s.iamManager, user)
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to convert user"))
}
- return "", errors.Errorf("user %q is no longer a member of workspace %q", user.Email, workspaceID)
+ v1User.Workspace = common.FormatWorkspace(workspaceID)
+ response.User = v1User
+
+ return resp, nil
}
// finalizeLogin builds the response, sets cookies if needed, and updates the user profile.
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 13f0c4fdd9..08dd217117 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -35,6 +35,67 @@ func NewWorkspaceService(store *store.Store, iamManager *iam.Manager, profile *c
}
}
+func (s *WorkspaceService) ListWorkspaces(ctx context.Context, _ *connect.Request[v1pb.ListWorkspacesRequest]) (*connect.Response[v1pb.ListWorkspacesResponse], error) {
+ user, ok := GetUserFromContext(ctx)
+ if !ok || user == nil {
+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("user not found"))
+ }
+
+ workspaces, err := s.store.ListWorkspacesByEmail(ctx, &store.FindWorkspaceMessage{
+ Email: user.Email,
+ IncludeAllUser: !s.profile.SaaS,
+ })
+ if err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to find workspaces"))
+ }
+
+ var result []*v1pb.Workspace
+ for _, ws := range workspaces {
+ result = append(result, &v1pb.Workspace{
+ Name: common.FormatWorkspace(ws.ResourceID),
+ Title: ws.Name,
+ })
+ }
+ return connect.NewResponse(&v1pb.ListWorkspacesResponse{Workspaces: result}), nil
+}
+
+func (s *WorkspaceService) UpdateWorkspace(ctx context.Context, req *connect.Request[v1pb.UpdateWorkspaceRequest]) (*connect.Response[v1pb.Workspace], error) {
+ ws := req.Msg.Workspace
+ if ws == nil {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("workspace is required"))
+ }
+ if req.Msg.UpdateMask == nil {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("update_mask must be set"))
+ }
+ if len(req.Msg.UpdateMask.GetPaths()) == 0 {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("update_mask is required"))
+ }
+
+ patch := &store.UpdateWorkspaceMessage{
+ ResourceID: common.GetWorkspaceIDFromContext(ctx),
+ }
+ for _, path := range req.Msg.UpdateMask.GetPaths() {
+ switch path {
+ case "title":
+ if ws.Title == "" {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("title cannot be empty"))
+ }
+ patch.Title = &ws.Title
+ default:
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unsupported field: %q", path))
+ }
+ }
+
+ if err := s.store.UpdateWorkspace(ctx, patch); err != nil {
+ return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to update workspace"))
+ }
+
+ return connect.NewResponse(&v1pb.Workspace{
+ Name: ws.Name,
+ Title: ws.Title,
+ }), nil
+}
+
func (s *WorkspaceService) GetIamPolicy(ctx context.Context, _ *connect.Request[v1pb.GetIamPolicyRequest]) (*connect.Response[v1pb.IamPolicy], error) {
policy, err := s.store.GetWorkspaceIamPolicy(ctx, common.GetWorkspaceIDFromContext(ctx))
if err != nil {
diff --git a/backend/common/permission/permission.go b/backend/common/permission/permission.go
index 6dca516568..f11cb2b5a4 100644
--- a/backend/common/permission/permission.go
+++ b/backend/common/permission/permission.go
@@ -151,6 +151,7 @@ const (
WorksheetsManage Permission = "bb.worksheets.manage"
WorkspacesGetIamPolicy Permission = "bb.workspaces.getIamPolicy"
WorkspacesSetIamPolicy Permission = "bb.workspaces.setIamPolicy"
+ WorkspacesUpdate Permission = "bb.workspaces.update"
)
var allPermissions = func() []Permission {
diff --git a/backend/common/permission/permission.yaml b/backend/common/permission/permission.yaml
index 5aabcc5146..57b76ff0d2 100644
--- a/backend/common/permission/permission.yaml
+++ b/backend/common/permission/permission.yaml
@@ -137,4 +137,5 @@ permissions:
- bb.workloadIdentities.undelete
- bb.workloadIdentities.update
- bb.workspaces.getIamPolicy
+ - bb.workspaces.update
- bb.workspaces.setIamPolicy
diff --git a/backend/enterprise/license.go b/backend/enterprise/license.go
index 460e62968e..d31949f7be 100644
--- a/backend/enterprise/license.go
+++ b/backend/enterprise/license.go
@@ -163,7 +163,7 @@ func NewLicenseService(mode common.ReleaseMode, store *store.Store, saas bool) (
store: store,
config: config,
saas: saas,
- cache: expirable.NewLRU[string, *v1pb.Subscription](1, nil, 1*time.Minute),
+ cache: expirable.NewLRU[string, *v1pb.Subscription](128, nil, 1*time.Minute),
}
service.replicaCache.Store(&replicaCacheState{
replicaCount: 1,
@@ -181,6 +181,9 @@ func licenseCacheKey(workspaceID string) string {
// If there is no license, we will return a free plan subscription without expiration time.
// If there is expired license, we will return a free plan subscription with the expiration time of the expired license.
func (s *LicenseService) LoadSubscription(ctx context.Context, workspaceID string) *v1pb.Subscription {
+ if workspaceID == "" {
+ return defaultFreeSubscription
+ }
key := licenseCacheKey(workspaceID)
// Fast path: cache hit (TTL handled automatically by expirable.LRU)
@@ -196,7 +199,13 @@ func (s *LicenseService) LoadSubscription(ctx context.Context, workspaceID strin
}
subscription := s.loadSubscriptionFromDB(ctx, workspaceID)
- s.cache.Add(key, subscription)
+
+ // Only cache non-free subscriptions. Free plan may be a transient failure
+ // (e.g. DB not ready during startup), and caching it would mask the real
+ // license for the TTL duration.
+ if subscription.Plan != v1pb.PlanType_FREE {
+ s.cache.Add(key, subscription)
+ }
return subscription, nil
})
diff --git a/backend/generated-go/v1/auth_service.pb.go b/backend/generated-go/v1/auth_service.pb.go
index 872f9d194b..a386ae588d 100644
--- a/backend/generated-go/v1/auth_service.pb.go
+++ b/backend/generated-go/v1/auth_service.pb.go
@@ -657,6 +657,88 @@ func (*RefreshResponse) Descriptor() ([]byte, []int) {
return file_v1_auth_service_proto_rawDescGZIP(), []int{10}
}
+type SwitchWorkspaceRequest struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ // The target workspace to switch to.
+ // Format: workspaces/{workspace}
+ Workspace string `protobuf:"bytes,1,opt,name=workspace,proto3" json:"workspace,omitempty"`
+ // If true, sets tokens as HTTP-only cookies (browser clients).
+ Web bool `protobuf:"varint,2,opt,name=web,proto3" json:"web,omitempty"`
+ // OTP code for MFA verification. Required if the target workspace enforces MFA.
+ OtpCode *string `protobuf:"bytes,3,opt,name=otp_code,json=otpCode,proto3,oneof" json:"otp_code,omitempty"`
+ // Recovery code for MFA verification (alternative to otp_code).
+ RecoveryCode *string `protobuf:"bytes,4,opt,name=recovery_code,json=recoveryCode,proto3,oneof" json:"recovery_code,omitempty"`
+ // Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token.
+ MfaTempToken *string `protobuf:"bytes,5,opt,name=mfa_temp_token,json=mfaTempToken,proto3,oneof" json:"mfa_temp_token,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *SwitchWorkspaceRequest) Reset() {
+ *x = SwitchWorkspaceRequest{}
+ mi := &file_v1_auth_service_proto_msgTypes[11]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *SwitchWorkspaceRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*SwitchWorkspaceRequest) ProtoMessage() {}
+
+func (x *SwitchWorkspaceRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_auth_service_proto_msgTypes[11]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use SwitchWorkspaceRequest.ProtoReflect.Descriptor instead.
+func (*SwitchWorkspaceRequest) Descriptor() ([]byte, []int) {
+ return file_v1_auth_service_proto_rawDescGZIP(), []int{11}
+}
+
+func (x *SwitchWorkspaceRequest) GetWorkspace() string {
+ if x != nil {
+ return x.Workspace
+ }
+ return ""
+}
+
+func (x *SwitchWorkspaceRequest) GetWeb() bool {
+ if x != nil {
+ return x.Web
+ }
+ return false
+}
+
+func (x *SwitchWorkspaceRequest) GetOtpCode() string {
+ if x != nil && x.OtpCode != nil {
+ return *x.OtpCode
+ }
+ return ""
+}
+
+func (x *SwitchWorkspaceRequest) GetRecoveryCode() string {
+ if x != nil && x.RecoveryCode != nil {
+ return *x.RecoveryCode
+ }
+ return ""
+}
+
+func (x *SwitchWorkspaceRequest) GetMfaTempToken() string {
+ if x != nil && x.MfaTempToken != nil {
+ return *x.MfaTempToken
+ }
+ return ""
+}
+
var File_v1_auth_service_proto protoreflect.FileDescriptor
const file_v1_auth_service_proto_rawDesc = "" +
@@ -700,13 +782,23 @@ const file_v1_auth_service_proto_rawDesc = "" +
"\bpassword\x18\x02 \x01(\tR\bpassword\x12\x14\n" +
"\x05title\x18\x03 \x01(\tR\x05title\"\x10\n" +
"\x0eRefreshRequest\"\x11\n" +
- "\x0fRefreshResponse2\xa3\x04\n" +
+ "\x0fRefreshResponse\"\xef\x01\n" +
+ "\x16SwitchWorkspaceRequest\x12\x1c\n" +
+ "\tworkspace\x18\x01 \x01(\tR\tworkspace\x12\x10\n" +
+ "\x03web\x18\x02 \x01(\bR\x03web\x12\x1e\n" +
+ "\botp_code\x18\x03 \x01(\tH\x00R\aotpCode\x88\x01\x01\x12(\n" +
+ "\rrecovery_code\x18\x04 \x01(\tH\x01R\frecoveryCode\x88\x01\x01\x12)\n" +
+ "\x0emfa_temp_token\x18\x05 \x01(\tH\x02R\fmfaTempToken\x88\x01\x01B\v\n" +
+ "\t_otp_codeB\x10\n" +
+ "\x0e_recovery_codeB\x11\n" +
+ "\x0f_mfa_temp_token2\xa0\x05\n" +
"\vAuthService\x12a\n" +
"\x05Login\x12\x19.bytebase.v1.LoginRequest\x1a\x1a.bytebase.v1.LoginResponse\"!\x80\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02\x13:\x01*\"\x0e/v1/auth/login\x12`\n" +
"\x06Logout\x12\x1a.bytebase.v1.LogoutRequest\x1a\x16.google.protobuf.Empty\"\"\x80\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/v1/auth/logout\x12\x81\x01\n" +
"\rExchangeToken\x12!.bytebase.v1.ExchangeTokenRequest\x1a\".bytebase.v1.ExchangeTokenResponse\")\x80\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/v1/auth:exchangeToken\x12d\n" +
"\x06Signup\x12\x1a.bytebase.v1.SignupRequest\x1a\x1a.bytebase.v1.LoginResponse\"\"\x80\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/v1/auth/signup\x12e\n" +
- "\aRefresh\x12\x1b.bytebase.v1.RefreshRequest\x1a\x1c.bytebase.v1.RefreshResponse\"\x1f\x80\xea0\x01\x82\xd3\xe4\x93\x02\x15:\x01*\"\x10/v1/auth/refreshB\xa6\x01\n" +
+ "\aRefresh\x12\x1b.bytebase.v1.RefreshRequest\x1a\x1c.bytebase.v1.RefreshResponse\"\x1f\x80\xea0\x01\x82\xd3\xe4\x93\x02\x15:\x01*\"\x10/v1/auth/refresh\x12{\n" +
+ "\x0fSwitchWorkspace\x12#.bytebase.v1.SwitchWorkspaceRequest\x1a\x1a.bytebase.v1.LoginResponse\"'\x90\xea0\x02\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/v1/auth:switchWorkspaceB\xa6\x01\n" +
"\x0fcom.bytebase.v1B\x10AuthServiceProtoP\x01Z4github.com/bytebase/bytebase/backend/generated-go/v1\xa2\x02\x03BXX\xaa\x02\vBytebase.V1\xca\x02\vBytebase\\V1\xe2\x02\x17Bytebase\\V1\\GPBMetadata\xea\x02\fBytebase::V1b\x06proto3"
var (
@@ -721,7 +813,7 @@ func file_v1_auth_service_proto_rawDescGZIP() []byte {
return file_v1_auth_service_proto_rawDescData
}
-var file_v1_auth_service_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
+var file_v1_auth_service_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_v1_auth_service_proto_goTypes = []any{
(*LoginRequest)(nil), // 0: bytebase.v1.LoginRequest
(*IdentityProviderContext)(nil), // 1: bytebase.v1.IdentityProviderContext
@@ -734,26 +826,29 @@ var file_v1_auth_service_proto_goTypes = []any{
(*SignupRequest)(nil), // 8: bytebase.v1.SignupRequest
(*RefreshRequest)(nil), // 9: bytebase.v1.RefreshRequest
(*RefreshResponse)(nil), // 10: bytebase.v1.RefreshResponse
- (*User)(nil), // 11: bytebase.v1.User
- (*emptypb.Empty)(nil), // 12: google.protobuf.Empty
+ (*SwitchWorkspaceRequest)(nil), // 11: bytebase.v1.SwitchWorkspaceRequest
+ (*User)(nil), // 12: bytebase.v1.User
+ (*emptypb.Empty)(nil), // 13: google.protobuf.Empty
}
var file_v1_auth_service_proto_depIdxs = []int32{
1, // 0: bytebase.v1.LoginRequest.idp_context:type_name -> bytebase.v1.IdentityProviderContext
2, // 1: bytebase.v1.IdentityProviderContext.oauth2_context:type_name -> bytebase.v1.OAuth2IdentityProviderContext
3, // 2: bytebase.v1.IdentityProviderContext.oidc_context:type_name -> bytebase.v1.OIDCIdentityProviderContext
- 11, // 3: bytebase.v1.LoginResponse.user:type_name -> bytebase.v1.User
+ 12, // 3: bytebase.v1.LoginResponse.user:type_name -> bytebase.v1.User
0, // 4: bytebase.v1.AuthService.Login:input_type -> bytebase.v1.LoginRequest
5, // 5: bytebase.v1.AuthService.Logout:input_type -> bytebase.v1.LogoutRequest
6, // 6: bytebase.v1.AuthService.ExchangeToken:input_type -> bytebase.v1.ExchangeTokenRequest
8, // 7: bytebase.v1.AuthService.Signup:input_type -> bytebase.v1.SignupRequest
9, // 8: bytebase.v1.AuthService.Refresh:input_type -> bytebase.v1.RefreshRequest
- 4, // 9: bytebase.v1.AuthService.Login:output_type -> bytebase.v1.LoginResponse
- 12, // 10: bytebase.v1.AuthService.Logout:output_type -> google.protobuf.Empty
- 7, // 11: bytebase.v1.AuthService.ExchangeToken:output_type -> bytebase.v1.ExchangeTokenResponse
- 4, // 12: bytebase.v1.AuthService.Signup:output_type -> bytebase.v1.LoginResponse
- 10, // 13: bytebase.v1.AuthService.Refresh:output_type -> bytebase.v1.RefreshResponse
- 9, // [9:14] is the sub-list for method output_type
- 4, // [4:9] is the sub-list for method input_type
+ 11, // 9: bytebase.v1.AuthService.SwitchWorkspace:input_type -> bytebase.v1.SwitchWorkspaceRequest
+ 4, // 10: bytebase.v1.AuthService.Login:output_type -> bytebase.v1.LoginResponse
+ 13, // 11: bytebase.v1.AuthService.Logout:output_type -> google.protobuf.Empty
+ 7, // 12: bytebase.v1.AuthService.ExchangeToken:output_type -> bytebase.v1.ExchangeTokenResponse
+ 4, // 13: bytebase.v1.AuthService.Signup:output_type -> bytebase.v1.LoginResponse
+ 10, // 14: bytebase.v1.AuthService.Refresh:output_type -> bytebase.v1.RefreshResponse
+ 4, // 15: bytebase.v1.AuthService.SwitchWorkspace:output_type -> bytebase.v1.LoginResponse
+ 10, // [10:16] is the sub-list for method output_type
+ 4, // [4:10] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
@@ -772,13 +867,14 @@ func file_v1_auth_service_proto_init() {
(*IdentityProviderContext_OidcContext)(nil),
}
file_v1_auth_service_proto_msgTypes[4].OneofWrappers = []any{}
+ file_v1_auth_service_proto_msgTypes[11].OneofWrappers = []any{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_v1_auth_service_proto_rawDesc), len(file_v1_auth_service_proto_rawDesc)),
NumEnums: 0,
- NumMessages: 11,
+ NumMessages: 12,
NumExtensions: 0,
NumServices: 1,
},
diff --git a/backend/generated-go/v1/auth_service.pb.gw.go b/backend/generated-go/v1/auth_service.pb.gw.go
index d68aea696d..b1cbfa2f0b 100644
--- a/backend/generated-go/v1/auth_service.pb.gw.go
+++ b/backend/generated-go/v1/auth_service.pb.gw.go
@@ -170,6 +170,33 @@ func local_request_AuthService_Refresh_0(ctx context.Context, marshaler runtime.
return msg, metadata, err
}
+func request_AuthService_SwitchWorkspace_0(ctx context.Context, marshaler runtime.Marshaler, client AuthServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq SwitchWorkspaceRequest
+ metadata runtime.ServerMetadata
+ )
+ if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if req.Body != nil {
+ _, _ = io.Copy(io.Discard, req.Body)
+ }
+ msg, err := client.SwitchWorkspace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
+ return msg, metadata, err
+}
+
+func local_request_AuthService_SwitchWorkspace_0(ctx context.Context, marshaler runtime.Marshaler, server AuthServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq SwitchWorkspaceRequest
+ metadata runtime.ServerMetadata
+ )
+ if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ msg, err := server.SwitchWorkspace(ctx, &protoReq)
+ return msg, metadata, err
+}
+
// RegisterAuthServiceHandlerServer registers the http handlers for service AuthService to "mux".
// UnaryRPC :call AuthServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@@ -276,6 +303,26 @@ func RegisterAuthServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
}
forward_AuthService_Refresh_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
+ mux.Handle(http.MethodPost, pattern_AuthService_SwitchWorkspace_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)
+ annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/bytebase.v1.AuthService/SwitchWorkspace", runtime.WithHTTPPathPattern("/v1/auth:switchWorkspace"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := local_request_AuthService_SwitchWorkspace_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_AuthService_SwitchWorkspace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
return nil
}
@@ -401,21 +448,40 @@ func RegisterAuthServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
}
forward_AuthService_Refresh_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
+ mux.Handle(http.MethodPost, pattern_AuthService_SwitchWorkspace_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)
+ annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/bytebase.v1.AuthService/SwitchWorkspace", runtime.WithHTTPPathPattern("/v1/auth:switchWorkspace"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := request_AuthService_SwitchWorkspace_0(annotatedContext, inboundMarshaler, client, req, pathParams)
+ annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
+ if err != nil {
+ runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ forward_AuthService_SwitchWorkspace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
return nil
}
var (
- pattern_AuthService_Login_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "login"}, ""))
- pattern_AuthService_Logout_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "logout"}, ""))
- pattern_AuthService_ExchangeToken_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "auth"}, "exchangeToken"))
- pattern_AuthService_Signup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "signup"}, ""))
- pattern_AuthService_Refresh_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "refresh"}, ""))
+ pattern_AuthService_Login_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "login"}, ""))
+ pattern_AuthService_Logout_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "logout"}, ""))
+ pattern_AuthService_ExchangeToken_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "auth"}, "exchangeToken"))
+ pattern_AuthService_Signup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "signup"}, ""))
+ pattern_AuthService_Refresh_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "auth", "refresh"}, ""))
+ pattern_AuthService_SwitchWorkspace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "auth"}, "switchWorkspace"))
)
var (
- forward_AuthService_Login_0 = runtime.ForwardResponseMessage
- forward_AuthService_Logout_0 = runtime.ForwardResponseMessage
- forward_AuthService_ExchangeToken_0 = runtime.ForwardResponseMessage
- forward_AuthService_Signup_0 = runtime.ForwardResponseMessage
- forward_AuthService_Refresh_0 = runtime.ForwardResponseMessage
+ forward_AuthService_Login_0 = runtime.ForwardResponseMessage
+ forward_AuthService_Logout_0 = runtime.ForwardResponseMessage
+ forward_AuthService_ExchangeToken_0 = runtime.ForwardResponseMessage
+ forward_AuthService_Signup_0 = runtime.ForwardResponseMessage
+ forward_AuthService_Refresh_0 = runtime.ForwardResponseMessage
+ forward_AuthService_SwitchWorkspace_0 = runtime.ForwardResponseMessage
)
diff --git a/backend/generated-go/v1/auth_service_equal.pb.go b/backend/generated-go/v1/auth_service_equal.pb.go
index b8671dfaa5..09f6623e36 100644
--- a/backend/generated-go/v1/auth_service_equal.pb.go
+++ b/backend/generated-go/v1/auth_service_equal.pb.go
@@ -178,3 +178,28 @@ func (x *RefreshResponse) Equal(y *RefreshResponse) bool {
}
return true
}
+
+func (x *SwitchWorkspaceRequest) Equal(y *SwitchWorkspaceRequest) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ if x.Workspace != y.Workspace {
+ return false
+ }
+ if x.Web != y.Web {
+ return false
+ }
+ if p, q := x.OtpCode, y.OtpCode; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {
+ return false
+ }
+ if p, q := x.RecoveryCode, y.RecoveryCode; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {
+ return false
+ }
+ if p, q := x.MfaTempToken, y.MfaTempToken; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) {
+ return false
+ }
+ return true
+}
diff --git a/backend/generated-go/v1/auth_service_grpc.pb.go b/backend/generated-go/v1/auth_service_grpc.pb.go
index cefc68ab37..52114bf089 100644
--- a/backend/generated-go/v1/auth_service_grpc.pb.go
+++ b/backend/generated-go/v1/auth_service_grpc.pb.go
@@ -20,11 +20,12 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
- AuthService_Login_FullMethodName = "/bytebase.v1.AuthService/Login"
- AuthService_Logout_FullMethodName = "/bytebase.v1.AuthService/Logout"
- AuthService_ExchangeToken_FullMethodName = "/bytebase.v1.AuthService/ExchangeToken"
- AuthService_Signup_FullMethodName = "/bytebase.v1.AuthService/Signup"
- AuthService_Refresh_FullMethodName = "/bytebase.v1.AuthService/Refresh"
+ AuthService_Login_FullMethodName = "/bytebase.v1.AuthService/Login"
+ AuthService_Logout_FullMethodName = "/bytebase.v1.AuthService/Logout"
+ AuthService_ExchangeToken_FullMethodName = "/bytebase.v1.AuthService/ExchangeToken"
+ AuthService_Signup_FullMethodName = "/bytebase.v1.AuthService/Signup"
+ AuthService_Refresh_FullMethodName = "/bytebase.v1.AuthService/Refresh"
+ AuthService_SwitchWorkspace_FullMethodName = "/bytebase.v1.AuthService/SwitchWorkspace"
)
// AuthServiceClient is the client API for AuthService service.
@@ -51,6 +52,9 @@ type AuthServiceClient interface {
// Refreshes the access token using the refresh token cookie.
// Permissions required: None (validates via refresh token cookie)
Refresh(ctx context.Context, in *RefreshRequest, opts ...grpc.CallOption) (*RefreshResponse, error)
+ // Switches the current user's active workspace and issues new tokens.
+ // The user must be a member of the target workspace.
+ SwitchWorkspace(ctx context.Context, in *SwitchWorkspaceRequest, opts ...grpc.CallOption) (*LoginResponse, error)
}
type authServiceClient struct {
@@ -111,6 +115,16 @@ func (c *authServiceClient) Refresh(ctx context.Context, in *RefreshRequest, opt
return out, nil
}
+func (c *authServiceClient) SwitchWorkspace(ctx context.Context, in *SwitchWorkspaceRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
+ out := new(LoginResponse)
+ err := c.cc.Invoke(ctx, AuthService_SwitchWorkspace_FullMethodName, in, out, cOpts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
// AuthServiceServer is the server API for AuthService service.
// All implementations must embed UnimplementedAuthServiceServer
// for forward compatibility.
@@ -135,6 +149,9 @@ type AuthServiceServer interface {
// Refreshes the access token using the refresh token cookie.
// Permissions required: None (validates via refresh token cookie)
Refresh(context.Context, *RefreshRequest) (*RefreshResponse, error)
+ // Switches the current user's active workspace and issues new tokens.
+ // The user must be a member of the target workspace.
+ SwitchWorkspace(context.Context, *SwitchWorkspaceRequest) (*LoginResponse, error)
mustEmbedUnimplementedAuthServiceServer()
}
@@ -160,6 +177,9 @@ func (UnimplementedAuthServiceServer) Signup(context.Context, *SignupRequest) (*
func (UnimplementedAuthServiceServer) Refresh(context.Context, *RefreshRequest) (*RefreshResponse, error) {
return nil, status.Error(codes.Unimplemented, "method Refresh not implemented")
}
+func (UnimplementedAuthServiceServer) SwitchWorkspace(context.Context, *SwitchWorkspaceRequest) (*LoginResponse, error) {
+ return nil, status.Error(codes.Unimplemented, "method SwitchWorkspace not implemented")
+}
func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {}
func (UnimplementedAuthServiceServer) testEmbeddedByValue() {}
@@ -271,6 +291,24 @@ func _AuthService_Refresh_Handler(srv interface{}, ctx context.Context, dec func
return interceptor(ctx, in, info, handler)
}
+func _AuthService_SwitchWorkspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(SwitchWorkspaceRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(AuthServiceServer).SwitchWorkspace(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: AuthService_SwitchWorkspace_FullMethodName,
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(AuthServiceServer).SwitchWorkspace(ctx, req.(*SwitchWorkspaceRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -298,6 +336,10 @@ var AuthService_ServiceDesc = grpc.ServiceDesc{
MethodName: "Refresh",
Handler: _AuthService_Refresh_Handler,
},
+ {
+ MethodName: "SwitchWorkspace",
+ Handler: _AuthService_SwitchWorkspace_Handler,
+ },
},
Streams: []grpc.StreamDesc{},
Metadata: "v1/auth_service.proto",
diff --git a/backend/generated-go/v1/v1connect/auth_service.connect.go b/backend/generated-go/v1/v1connect/auth_service.connect.go
index b3f225dd21..671bb6bc8d 100644
--- a/backend/generated-go/v1/v1connect/auth_service.connect.go
+++ b/backend/generated-go/v1/v1connect/auth_service.connect.go
@@ -45,6 +45,9 @@ const (
AuthServiceSignupProcedure = "/bytebase.v1.AuthService/Signup"
// AuthServiceRefreshProcedure is the fully-qualified name of the AuthService's Refresh RPC.
AuthServiceRefreshProcedure = "/bytebase.v1.AuthService/Refresh"
+ // AuthServiceSwitchWorkspaceProcedure is the fully-qualified name of the AuthService's
+ // SwitchWorkspace RPC.
+ AuthServiceSwitchWorkspaceProcedure = "/bytebase.v1.AuthService/SwitchWorkspace"
)
// AuthServiceClient is a client for the bytebase.v1.AuthService service.
@@ -67,6 +70,9 @@ type AuthServiceClient interface {
// Refreshes the access token using the refresh token cookie.
// Permissions required: None (validates via refresh token cookie)
Refresh(context.Context, *connect.Request[v1.RefreshRequest]) (*connect.Response[v1.RefreshResponse], error)
+ // Switches the current user's active workspace and issues new tokens.
+ // The user must be a member of the target workspace.
+ SwitchWorkspace(context.Context, *connect.Request[v1.SwitchWorkspaceRequest]) (*connect.Response[v1.LoginResponse], error)
}
// NewAuthServiceClient constructs a client for the bytebase.v1.AuthService service. By default, it
@@ -110,16 +116,23 @@ func NewAuthServiceClient(httpClient connect.HTTPClient, baseURL string, opts ..
connect.WithSchema(authServiceMethods.ByName("Refresh")),
connect.WithClientOptions(opts...),
),
+ switchWorkspace: connect.NewClient[v1.SwitchWorkspaceRequest, v1.LoginResponse](
+ httpClient,
+ baseURL+AuthServiceSwitchWorkspaceProcedure,
+ connect.WithSchema(authServiceMethods.ByName("SwitchWorkspace")),
+ connect.WithClientOptions(opts...),
+ ),
}
}
// authServiceClient implements AuthServiceClient.
type authServiceClient struct {
- login *connect.Client[v1.LoginRequest, v1.LoginResponse]
- logout *connect.Client[v1.LogoutRequest, emptypb.Empty]
- exchangeToken *connect.Client[v1.ExchangeTokenRequest, v1.ExchangeTokenResponse]
- signup *connect.Client[v1.SignupRequest, v1.LoginResponse]
- refresh *connect.Client[v1.RefreshRequest, v1.RefreshResponse]
+ login *connect.Client[v1.LoginRequest, v1.LoginResponse]
+ logout *connect.Client[v1.LogoutRequest, emptypb.Empty]
+ exchangeToken *connect.Client[v1.ExchangeTokenRequest, v1.ExchangeTokenResponse]
+ signup *connect.Client[v1.SignupRequest, v1.LoginResponse]
+ refresh *connect.Client[v1.RefreshRequest, v1.RefreshResponse]
+ switchWorkspace *connect.Client[v1.SwitchWorkspaceRequest, v1.LoginResponse]
}
// Login calls bytebase.v1.AuthService.Login.
@@ -147,6 +160,11 @@ func (c *authServiceClient) Refresh(ctx context.Context, req *connect.Request[v1
return c.refresh.CallUnary(ctx, req)
}
+// SwitchWorkspace calls bytebase.v1.AuthService.SwitchWorkspace.
+func (c *authServiceClient) SwitchWorkspace(ctx context.Context, req *connect.Request[v1.SwitchWorkspaceRequest]) (*connect.Response[v1.LoginResponse], error) {
+ return c.switchWorkspace.CallUnary(ctx, req)
+}
+
// AuthServiceHandler is an implementation of the bytebase.v1.AuthService service.
type AuthServiceHandler interface {
// Authenticates a user and returns access tokens.
@@ -167,6 +185,9 @@ type AuthServiceHandler interface {
// Refreshes the access token using the refresh token cookie.
// Permissions required: None (validates via refresh token cookie)
Refresh(context.Context, *connect.Request[v1.RefreshRequest]) (*connect.Response[v1.RefreshResponse], error)
+ // Switches the current user's active workspace and issues new tokens.
+ // The user must be a member of the target workspace.
+ SwitchWorkspace(context.Context, *connect.Request[v1.SwitchWorkspaceRequest]) (*connect.Response[v1.LoginResponse], error)
}
// NewAuthServiceHandler builds an HTTP handler from the service implementation. It returns the path
@@ -206,6 +227,12 @@ func NewAuthServiceHandler(svc AuthServiceHandler, opts ...connect.HandlerOption
connect.WithSchema(authServiceMethods.ByName("Refresh")),
connect.WithHandlerOptions(opts...),
)
+ authServiceSwitchWorkspaceHandler := connect.NewUnaryHandler(
+ AuthServiceSwitchWorkspaceProcedure,
+ svc.SwitchWorkspace,
+ connect.WithSchema(authServiceMethods.ByName("SwitchWorkspace")),
+ connect.WithHandlerOptions(opts...),
+ )
return "/bytebase.v1.AuthService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case AuthServiceLoginProcedure:
@@ -218,6 +245,8 @@ func NewAuthServiceHandler(svc AuthServiceHandler, opts ...connect.HandlerOption
authServiceSignupHandler.ServeHTTP(w, r)
case AuthServiceRefreshProcedure:
authServiceRefreshHandler.ServeHTTP(w, r)
+ case AuthServiceSwitchWorkspaceProcedure:
+ authServiceSwitchWorkspaceHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
@@ -246,3 +275,7 @@ func (UnimplementedAuthServiceHandler) Signup(context.Context, *connect.Request[
func (UnimplementedAuthServiceHandler) Refresh(context.Context, *connect.Request[v1.RefreshRequest]) (*connect.Response[v1.RefreshResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("bytebase.v1.AuthService.Refresh is not implemented"))
}
+
+func (UnimplementedAuthServiceHandler) SwitchWorkspace(context.Context, *connect.Request[v1.SwitchWorkspaceRequest]) (*connect.Response[v1.LoginResponse], error) {
+ return nil, connect.NewError(connect.CodeUnimplemented, errors.New("bytebase.v1.AuthService.SwitchWorkspace is not implemented"))
+}
diff --git a/backend/generated-go/v1/v1connect/workspace_service.connect.go b/backend/generated-go/v1/v1connect/workspace_service.connect.go
index 0dcedd1d2f..683310912c 100644
--- a/backend/generated-go/v1/v1connect/workspace_service.connect.go
+++ b/backend/generated-go/v1/v1connect/workspace_service.connect.go
@@ -33,6 +33,12 @@ const (
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
+ // WorkspaceServiceListWorkspacesProcedure is the fully-qualified name of the WorkspaceService's
+ // ListWorkspaces RPC.
+ WorkspaceServiceListWorkspacesProcedure = "/bytebase.v1.WorkspaceService/ListWorkspaces"
+ // WorkspaceServiceUpdateWorkspaceProcedure is the fully-qualified name of the WorkspaceService's
+ // UpdateWorkspace RPC.
+ WorkspaceServiceUpdateWorkspaceProcedure = "/bytebase.v1.WorkspaceService/UpdateWorkspace"
// WorkspaceServiceGetIamPolicyProcedure is the fully-qualified name of the WorkspaceService's
// GetIamPolicy RPC.
WorkspaceServiceGetIamPolicyProcedure = "/bytebase.v1.WorkspaceService/GetIamPolicy"
@@ -43,6 +49,10 @@ const (
// WorkspaceServiceClient is a client for the bytebase.v1.WorkspaceService service.
type WorkspaceServiceClient interface {
+ // Lists all workspaces the current user is a member of.
+ ListWorkspaces(context.Context, *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error)
+ // Updates a workspace. Currently only title can be updated.
+ UpdateWorkspace(context.Context, *connect.Request[v1.UpdateWorkspaceRequest]) (*connect.Response[v1.Workspace], error)
// Retrieves IAM policy for the workspace.
// Permissions required: bb.workspaces.getIamPolicy
GetIamPolicy(context.Context, *connect.Request[v1.GetIamPolicyRequest]) (*connect.Response[v1.IamPolicy], error)
@@ -62,6 +72,18 @@ func NewWorkspaceServiceClient(httpClient connect.HTTPClient, baseURL string, op
baseURL = strings.TrimRight(baseURL, "/")
workspaceServiceMethods := v1.File_v1_workspace_service_proto.Services().ByName("WorkspaceService").Methods()
return &workspaceServiceClient{
+ listWorkspaces: connect.NewClient[v1.ListWorkspacesRequest, v1.ListWorkspacesResponse](
+ httpClient,
+ baseURL+WorkspaceServiceListWorkspacesProcedure,
+ connect.WithSchema(workspaceServiceMethods.ByName("ListWorkspaces")),
+ connect.WithClientOptions(opts...),
+ ),
+ updateWorkspace: connect.NewClient[v1.UpdateWorkspaceRequest, v1.Workspace](
+ httpClient,
+ baseURL+WorkspaceServiceUpdateWorkspaceProcedure,
+ connect.WithSchema(workspaceServiceMethods.ByName("UpdateWorkspace")),
+ connect.WithClientOptions(opts...),
+ ),
getIamPolicy: connect.NewClient[v1.GetIamPolicyRequest, v1.IamPolicy](
httpClient,
baseURL+WorkspaceServiceGetIamPolicyProcedure,
@@ -79,8 +101,20 @@ func NewWorkspaceServiceClient(httpClient connect.HTTPClient, baseURL string, op
// workspaceServiceClient implements WorkspaceServiceClient.
type workspaceServiceClient struct {
- getIamPolicy *connect.Client[v1.GetIamPolicyRequest, v1.IamPolicy]
- setIamPolicy *connect.Client[v1.SetIamPolicyRequest, v1.IamPolicy]
+ listWorkspaces *connect.Client[v1.ListWorkspacesRequest, v1.ListWorkspacesResponse]
+ updateWorkspace *connect.Client[v1.UpdateWorkspaceRequest, v1.Workspace]
+ getIamPolicy *connect.Client[v1.GetIamPolicyRequest, v1.IamPolicy]
+ setIamPolicy *connect.Client[v1.SetIamPolicyRequest, v1.IamPolicy]
+}
+
+// ListWorkspaces calls bytebase.v1.WorkspaceService.ListWorkspaces.
+func (c *workspaceServiceClient) ListWorkspaces(ctx context.Context, req *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error) {
+ return c.listWorkspaces.CallUnary(ctx, req)
+}
+
+// UpdateWorkspace calls bytebase.v1.WorkspaceService.UpdateWorkspace.
+func (c *workspaceServiceClient) UpdateWorkspace(ctx context.Context, req *connect.Request[v1.UpdateWorkspaceRequest]) (*connect.Response[v1.Workspace], error) {
+ return c.updateWorkspace.CallUnary(ctx, req)
}
// GetIamPolicy calls bytebase.v1.WorkspaceService.GetIamPolicy.
@@ -95,6 +129,10 @@ func (c *workspaceServiceClient) SetIamPolicy(ctx context.Context, req *connect.
// WorkspaceServiceHandler is an implementation of the bytebase.v1.WorkspaceService service.
type WorkspaceServiceHandler interface {
+ // Lists all workspaces the current user is a member of.
+ ListWorkspaces(context.Context, *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error)
+ // Updates a workspace. Currently only title can be updated.
+ UpdateWorkspace(context.Context, *connect.Request[v1.UpdateWorkspaceRequest]) (*connect.Response[v1.Workspace], error)
// Retrieves IAM policy for the workspace.
// Permissions required: bb.workspaces.getIamPolicy
GetIamPolicy(context.Context, *connect.Request[v1.GetIamPolicyRequest]) (*connect.Response[v1.IamPolicy], error)
@@ -110,6 +148,18 @@ type WorkspaceServiceHandler interface {
// and JSON codecs. They also support gzip compression.
func NewWorkspaceServiceHandler(svc WorkspaceServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
workspaceServiceMethods := v1.File_v1_workspace_service_proto.Services().ByName("WorkspaceService").Methods()
+ workspaceServiceListWorkspacesHandler := connect.NewUnaryHandler(
+ WorkspaceServiceListWorkspacesProcedure,
+ svc.ListWorkspaces,
+ connect.WithSchema(workspaceServiceMethods.ByName("ListWorkspaces")),
+ connect.WithHandlerOptions(opts...),
+ )
+ workspaceServiceUpdateWorkspaceHandler := connect.NewUnaryHandler(
+ WorkspaceServiceUpdateWorkspaceProcedure,
+ svc.UpdateWorkspace,
+ connect.WithSchema(workspaceServiceMethods.ByName("UpdateWorkspace")),
+ connect.WithHandlerOptions(opts...),
+ )
workspaceServiceGetIamPolicyHandler := connect.NewUnaryHandler(
WorkspaceServiceGetIamPolicyProcedure,
svc.GetIamPolicy,
@@ -124,6 +174,10 @@ func NewWorkspaceServiceHandler(svc WorkspaceServiceHandler, opts ...connect.Han
)
return "/bytebase.v1.WorkspaceService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
+ case WorkspaceServiceListWorkspacesProcedure:
+ workspaceServiceListWorkspacesHandler.ServeHTTP(w, r)
+ case WorkspaceServiceUpdateWorkspaceProcedure:
+ workspaceServiceUpdateWorkspaceHandler.ServeHTTP(w, r)
case WorkspaceServiceGetIamPolicyProcedure:
workspaceServiceGetIamPolicyHandler.ServeHTTP(w, r)
case WorkspaceServiceSetIamPolicyProcedure:
@@ -137,6 +191,14 @@ func NewWorkspaceServiceHandler(svc WorkspaceServiceHandler, opts ...connect.Han
// UnimplementedWorkspaceServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedWorkspaceServiceHandler struct{}
+func (UnimplementedWorkspaceServiceHandler) ListWorkspaces(context.Context, *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error) {
+ return nil, connect.NewError(connect.CodeUnimplemented, errors.New("bytebase.v1.WorkspaceService.ListWorkspaces is not implemented"))
+}
+
+func (UnimplementedWorkspaceServiceHandler) UpdateWorkspace(context.Context, *connect.Request[v1.UpdateWorkspaceRequest]) (*connect.Response[v1.Workspace], error) {
+ return nil, connect.NewError(connect.CodeUnimplemented, errors.New("bytebase.v1.WorkspaceService.UpdateWorkspace is not implemented"))
+}
+
func (UnimplementedWorkspaceServiceHandler) GetIamPolicy(context.Context, *connect.Request[v1.GetIamPolicyRequest]) (*connect.Response[v1.IamPolicy], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("bytebase.v1.WorkspaceService.GetIamPolicy is not implemented"))
}
diff --git a/backend/generated-go/v1/workspace_service.pb.go b/backend/generated-go/v1/workspace_service.pb.go
index ea73ac95ee..e42b4c88a0 100644
--- a/backend/generated-go/v1/workspace_service.pb.go
+++ b/backend/generated-go/v1/workspace_service.pb.go
@@ -10,7 +10,9 @@ import (
_ "google.golang.org/genproto/googleapis/api/annotations"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
reflect "reflect"
+ sync "sync"
unsafe "unsafe"
)
@@ -21,31 +23,255 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
+type ListWorkspacesRequest struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *ListWorkspacesRequest) Reset() {
+ *x = ListWorkspacesRequest{}
+ mi := &file_v1_workspace_service_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *ListWorkspacesRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ListWorkspacesRequest) ProtoMessage() {}
+
+func (x *ListWorkspacesRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_workspace_service_proto_msgTypes[0]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use ListWorkspacesRequest.ProtoReflect.Descriptor instead.
+func (*ListWorkspacesRequest) Descriptor() ([]byte, []int) {
+ return file_v1_workspace_service_proto_rawDescGZIP(), []int{0}
+}
+
+type ListWorkspacesResponse struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Workspaces []*Workspace `protobuf:"bytes,1,rep,name=workspaces,proto3" json:"workspaces,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *ListWorkspacesResponse) Reset() {
+ *x = ListWorkspacesResponse{}
+ mi := &file_v1_workspace_service_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *ListWorkspacesResponse) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ListWorkspacesResponse) ProtoMessage() {}
+
+func (x *ListWorkspacesResponse) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_workspace_service_proto_msgTypes[1]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use ListWorkspacesResponse.ProtoReflect.Descriptor instead.
+func (*ListWorkspacesResponse) Descriptor() ([]byte, []int) {
+ return file_v1_workspace_service_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *ListWorkspacesResponse) GetWorkspaces() []*Workspace {
+ if x != nil {
+ return x.Workspaces
+ }
+ return nil
+}
+
+type Workspace struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ // Format: workspaces/{workspace}
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *Workspace) Reset() {
+ *x = Workspace{}
+ mi := &file_v1_workspace_service_proto_msgTypes[2]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *Workspace) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*Workspace) ProtoMessage() {}
+
+func (x *Workspace) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_workspace_service_proto_msgTypes[2]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use Workspace.ProtoReflect.Descriptor instead.
+func (*Workspace) Descriptor() ([]byte, []int) {
+ return file_v1_workspace_service_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *Workspace) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+func (x *Workspace) GetTitle() string {
+ if x != nil {
+ return x.Title
+ }
+ return ""
+}
+
+type UpdateWorkspaceRequest struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Workspace *Workspace `protobuf:"bytes,1,opt,name=workspace,proto3" json:"workspace,omitempty"`
+ UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *UpdateWorkspaceRequest) Reset() {
+ *x = UpdateWorkspaceRequest{}
+ mi := &file_v1_workspace_service_proto_msgTypes[3]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *UpdateWorkspaceRequest) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*UpdateWorkspaceRequest) ProtoMessage() {}
+
+func (x *UpdateWorkspaceRequest) ProtoReflect() protoreflect.Message {
+ mi := &file_v1_workspace_service_proto_msgTypes[3]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use UpdateWorkspaceRequest.ProtoReflect.Descriptor instead.
+func (*UpdateWorkspaceRequest) Descriptor() ([]byte, []int) {
+ return file_v1_workspace_service_proto_rawDescGZIP(), []int{3}
+}
+
+func (x *UpdateWorkspaceRequest) GetWorkspace() *Workspace {
+ if x != nil {
+ return x.Workspace
+ }
+ return nil
+}
+
+func (x *UpdateWorkspaceRequest) GetUpdateMask() *fieldmaskpb.FieldMask {
+ if x != nil {
+ return x.UpdateMask
+ }
+ return nil
+}
+
var File_v1_workspace_service_proto protoreflect.FileDescriptor
const file_v1_workspace_service_proto_rawDesc = "" +
"\n" +
- "\x1av1/workspace_service.proto\x12\vbytebase.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x13v1/annotation.proto\x1a\x13v1/iam_policy.proto2\xd7\x02\n" +
- "\x10WorkspaceService\x12\x9c\x01\n" +
+ "\x1av1/workspace_service.proto\x12\vbytebase.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a google/protobuf/field_mask.proto\x1a\x13v1/annotation.proto\x1a\x13v1/iam_policy.proto\"\x17\n" +
+ "\x15ListWorkspacesRequest\"P\n" +
+ "\x16ListWorkspacesResponse\x126\n" +
+ "\n" +
+ "workspaces\x18\x01 \x03(\v2\x16.bytebase.v1.WorkspaceR\n" +
+ "workspaces\"5\n" +
+ "\tWorkspace\x12\x12\n" +
+ "\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
+ "\x05title\x18\x02 \x01(\tR\x05title\"\x90\x01\n" +
+ "\x16UpdateWorkspaceRequest\x129\n" +
+ "\tworkspace\x18\x01 \x01(\v2\x16.bytebase.v1.WorkspaceB\x03\xe0A\x02R\tworkspace\x12;\n" +
+ "\vupdate_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskR\n" +
+ "updateMask2\xed\x04\n" +
+ "\x10WorkspaceService\x12u\n" +
+ "\x0eListWorkspaces\x12\".bytebase.v1.ListWorkspacesRequest\x1a#.bytebase.v1.ListWorkspacesResponse\"\x1a\x90\xea0\x02\x82\xd3\xe4\x93\x02\x10\x12\x0e/v1/workspaces\x12\x9c\x01\n" +
+ "\x0fUpdateWorkspace\x12#.bytebase.v1.UpdateWorkspaceRequest\x1a\x16.bytebase.v1.Workspace\"L\x8a\xea0\x14bb.workspaces.update\x90\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02&:\x01*2!/v1/{workspace.name=workspaces/*}\x12\x9c\x01\n" +
"\fGetIamPolicy\x12 .bytebase.v1.GetIamPolicyRequest\x1a\x16.bytebase.v1.IamPolicy\"R\x8a\xea0\x1abb.workspaces.getIamPolicy\x90\xea0\x01\x82\xd3\xe4\x93\x02*\x12(/v1/{resource=workspaces/*}:getIamPolicy\x12\xa3\x01\n" +
"\fSetIamPolicy\x12 .bytebase.v1.SetIamPolicyRequest\x1a\x16.bytebase.v1.IamPolicy\"Y\x8a\xea0\x1abb.workspaces.setIamPolicy\x90\xea0\x01\x98\xea0\x01\x82\xd3\xe4\x93\x02-:\x01*\"(/v1/{resource=workspaces/*}:setIamPolicyB\xab\x01\n" +
"\x0fcom.bytebase.v1B\x15WorkspaceServiceProtoP\x01Z4github.com/bytebase/bytebase/backend/generated-go/v1\xa2\x02\x03BXX\xaa\x02\vBytebase.V1\xca\x02\vBytebase\\V1\xe2\x02\x17Bytebase\\V1\\GPBMetadata\xea\x02\fBytebase::V1b\x06proto3"
+var (
+ file_v1_workspace_service_proto_rawDescOnce sync.Once
+ file_v1_workspace_service_proto_rawDescData []byte
+)
+
+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(unsafe.Slice(unsafe.StringData(file_v1_workspace_service_proto_rawDesc), len(file_v1_workspace_service_proto_rawDesc)))
+ })
+ return file_v1_workspace_service_proto_rawDescData
+}
+
+var file_v1_workspace_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_v1_workspace_service_proto_goTypes = []any{
- (*GetIamPolicyRequest)(nil), // 0: bytebase.v1.GetIamPolicyRequest
- (*SetIamPolicyRequest)(nil), // 1: bytebase.v1.SetIamPolicyRequest
- (*IamPolicy)(nil), // 2: bytebase.v1.IamPolicy
+ (*ListWorkspacesRequest)(nil), // 0: bytebase.v1.ListWorkspacesRequest
+ (*ListWorkspacesResponse)(nil), // 1: bytebase.v1.ListWorkspacesResponse
+ (*Workspace)(nil), // 2: bytebase.v1.Workspace
+ (*UpdateWorkspaceRequest)(nil), // 3: bytebase.v1.UpdateWorkspaceRequest
+ (*fieldmaskpb.FieldMask)(nil), // 4: google.protobuf.FieldMask
+ (*GetIamPolicyRequest)(nil), // 5: bytebase.v1.GetIamPolicyRequest
+ (*SetIamPolicyRequest)(nil), // 6: bytebase.v1.SetIamPolicyRequest
+ (*IamPolicy)(nil), // 7: bytebase.v1.IamPolicy
}
var file_v1_workspace_service_proto_depIdxs = []int32{
- 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
+ 2, // 0: bytebase.v1.ListWorkspacesResponse.workspaces:type_name -> bytebase.v1.Workspace
+ 2, // 1: bytebase.v1.UpdateWorkspaceRequest.workspace:type_name -> bytebase.v1.Workspace
+ 4, // 2: bytebase.v1.UpdateWorkspaceRequest.update_mask:type_name -> google.protobuf.FieldMask
+ 0, // 3: bytebase.v1.WorkspaceService.ListWorkspaces:input_type -> bytebase.v1.ListWorkspacesRequest
+ 3, // 4: bytebase.v1.WorkspaceService.UpdateWorkspace:input_type -> bytebase.v1.UpdateWorkspaceRequest
+ 5, // 5: bytebase.v1.WorkspaceService.GetIamPolicy:input_type -> bytebase.v1.GetIamPolicyRequest
+ 6, // 6: bytebase.v1.WorkspaceService.SetIamPolicy:input_type -> bytebase.v1.SetIamPolicyRequest
+ 1, // 7: bytebase.v1.WorkspaceService.ListWorkspaces:output_type -> bytebase.v1.ListWorkspacesResponse
+ 2, // 8: bytebase.v1.WorkspaceService.UpdateWorkspace:output_type -> bytebase.v1.Workspace
+ 7, // 9: bytebase.v1.WorkspaceService.GetIamPolicy:output_type -> bytebase.v1.IamPolicy
+ 7, // 10: bytebase.v1.WorkspaceService.SetIamPolicy:output_type -> bytebase.v1.IamPolicy
+ 7, // [7:11] is the sub-list for method output_type
+ 3, // [3:7] is the sub-list for method input_type
+ 3, // [3:3] is the sub-list for extension type_name
+ 3, // [3:3] is the sub-list for extension extendee
+ 0, // [0:3] is the sub-list for field type_name
}
func init() { file_v1_workspace_service_proto_init() }
@@ -61,12 +287,13 @@ func file_v1_workspace_service_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_v1_workspace_service_proto_rawDesc), len(file_v1_workspace_service_proto_rawDesc)),
NumEnums: 0,
- NumMessages: 0,
+ NumMessages: 4,
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_goTypes = nil
diff --git a/backend/generated-go/v1/workspace_service.pb.gw.go b/backend/generated-go/v1/workspace_service.pb.gw.go
index 66840f1119..c86d991310 100644
--- a/backend/generated-go/v1/workspace_service.pb.gw.go
+++ b/backend/generated-go/v1/workspace_service.pb.gw.go
@@ -35,6 +35,72 @@ var (
_ = metadata.Join
)
+func request_WorkspaceService_ListWorkspaces_0(ctx context.Context, marshaler runtime.Marshaler, client WorkspaceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq ListWorkspacesRequest
+ metadata runtime.ServerMetadata
+ )
+ if req.Body != nil {
+ _, _ = io.Copy(io.Discard, req.Body)
+ }
+ msg, err := client.ListWorkspaces(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
+ return msg, metadata, err
+}
+
+func local_request_WorkspaceService_ListWorkspaces_0(ctx context.Context, marshaler runtime.Marshaler, server WorkspaceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq ListWorkspacesRequest
+ metadata runtime.ServerMetadata
+ )
+ msg, err := server.ListWorkspaces(ctx, &protoReq)
+ return msg, metadata, err
+}
+
+func request_WorkspaceService_UpdateWorkspace_0(ctx context.Context, marshaler runtime.Marshaler, client WorkspaceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq UpdateWorkspaceRequest
+ metadata runtime.ServerMetadata
+ err error
+ )
+ if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if req.Body != nil {
+ _, _ = io.Copy(io.Discard, req.Body)
+ }
+ val, ok := pathParams["workspace.name"]
+ if !ok {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "workspace.name")
+ }
+ err = runtime.PopulateFieldFromPath(&protoReq, "workspace.name", val)
+ if err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "workspace.name", err)
+ }
+ msg, err := client.UpdateWorkspace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
+ return msg, metadata, err
+}
+
+func local_request_WorkspaceService_UpdateWorkspace_0(ctx context.Context, marshaler runtime.Marshaler, server WorkspaceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+ var (
+ protoReq UpdateWorkspaceRequest
+ metadata runtime.ServerMetadata
+ err error
+ )
+ if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ val, ok := pathParams["workspace.name"]
+ if !ok {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "workspace.name")
+ }
+ err = runtime.PopulateFieldFromPath(&protoReq, "workspace.name", val)
+ if err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "workspace.name", err)
+ }
+ msg, err := server.UpdateWorkspace(ctx, &protoReq)
+ return msg, metadata, err
+}
+
func request_WorkspaceService_GetIamPolicy_0(ctx context.Context, marshaler runtime.Marshaler, client WorkspaceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq GetIamPolicyRequest
@@ -125,6 +191,46 @@ func local_request_WorkspaceService_SetIamPolicy_0(ctx context.Context, marshale
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterWorkspaceServiceHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterWorkspaceServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WorkspaceServiceServer) error {
+ mux.Handle(http.MethodGet, pattern_WorkspaceService_ListWorkspaces_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)
+ annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/ListWorkspaces", runtime.WithHTTPPathPattern("/v1/workspaces"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := local_request_WorkspaceService_ListWorkspaces_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_ListWorkspaces_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
+ mux.Handle(http.MethodPatch, pattern_WorkspaceService_UpdateWorkspace_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)
+ annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/UpdateWorkspace", runtime.WithHTTPPathPattern("/v1/{workspace.name=workspaces/*}"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := local_request_WorkspaceService_UpdateWorkspace_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_UpdateWorkspace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
mux.Handle(http.MethodGet, pattern_WorkspaceService_GetIamPolicy_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -205,6 +311,40 @@ func RegisterWorkspaceServiceHandler(ctx context.Context, mux *runtime.ServeMux,
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "WorkspaceServiceClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterWorkspaceServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WorkspaceServiceClient) error {
+ mux.Handle(http.MethodGet, pattern_WorkspaceService_ListWorkspaces_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)
+ annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/ListWorkspaces", runtime.WithHTTPPathPattern("/v1/workspaces"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := request_WorkspaceService_ListWorkspaces_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_ListWorkspaces_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
+ mux.Handle(http.MethodPatch, pattern_WorkspaceService_UpdateWorkspace_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)
+ annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/bytebase.v1.WorkspaceService/UpdateWorkspace", runtime.WithHTTPPathPattern("/v1/{workspace.name=workspaces/*}"))
+ if err != nil {
+ runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+ return
+ }
+ resp, md, err := request_WorkspaceService_UpdateWorkspace_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_UpdateWorkspace_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+ })
mux.Handle(http.MethodGet, pattern_WorkspaceService_GetIamPolicy_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -243,11 +383,15 @@ func RegisterWorkspaceServiceHandlerClient(ctx context.Context, mux *runtime.Ser
}
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_ListWorkspaces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "workspaces"}, ""))
+ pattern_WorkspaceService_UpdateWorkspace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2}, []string{"v1", "workspaces", "workspace.name"}, ""))
+ 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"))
)
var (
- forward_WorkspaceService_GetIamPolicy_0 = runtime.ForwardResponseMessage
- forward_WorkspaceService_SetIamPolicy_0 = runtime.ForwardResponseMessage
+ forward_WorkspaceService_ListWorkspaces_0 = runtime.ForwardResponseMessage
+ forward_WorkspaceService_UpdateWorkspace_0 = runtime.ForwardResponseMessage
+ forward_WorkspaceService_GetIamPolicy_0 = runtime.ForwardResponseMessage
+ forward_WorkspaceService_SetIamPolicy_0 = runtime.ForwardResponseMessage
)
diff --git a/backend/generated-go/v1/workspace_service_equal.pb.go b/backend/generated-go/v1/workspace_service_equal.pb.go
index 7d6d8b5131..e6a8aa5124 100644
--- a/backend/generated-go/v1/workspace_service_equal.pb.go
+++ b/backend/generated-go/v1/workspace_service_equal.pb.go
@@ -2,3 +2,72 @@
// source: v1/workspace_service.proto
package v1
+
+import (
+ proto "google.golang.org/protobuf/proto"
+ fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
+)
+
+func (x *ListWorkspacesRequest) Equal(y *ListWorkspacesRequest) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ return true
+}
+
+func (x *ListWorkspacesResponse) Equal(y *ListWorkspacesResponse) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ if len(x.Workspaces) != len(y.Workspaces) {
+ return false
+ }
+ for i := 0; i < len(x.Workspaces); i++ {
+ if !x.Workspaces[i].Equal(y.Workspaces[i]) {
+ return false
+ }
+ }
+ return true
+}
+
+func (x *Workspace) Equal(y *Workspace) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ if x.Name != y.Name {
+ return false
+ }
+ if x.Title != y.Title {
+ return false
+ }
+ return true
+}
+
+func (x *UpdateWorkspaceRequest) Equal(y *UpdateWorkspaceRequest) bool {
+ if x == y {
+ return true
+ }
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
+ if !x.Workspace.Equal(y.Workspace) {
+ return false
+ }
+ if equal, ok := interface{}(x.UpdateMask).(interface {
+ Equal(*fieldmaskpb.FieldMask) bool
+ }); !ok || !equal.Equal(y.UpdateMask) {
+ return false
+ } else if !proto.Equal(x.UpdateMask, y.UpdateMask) {
+ return false
+ }
+ return true
+}
diff --git a/backend/generated-go/v1/workspace_service_grpc.pb.go b/backend/generated-go/v1/workspace_service_grpc.pb.go
index 4cd154da44..b52f6b46f3 100644
--- a/backend/generated-go/v1/workspace_service_grpc.pb.go
+++ b/backend/generated-go/v1/workspace_service_grpc.pb.go
@@ -19,8 +19,10 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
- WorkspaceService_GetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/GetIamPolicy"
- WorkspaceService_SetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/SetIamPolicy"
+ WorkspaceService_ListWorkspaces_FullMethodName = "/bytebase.v1.WorkspaceService/ListWorkspaces"
+ WorkspaceService_UpdateWorkspace_FullMethodName = "/bytebase.v1.WorkspaceService/UpdateWorkspace"
+ WorkspaceService_GetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/GetIamPolicy"
+ WorkspaceService_SetIamPolicy_FullMethodName = "/bytebase.v1.WorkspaceService/SetIamPolicy"
)
// WorkspaceServiceClient is the client API for WorkspaceService service.
@@ -29,6 +31,10 @@ const (
//
// WorkspaceService manages workspace-level operations and profile.
type WorkspaceServiceClient interface {
+ // Lists all workspaces the current user is a member of.
+ ListWorkspaces(ctx context.Context, in *ListWorkspacesRequest, opts ...grpc.CallOption) (*ListWorkspacesResponse, error)
+ // Updates a workspace. Currently only title can be updated.
+ UpdateWorkspace(ctx context.Context, in *UpdateWorkspaceRequest, opts ...grpc.CallOption) (*Workspace, error)
// Retrieves IAM policy for the workspace.
// Permissions required: bb.workspaces.getIamPolicy
GetIamPolicy(ctx context.Context, in *GetIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error)
@@ -45,6 +51,26 @@ func NewWorkspaceServiceClient(cc grpc.ClientConnInterface) WorkspaceServiceClie
return &workspaceServiceClient{cc}
}
+func (c *workspaceServiceClient) ListWorkspaces(ctx context.Context, in *ListWorkspacesRequest, opts ...grpc.CallOption) (*ListWorkspacesResponse, error) {
+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
+ out := new(ListWorkspacesResponse)
+ err := c.cc.Invoke(ctx, WorkspaceService_ListWorkspaces_FullMethodName, in, out, cOpts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *workspaceServiceClient) UpdateWorkspace(ctx context.Context, in *UpdateWorkspaceRequest, opts ...grpc.CallOption) (*Workspace, error) {
+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
+ out := new(Workspace)
+ err := c.cc.Invoke(ctx, WorkspaceService_UpdateWorkspace_FullMethodName, in, out, cOpts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
func (c *workspaceServiceClient) GetIamPolicy(ctx context.Context, in *GetIamPolicyRequest, opts ...grpc.CallOption) (*IamPolicy, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(IamPolicy)
@@ -71,6 +97,10 @@ func (c *workspaceServiceClient) SetIamPolicy(ctx context.Context, in *SetIamPol
//
// WorkspaceService manages workspace-level operations and profile.
type WorkspaceServiceServer interface {
+ // Lists all workspaces the current user is a member of.
+ ListWorkspaces(context.Context, *ListWorkspacesRequest) (*ListWorkspacesResponse, error)
+ // Updates a workspace. Currently only title can be updated.
+ UpdateWorkspace(context.Context, *UpdateWorkspaceRequest) (*Workspace, error)
// Retrieves IAM policy for the workspace.
// Permissions required: bb.workspaces.getIamPolicy
GetIamPolicy(context.Context, *GetIamPolicyRequest) (*IamPolicy, error)
@@ -87,6 +117,12 @@ type WorkspaceServiceServer interface {
// pointer dereference when methods are called.
type UnimplementedWorkspaceServiceServer struct{}
+func (UnimplementedWorkspaceServiceServer) ListWorkspaces(context.Context, *ListWorkspacesRequest) (*ListWorkspacesResponse, error) {
+ return nil, status.Error(codes.Unimplemented, "method ListWorkspaces not implemented")
+}
+func (UnimplementedWorkspaceServiceServer) UpdateWorkspace(context.Context, *UpdateWorkspaceRequest) (*Workspace, error) {
+ return nil, status.Error(codes.Unimplemented, "method UpdateWorkspace not implemented")
+}
func (UnimplementedWorkspaceServiceServer) GetIamPolicy(context.Context, *GetIamPolicyRequest) (*IamPolicy, error) {
return nil, status.Error(codes.Unimplemented, "method GetIamPolicy not implemented")
}
@@ -114,6 +150,42 @@ func RegisterWorkspaceServiceServer(s grpc.ServiceRegistrar, srv WorkspaceServic
s.RegisterService(&WorkspaceService_ServiceDesc, srv)
}
+func _WorkspaceService_ListWorkspaces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(ListWorkspacesRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(WorkspaceServiceServer).ListWorkspaces(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: WorkspaceService_ListWorkspaces_FullMethodName,
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(WorkspaceServiceServer).ListWorkspaces(ctx, req.(*ListWorkspacesRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+func _WorkspaceService_UpdateWorkspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(UpdateWorkspaceRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(WorkspaceServiceServer).UpdateWorkspace(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: WorkspaceService_UpdateWorkspace_FullMethodName,
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(WorkspaceServiceServer).UpdateWorkspace(ctx, req.(*UpdateWorkspaceRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
func _WorkspaceService_GetIamPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetIamPolicyRequest)
if err := dec(in); err != nil {
@@ -157,6 +229,14 @@ var WorkspaceService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "bytebase.v1.WorkspaceService",
HandlerType: (*WorkspaceServiceServer)(nil),
Methods: []grpc.MethodDesc{
+ {
+ MethodName: "ListWorkspaces",
+ Handler: _WorkspaceService_ListWorkspaces_Handler,
+ },
+ {
+ MethodName: "UpdateWorkspace",
+ Handler: _WorkspaceService_UpdateWorkspace_Handler,
+ },
{
MethodName: "GetIamPolicy",
Handler: _WorkspaceService_GetIamPolicy_Handler,
diff --git a/backend/store/predefined_roles.go b/backend/store/predefined_roles.go
index 93cb29cad3..9f81c40d47 100644
--- a/backend/store/predefined_roles.go
+++ b/backend/store/predefined_roles.go
@@ -157,6 +157,7 @@ var PredefinedRoles = []*RoleMessage{
permission.WorksheetsGet,
permission.WorksheetsManage,
permission.WorkspacesGetIamPolicy,
+ permission.WorkspacesUpdate,
permission.WorkspacesSetIamPolicy,
permission.ServiceAccountsCreate,
permission.ServiceAccountsDelete,
diff --git a/backend/store/store.go b/backend/store/store.go
index ad7a78dbe6..3ea9f38ca4 100644
--- a/backend/store/store.go
+++ b/backend/store/store.go
@@ -57,11 +57,11 @@ func New(ctx context.Context, pgURL string, enableCache bool) (*Store, error) {
if err != nil {
return nil, err
}
- policyCache, err := lru.New[string, *PolicyMessage](128)
+ policyCache, err := lru.New[string, *PolicyMessage](4096)
if err != nil {
return nil, err
}
- settingCache, err := lru.New[string, *SettingMessage](64)
+ settingCache, err := lru.New[string, *SettingMessage](1024)
if err != nil {
return nil, err
}
@@ -138,7 +138,7 @@ func getInstanceCacheKey(instanceID string) string {
}
func getSettingCacheKey(workspace string, name storepb.SettingName) string {
- return fmt.Sprintf("workspaces/%s/settings/%s", workspace, name)
+ return fmt.Sprintf("workspaces/%s/settings/%s", workspace, name.String())
}
func getGroupCacheKey(workspace, email string) string {
@@ -154,7 +154,7 @@ func getMemberGroupsCacheKey(workspace, userName string) string {
}
func getPolicyCacheKey(workspace string, resourceType storepb.Policy_Resource, resource string, policyType storepb.Policy_Type) string {
- return fmt.Sprintf("workspaces/%s/policies/%s/%s/%s", workspace, resourceType, resource, policyType)
+ return fmt.Sprintf("workspaces/%s/policies/%s/%s/%s", workspace, resourceType.String(), resource, policyType.String())
}
func getDatabaseCacheKey(workspace, instanceID, databaseName string) string {
diff --git a/backend/store/workspace.go b/backend/store/workspace.go
index 5704fbd7de..5a431484d5 100644
--- a/backend/store/workspace.go
+++ b/backend/store/workspace.go
@@ -148,26 +148,59 @@ func (s *Store) CreateWorkspace(ctx context.Context, create *WorkspaceMessage, a
return create, nil
}
-func (s *Store) FindWorkspaceIDByMemberEmail(ctx context.Context, memberName string, includeAllUser bool) (string, error) {
- workspaces, err := s.FindWorkspacesByMemberEmail(ctx, memberName, includeAllUser)
+// UpdateWorkspaceMessage is the message for updating a workspace.
+type UpdateWorkspaceMessage struct {
+ ResourceID string
+ Title *string
+}
+
+// UpdateWorkspace updates a workspace.
+func (s *Store) UpdateWorkspace(ctx context.Context, patch *UpdateWorkspaceMessage) error {
+ set := qb.Q()
+ if v := patch.Title; v != nil {
+ set.Comma("name = ?", *v)
+ }
+ q := qb.Q().Space("UPDATE workspace SET ? WHERE resource_id = ? AND deleted = FALSE", set, patch.ResourceID)
+ query, args, err := q.ToSQL()
if err != nil {
- return "", errors.Wrap(err, "failed to find workspaces for user")
+ return errors.Wrapf(err, "failed to build sql")
+ }
+ if _, err := s.GetDB().ExecContext(ctx, query, args...); err != nil {
+ return errors.Wrapf(err, "failed to update workspace")
+ }
+ return nil
+}
+
+// FindWorkspaceMessage is the message for finding workspaces.
+type FindWorkspaceMessage struct {
+ // WorkspaceID filters by a specific workspace. Nil means no filter.
+ WorkspaceID *string
+ // Email is required. The user email (without "users/" prefix).
+ Email string
+ // IncludeAllUser includes workspaces where "allUsers" is a member.
+ IncludeAllUser bool
+}
+
+// FindWorkspace finds a single workspace matching the filter.
+// Returns (nil, nil) if no workspace matches.
+func (s *Store) FindWorkspace(ctx context.Context, find *FindWorkspaceMessage) (*WorkspaceMessage, error) {
+ workspaces, err := s.ListWorkspacesByEmail(ctx, find)
+ if err != nil {
+ return nil, err
}
if len(workspaces) == 0 {
- return "", errors.Errorf("%q is not a member of any workspace", memberName)
+ return nil, nil
}
- // Returns the first workspace. The caller (resolveWorkspaceForLogin) may
- // override this with the user's last login workspace from their profile.
- return workspaces[0].ResourceID, nil
+ return workspaces[0], nil
}
-// FindWorkspacesByMemberEmail finds all workspaces where the given email is a member
-// in the workspace IAM policy bindings. The memberName should be in the format
-// "users/{email}", "serviceAccounts/{email}", etc.
+// ListWorkspacesByEmail finds all workspaces where the given email is a member
+// in the workspace IAM policy bindings.
// Returns workspaces sorted by name.
-func (s *Store) FindWorkspacesByMemberEmail(ctx context.Context, memberName string, includeAllUser bool) ([]*WorkspaceMessage, error) {
+func (s *Store) ListWorkspacesByEmail(ctx context.Context, find *FindWorkspaceMessage) ([]*WorkspaceMessage, error) {
+ memberName := common.FormatUserEmail(find.Email)
memberFilter := qb.Q().Space("member = ?", memberName)
- if includeAllUser {
+ if find.IncludeAllUser {
memberFilter.Or("member = ?", common.AllUsers)
}
@@ -184,8 +217,11 @@ func (s *Store) FindWorkspacesByMemberEmail(ctx context.Context, memberName stri
jsonb_array_elements_text(binding->'members') AS member
WHERE ?
)
- ORDER BY w.name
`, memberFilter)
+ if v := find.WorkspaceID; v != nil {
+ q.And("w.resource_id = ?", *v)
+ }
+ q.Space("ORDER BY w.name")
query, args, err := q.ToSQL()
if err != nil {
diff --git a/frontend/src/components/GeneralSetting/AuditLogStdoutSetting.vue b/frontend/src/components/GeneralSetting/AuditLogStdoutSetting.vue
index af662fa775..c354dd63b7 100644
--- a/frontend/src/components/GeneralSetting/AuditLogStdoutSetting.vue
+++ b/frontend/src/components/GeneralSetting/AuditLogStdoutSetting.vue
@@ -5,7 +5,6 @@
<h1 class="text-2xl font-bold">
{{ $t("settings.general.workspace.log") }}
</h1>
- <FeatureBadge :feature="PlanFeature.FEATURE_AUDIT_LOG" />
</div>
</div>
@@ -17,9 +16,10 @@
:text="true"
:disabled="!allowEdit || !hasAuditLogFeature"
/>
- <span class="text-sm">
+ <div class="flex items-center gap-x-2 text-sm">
{{ $t("settings.general.workspace.audit-log-stdout.enable") }}
- </span>
+ <FeatureBadge :feature="PlanFeature.FEATURE_AUDIT_LOG" />
+ </div>
</div>
<div class="mt-1 text-sm text-gray-400">
{{ $t("settings.general.workspace.audit-log-stdout.description") }}
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 6a7a2d5866..2551a169c7 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -47,10 +47,13 @@ migrateStorageKeys();
const currentUser = await useAuthStore().fetchCurrentUser();
// Initialize stores.
- await Promise.all([
+ const initPromises: Promise<unknown>[] = [
useActuatorV1Store().fetchServerInfo(currentUser?.workspace),
- useSubscriptionV1Store().fetchSubscription(),
- ]);
+ ];
+ if (currentUser) {
+ initPromises.push(useSubscriptionV1Store().fetchSubscription());
+ }
+ await Promise.all(initPromises);
app.use(router).use(highlight).use(i18n).use(NaiveUI);
diff --git a/frontend/src/store/modules/v1/auth.ts b/frontend/src/store/modules/v1/auth.ts
index 66f03d9acb..d0a4d40df8 100644
--- a/frontend/src/store/modules/v1/auth.ts
+++ b/frontend/src/store/modules/v1/auth.ts
@@ -14,7 +14,12 @@ import {
} from "@/router/auth";
import { SETUP_MODULE } from "@/router/setup";
import { SQL_EDITOR_HOME_MODULE } from "@/router/sqlEditor";
-import { useActuatorV1Store, useAppFeature, useUserStore } from "@/store";
+import {
+ useActuatorV1Store,
+ useAppFeature,
+ useSubscriptionV1Store,
+ useUserStore,
+} from "@/store";
import { UNKNOWN_USER_NAME, unknownUser } from "@/types";
import {
type LoginRequest,
@@ -117,6 +122,7 @@ export const useAuthStore = defineStore("auth_v1", () => {
setRequireResetPassword(resp.requireResetPassword);
await actuatorStore.fetchServerInfo(user?.workspace);
+ await useSubscriptionV1Store().fetchSubscription();
// After user login, we need to reset the auth session key.
authSessionKey.value = uniqueId();
@@ -159,6 +165,7 @@ export const useAuthStore = defineStore("auth_v1", () => {
}
await actuatorStore.fetchServerInfo(user?.workspace);
+ await useSubscriptionV1Store().fetchSubscription();
authSessionKey.value = uniqueId();
if (actuatorStore.enableOnboarding) {
diff --git a/frontend/src/types/iam/permission-generated.ts b/frontend/src/types/iam/permission-generated.ts
index af527198ef..343304c7f0 100644
--- a/frontend/src/types/iam/permission-generated.ts
+++ b/frontend/src/types/iam/permission-generated.ts
@@ -140,4 +140,5 @@ export type Permission =
| "bb.workloadIdentities.undelete"
| "bb.workloadIdentities.update"
| "bb.workspaces.getIamPolicy"
+ | "bb.workspaces.update"
| "bb.workspaces.setIamPolicy";
diff --git a/frontend/src/types/proto-es/v1/auth_service_pb.d.ts b/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
index 34000e7aff..1bc2130598 100644
--- a/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
@@ -313,6 +313,53 @@ export declare type RefreshResponse = Message<"bytebase.v1.RefreshResponse"> & {
*/
export declare const RefreshResponseSchema: GenMessage<RefreshResponse>;
+/**
+ * @generated from message bytebase.v1.SwitchWorkspaceRequest
+ */
+export declare type SwitchWorkspaceRequest = Message<"bytebase.v1.SwitchWorkspaceRequest"> & {
+ /**
+ * The target workspace to switch to.
+ * Format: workspaces/{workspace}
+ *
+ * @generated from field: string workspace = 1;
+ */
+ workspace: string;
+
+ /**
+ * If true, sets tokens as HTTP-only cookies (browser clients).
+ *
+ * @generated from field: bool web = 2;
+ */
+ web: boolean;
+
+ /**
+ * OTP code for MFA verification. Required if the target workspace enforces MFA.
+ *
+ * @generated from field: optional string otp_code = 3;
+ */
+ otpCode?: string;
+
+ /**
+ * Recovery code for MFA verification (alternative to otp_code).
+ *
+ * @generated from field: optional string recovery_code = 4;
+ */
+ recoveryCode?: string;
+
+ /**
+ * Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token.
+ *
+ * @generated from field: optional string mfa_temp_token = 5;
+ */
+ mfaTempToken?: string;
+};
+
+/**
+ * Describes the message bytebase.v1.SwitchWorkspaceRequest.
+ * Use `create(SwitchWorkspaceRequestSchema)` to create a new message.
+ */
+export declare const SwitchWorkspaceRequestSchema: GenMessage<SwitchWorkspaceRequest>;
+
/**
* AuthService handles user authentication operations.
*
@@ -377,5 +424,16 @@ export declare const AuthService: GenService<{
input: typeof RefreshRequestSchema;
output: typeof RefreshResponseSchema;
},
+ /**
+ * Switches the current user's active workspace and issues new tokens.
+ * The user must be a member of the target workspace.
+ *
+ * @generated from rpc bytebase.v1.AuthService.SwitchWorkspace
+ */
+ switchWorkspace: {
+ methodKind: "unary";
+ input: typeof SwitchWorkspaceRequestSchema;
+ output: typeof LoginResponseSchema;
+ },
}>;
diff --git a/frontend/src/types/proto-es/v1/auth_service_pb.js b/frontend/src/types/proto-es/v1/auth_service_pb.js
index 1827b93b77..3a28073305 100644
--- a/frontend/src/types/proto-es/v1/auth_service_pb.js
+++ b/frontend/src/types/proto-es/v1/auth_service_pb.js
@@ -12,7 +12,7 @@ import { file_v1_user_service } from "./user_service_pb";
* Describes the file v1/auth_service.proto.
*/
export const file_v1_auth_service = /*@__PURE__*/
- fileDesc("ChV2MS9hdXRoX3NlcnZpY2UucHJvdG8SC2J5dGViYXNlLnYxIosCCgxMb2dpblJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSCwoDd2ViGAMgASgIEhAKCGlkcF9uYW1lGAQgASgJEjkKC2lkcF9jb250ZXh0GAUgASgLMiQuYnl0ZWJhc2UudjEuSWRlbnRpdHlQcm92aWRlckNvbnRleHQSFQoIb3RwX2NvZGUYBiABKAlIAIgBARIaCg1yZWNvdmVyeV9jb2RlGAcgASgJSAGIAQESGwoObWZhX3RlbXBfdG9rZW4YCCABKAlIAogBAUILCglfb3RwX2NvZGVCEAoOX3JlY292ZXJ5X2NvZGVCEQoPX21mYV90ZW1wX3Rva2VuIqwBChdJZGVudGl0eVByb3ZpZGVyQ29udGV4dBJECg5vYXV0aDJfY29udGV4dBgBIAEoCzIqLmJ5dGViYXNlLnYxLk9BdXRoMklkZW50aXR5UHJvdmlkZXJDb250ZXh0SAASQAoMb2lkY19jb250ZXh0GAIgASgLMiguYnl0ZWJhc2UudjEuT0lEQ0lkZW50aXR5UHJvdmlkZXJDb250ZXh0SABCCQoHY29udGV4dCItCh1PQXV0aDJJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIisKG09JRENJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIo8BCg1Mb2dpblJlc3BvbnNlEg0KBXRva2VuGAEgASgJEhsKDm1mYV90ZW1wX3Rva2VuGAIgASgJSACIAQESHgoWcmVxdWlyZV9yZXNldF9wYXNzd29yZBgDIAEoCBIfCgR1c2VyGAQgASgLMhEuYnl0ZWJhc2UudjEuVXNlckIRCg9fbWZhX3RlbXBfdG9rZW4iDwoNTG9nb3V0UmVxdWVzdCI0ChRFeGNoYW5nZVRva2VuUmVxdWVzdBINCgV0b2tlbhgBIAEoCRINCgVlbWFpbBgCIAEoCSItChVFeGNoYW5nZVRva2VuUmVzcG9uc2USFAoMYWNjZXNzX3Rva2VuGAEgASgJIj8KDVNpZ251cFJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSDQoFdGl0bGUYAyABKAkiEAoOUmVmcmVzaFJlcXVlc3QiEQoPUmVmcmVzaFJlc3BvbnNlMqMECgtBdXRoU2VydmljZRJhCgVMb2dpbhIZLmJ5dGViYXNlLnYxLkxvZ2luUmVxdWVzdBoaLmJ5dGViYXNlLnYxLkxvZ2luUmVzcG9uc2UiIYDqMAGY6jABgtPkkwITOgEqIg4vdjEvYXV0aC9sb2dpbhJgCgZMb2dvdXQSGi5ieXRlYmFzZS52MS5Mb2dvdXRSZXF1ZXN0GhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5IiKA6jABmOowAYLT5JMCFDoBKiIPL3YxL2F1dGgvbG9nb3V0EoEBCg1FeGNoYW5nZVRva2VuEiEuYnl0ZWJhc2UudjEuRXhjaGFuZ2VUb2tlblJlcXVlc3QaIi5ieXRlYmFzZS52MS5FeGNoYW5nZVRva2VuUmVzcG9uc2UiKYDqMAGY6jABgtPkkwIbOgEqIhYvdjEvYXV0aDpleGNoYW5nZVRva2VuEmQKBlNpZ251cBIaLmJ5dGViYXNlLnYxLlNpZ251cFJlcXVlc3QaGi5ieXRlYmFzZS52MS5Mb2dpblJlc3BvbnNlIiKA6jABmOowAYLT5JMCFDoBKiIPL3YxL2F1dGgvc2lnbnVwEmUKB1JlZnJlc2gSGy5ieXRlYmFzZS52MS5SZWZyZXNoUmVxdWVzdBocLmJ5dGViYXNlLnYxLlJlZnJlc2hSZXNwb25zZSIfgOowAYLT5JMCFToBKiIQL3YxL2F1dGgvcmVmcmVzaEKmAQoPY29tLmJ5dGViYXNlLnYxQhBBdXRoU2VydmljZVByb3RvUAFaNGdpdGh1Yi5jb20vYnl0ZWJhc2UvYnl0ZWJhc2UvYmFja2VuZC9nZW5lcmF0ZWQtZ28vdjGiAgNCWFiqAgtCeXRlYmFzZS5WMcoCC0J5dGViYXNlXFYx4gIXQnl0ZWJhc2VcVjFcR1BCTWV0YWRhdGHqAgxCeXRlYmFzZTo6VjFiBnByb3RvMw", [file_google_api_annotations, file_google_protobuf_empty, file_v1_annotation, file_v1_user_service]);
+ fileDesc("ChV2MS9hdXRoX3NlcnZpY2UucHJvdG8SC2J5dGViYXNlLnYxIosCCgxMb2dpblJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSCwoDd2ViGAMgASgIEhAKCGlkcF9uYW1lGAQgASgJEjkKC2lkcF9jb250ZXh0GAUgASgLMiQuYnl0ZWJhc2UudjEuSWRlbnRpdHlQcm92aWRlckNvbnRleHQSFQoIb3RwX2NvZGUYBiABKAlIAIgBARIaCg1yZWNvdmVyeV9jb2RlGAcgASgJSAGIAQESGwoObWZhX3RlbXBfdG9rZW4YCCABKAlIAogBAUILCglfb3RwX2NvZGVCEAoOX3JlY292ZXJ5X2NvZGVCEQoPX21mYV90ZW1wX3Rva2VuIqwBChdJZGVudGl0eVByb3ZpZGVyQ29udGV4dBJECg5vYXV0aDJfY29udGV4dBgBIAEoCzIqLmJ5dGViYXNlLnYxLk9BdXRoMklkZW50aXR5UHJvdmlkZXJDb250ZXh0SAASQAoMb2lkY19jb250ZXh0GAIgASgLMiguYnl0ZWJhc2UudjEuT0lEQ0lkZW50aXR5UHJvdmlkZXJDb250ZXh0SABCCQoHY29udGV4dCItCh1PQXV0aDJJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIisKG09JRENJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIo8BCg1Mb2dpblJlc3BvbnNlEg0KBXRva2VuGAEgASgJEhsKDm1mYV90ZW1wX3Rva2VuGAIgASgJSACIAQESHgoWcmVxdWlyZV9yZXNldF9wYXNzd29yZBgDIAEoCBIfCgR1c2VyGAQgASgLMhEuYnl0ZWJhc2UudjEuVXNlckIRCg9fbWZhX3RlbXBfdG9rZW4iDwoNTG9nb3V0UmVxdWVzdCI0ChRFeGNoYW5nZVRva2VuUmVxdWVzdBINCgV0b2tlbhgBIAEoCRINCgVlbWFpbBgCIAEoCSItChVFeGNoYW5nZVRva2VuUmVzcG9uc2USFAoMYWNjZXNzX3Rva2VuGAEgASgJIj8KDVNpZ251cFJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSDQoFdGl0bGUYAyABKAkiEAoOUmVmcmVzaFJlcXVlc3QiEQoPUmVmcmVzaFJlc3BvbnNlIroBChZTd2l0Y2hXb3Jrc3BhY2VSZXF1ZXN0EhEKCXdvcmtzcGFjZRgBIAEoCRILCgN3ZWIYAiABKAgSFQoIb3RwX2NvZGUYAyABKAlIAIgBARIaCg1yZWNvdmVyeV9jb2RlGAQgASgJSAGIAQESGwoObWZhX3RlbXBfdG9rZW4YBSABKAlIAogBAUILCglfb3RwX2NvZGVCEAoOX3JlY292ZXJ5X2NvZGVCEQoPX21mYV90ZW1wX3Rva2VuMqAFCgtBdXRoU2VydmljZRJhCgVMb2dpbhIZLmJ5dGViYXNlLnYxLkxvZ2luUmVxdWVzdBoaLmJ5dGViYXNlLnYxLkxvZ2luUmVzcG9uc2UiIYDqMAGY6jABgtPkkwITOgEqIg4vdjEvYXV0aC9sb2dpbhJgCgZMb2dvdXQSGi5ieXRlYmFzZS52MS5Mb2dvdXRSZXF1ZXN0GhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5IiKA6jABmOowAYLT5JMCFDoBKiIPL3YxL2F1dGgvbG9nb3V0EoEBCg1FeGNoYW5nZVRva2VuEiEuYnl0ZWJhc2UudjEuRXhjaGFuZ2VUb2tlblJlcXVlc3QaIi5ieXRlYmFzZS52MS5FeGNoYW5nZVRva2VuUmVzcG9uc2UiKYDqMAGY6jABgtPkkwIbOgEqIhYvdjEvYXV0aDpleGNoYW5nZVRva2VuEmQKBlNpZ251cBIaLmJ5dGViYXNlLnYxLlNpZ251cFJlcXVlc3QaGi5ieXRlYmFzZS52MS5Mb2dpblJlc3BvbnNlIiKA6jABmOowAYLT5JMCFDoBKiIPL3YxL2F1dGgvc2lnbnVwEmUKB1JlZnJlc2gSGy5ieXRlYmFzZS52MS5SZWZyZXNoUmVxdWVzdBocLmJ5dGViYXNlLnYxLlJlZnJlc2hSZXNwb25zZSIfgOowAYLT5JMCFToBKiIQL3YxL2F1dGgvcmVmcmVzaBJ7Cg9Td2l0Y2hXb3Jrc3BhY2USIy5ieXRlYmFzZS52MS5Td2l0Y2hXb3Jrc3BhY2VSZXF1ZXN0GhouYnl0ZWJhc2UudjEuTG9naW5SZXNwb25zZSInkOowAoLT5JMCHToBKiIYL3YxL2F1dGg6c3dpdGNoV29ya3NwYWNlQqYBCg9jb20uYnl0ZWJhc2UudjFCEEF1dGhTZXJ2aWNlUHJvdG9QAVo0Z2l0aHViLmNvbS9ieXRlYmFzZS9ieXRlYmFzZS9iYWNrZW5kL2dlbmVyYXRlZC1nby92MaICA0JYWKoCC0J5dGViYXNlLlYxygILQnl0ZWJhc2VcVjHiAhdCeXRlYmFzZVxWMVxHUEJNZXRhZGF0YeoCDEJ5dGViYXNlOjpWMWIGcHJvdG8z", [file_google_api_annotations, file_google_protobuf_empty, file_v1_annotation, file_v1_user_service]);
/**
* Describes the message bytebase.v1.LoginRequest.
@@ -91,6 +91,13 @@ export const RefreshRequestSchema = /*@__PURE__*/
export const RefreshResponseSchema = /*@__PURE__*/
messageDesc(file_v1_auth_service, 10);
+/**
+ * Describes the message bytebase.v1.SwitchWorkspaceRequest.
+ * Use `create(SwitchWorkspaceRequestSchema)` to create a new message.
+ */
+export const SwitchWorkspaceRequestSchema = /*@__PURE__*/
+ messageDesc(file_v1_auth_service, 11);
+
/**
* AuthService handles user authentication operations.
*
diff --git a/frontend/src/types/proto-es/v1/workspace_service_pb.d.ts b/frontend/src/types/proto-es/v1/workspace_service_pb.d.ts
index b65a130e55..8b212c9f97 100644
--- a/frontend/src/types/proto-es/v1/workspace_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/workspace_service_pb.d.ts
@@ -2,7 +2,9 @@
// @generated from file v1/workspace_service.proto (package bytebase.v1, syntax proto3)
/* eslint-disable */
-import type { GenFile, GenService } from "@bufbuild/protobuf/codegenv2";
+import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
+import type { Message } from "@bufbuild/protobuf";
+import type { FieldMask } from "@bufbuild/protobuf/wkt";
import type { GetIamPolicyRequestSchema, IamPolicySchema, SetIamPolicyRequestSchema } from "./iam_policy_pb";
/**
@@ -10,12 +12,104 @@ import type { GetIamPolicyRequestSchema, IamPolicySchema, SetIamPolicyRequestSch
*/
export declare const file_v1_workspace_service: GenFile;
+/**
+ * @generated from message bytebase.v1.ListWorkspacesRequest
+ */
+export declare type ListWorkspacesRequest = Message<"bytebase.v1.ListWorkspacesRequest"> & {
+};
+
+/**
+ * Describes the message bytebase.v1.ListWorkspacesRequest.
+ * Use `create(ListWorkspacesRequestSchema)` to create a new message.
+ */
+export declare const ListWorkspacesRequestSchema: GenMessage<ListWorkspacesRequest>;
+
+/**
+ * @generated from message bytebase.v1.ListWorkspacesResponse
+ */
+export declare type ListWorkspacesResponse = Message<"bytebase.v1.ListWorkspacesResponse"> & {
+ /**
+ * @generated from field: repeated bytebase.v1.Workspace workspaces = 1;
+ */
+ workspaces: Workspace[];
+};
+
+/**
+ * Describes the message bytebase.v1.ListWorkspacesResponse.
+ * Use `create(ListWorkspacesResponseSchema)` to create a new message.
+ */
+export declare const ListWorkspacesResponseSchema: GenMessage<ListWorkspacesResponse>;
+
+/**
+ * @generated from message bytebase.v1.Workspace
+ */
+export declare type Workspace = Message<"bytebase.v1.Workspace"> & {
+ /**
+ * Format: workspaces/{workspace}
+ *
+ * @generated from field: string name = 1;
+ */
+ name: string;
+
+ /**
+ * @generated from field: string title = 2;
+ */
+ title: string;
+};
+
+/**
+ * Describes the message bytebase.v1.Workspace.
+ * Use `create(WorkspaceSchema)` to create a new message.
+ */
+export declare const WorkspaceSchema: GenMessage<Workspace>;
+
+/**
+ * @generated from message bytebase.v1.UpdateWorkspaceRequest
+ */
+export declare type UpdateWorkspaceRequest = Message<"bytebase.v1.UpdateWorkspaceRequest"> & {
+ /**
+ * @generated from field: bytebase.v1.Workspace workspace = 1;
+ */
+ workspace?: Workspace;
+
+ /**
+ * @generated from field: google.protobuf.FieldMask update_mask = 2;
+ */
+ updateMask?: FieldMask;
+};
+
+/**
+ * Describes the message bytebase.v1.UpdateWorkspaceRequest.
+ * Use `create(UpdateWorkspaceRequestSchema)` to create a new message.
+ */
+export declare const UpdateWorkspaceRequestSchema: GenMessage<UpdateWorkspaceRequest>;
+
/**
* WorkspaceService manages workspace-level operations and profile.
*
* @generated from service bytebase.v1.WorkspaceService
*/
export declare const WorkspaceService: GenService<{
+ /**
+ * Lists all workspaces the current user is a member of.
+ *
+ * @generated from rpc bytebase.v1.WorkspaceService.ListWorkspaces
+ */
+ listWorkspaces: {
+ methodKind: "unary";
+ input: typeof ListWorkspacesRequestSchema;
+ output: typeof ListWorkspacesResponseSchema;
+ },
+ /**
+ * Updates a workspace. Currently only title can be updated.
+ *
+ * @generated from rpc bytebase.v1.WorkspaceService.UpdateWorkspace
+ */
+ updateWorkspace: {
+ methodKind: "unary";
+ input: typeof UpdateWorkspaceRequestSchema;
+ output: typeof WorkspaceSchema;
+ },
/**
* Retrieves IAM policy for the workspace.
* Permissions required: bb.workspaces.getIamPolicy
diff --git a/frontend/src/types/proto-es/v1/workspace_service_pb.js b/frontend/src/types/proto-es/v1/workspace_service_pb.js
index 7ed055a9ac..24a12e71ed 100644
--- a/frontend/src/types/proto-es/v1/workspace_service_pb.js
+++ b/frontend/src/types/proto-es/v1/workspace_service_pb.js
@@ -2,8 +2,10 @@
// @generated from file v1/workspace_service.proto (package bytebase.v1, syntax proto3)
/* eslint-disable */
-import { fileDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
+import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
import { file_google_api_annotations } from "../google/api/annotations_pb";
+import { file_google_api_field_behavior } from "../google/api/field_behavior_pb";
+import { file_google_protobuf_field_mask } from "@bufbuild/protobuf/wkt";
import { file_v1_annotation } from "./annotation_pb";
import { file_v1_iam_policy } from "./iam_policy_pb";
@@ -11,7 +13,35 @@ import { file_v1_iam_policy } from "./iam_policy_pb";
* Describes the file v1/workspace_service.proto.
*/
export const file_v1_workspace_service = /*@__PURE__*/
- fileDesc("Chp2MS93b3Jrc3BhY2Vfc2VydmljZS5wcm90bxILYnl0ZWJhc2UudjEy1wIKEFdvcmtzcGFjZVNlcnZpY2USnAEKDEdldElhbVBvbGljeRIgLmJ5dGViYXNlLnYxLkdldElhbVBvbGljeVJlcXVlc3QaFi5ieXRlYmFzZS52MS5JYW1Qb2xpY3kiUorqMBpiYi53b3Jrc3BhY2VzLmdldElhbVBvbGljeZDqMAGC0+STAioSKC92MS97cmVzb3VyY2U9d29ya3NwYWNlcy8qfTpnZXRJYW1Qb2xpY3kSowEKDFNldElhbVBvbGljeRIgLmJ5dGViYXNlLnYxLlNldElhbVBvbGljeVJlcXVlc3QaFi5ieXRlYmFzZS52MS5JYW1Qb2xpY3kiWYrqMBpiYi53b3Jrc3BhY2VzLnNldElhbVBvbGljeZDqMAGY6jABgtPkkwItOgEqIigvdjEve3Jlc291cmNlPXdvcmtzcGFjZXMvKn06c2V0SWFtUG9saWN5QqsBCg9jb20uYnl0ZWJhc2UudjFCFVdvcmtzcGFjZVNlcnZpY2VQcm90b1ABWjRnaXRodWIuY29tL2J5dGViYXNlL2J5dGViYXNlL2JhY2tlbmQvZ2VuZXJhdGVkLWdvL3YxogIDQlhYqgILQnl0ZWJhc2UuVjHKAgtCeXRlYmFzZVxWMeICF0J5dGViYXNlXFYxXEdQQk1ldGFkYXRh6gIMQnl0ZWJhc2U6OlYxYgZwcm90bzM", [file_google_api_annotations, file_v1_annotation, file_v1_iam_policy]);
+ fileDesc("Chp2MS93b3Jrc3BhY2Vfc2VydmljZS5wcm90bxILYnl0ZWJhc2UudjEiFwoVTGlzdFdvcmtzcGFjZXNSZXF1ZXN0IkQKFkxpc3RXb3Jrc3BhY2VzUmVzcG9uc2USKgoKd29ya3NwYWNlcxgBIAMoCzIWLmJ5dGViYXNlLnYxLldvcmtzcGFjZSIoCglXb3Jrc3BhY2USDAoEbmFtZRgBIAEoCRINCgV0aXRsZRgCIAEoCSJ5ChZVcGRhdGVXb3Jrc3BhY2VSZXF1ZXN0Ei4KCXdvcmtzcGFjZRgBIAEoCzIWLmJ5dGViYXNlLnYxLldvcmtzcGFjZUID4EECEi8KC3VwZGF0ZV9tYXNrGAIgASgLMhouZ29vZ2xlLnByb3RvYnVmLkZpZWxkTWFzazLtBAoQV29ya3NwYWNlU2VydmljZRJ1Cg5MaXN0V29ya3NwYWNlcxIiLmJ5dGViYXNlLnYxLkxpc3RXb3Jrc3BhY2VzUmVxdWVzdBojLmJ5dGViYXNlLnYxLkxpc3RXb3Jrc3BhY2VzUmVzcG9uc2UiGpDqMAKC0+STAhASDi92MS93b3Jrc3BhY2VzEpwBCg9VcGRhdGVXb3Jrc3BhY2USIy5ieXRlYmFzZS52MS5VcGRhdGVXb3Jrc3BhY2VSZXF1ZXN0GhYuYnl0ZWJhc2UudjEuV29ya3NwYWNlIkyK6jAUYmIud29ya3NwYWNlcy51cGRhdGWQ6jABmOowAYLT5JMCJjoBKjIhL3YxL3t3b3Jrc3BhY2UubmFtZT13b3Jrc3BhY2VzLyp9EpwBCgxHZXRJYW1Qb2xpY3kSIC5ieXRlYmFzZS52MS5HZXRJYW1Qb2xpY3lSZXF1ZXN0GhYuYnl0ZWJhc2UudjEuSWFtUG9saWN5IlKK6jAaYmIud29ya3NwYWNlcy5nZXRJYW1Qb2xpY3mQ6jABgtPkkwIqEigvdjEve3Jlc291cmNlPXdvcmtzcGFjZXMvKn06Z2V0SWFtUG9saWN5EqMBCgxTZXRJYW1Qb2xpY3kSIC5ieXRlYmFzZS52MS5TZXRJYW1Qb2xpY3lSZXF1ZXN0GhYuYnl0ZWJhc2UudjEuSWFtUG9saWN5IlmK6jAaYmIud29ya3NwYWNlcy5zZXRJYW1Qb2xpY3mQ6jABmOowAYLT5JMCLToBKiIoL3YxL3tyZXNvdXJjZT13b3Jrc3BhY2VzLyp9OnNldElhbVBvbGljeUKrAQoPY29tLmJ5dGViYXNlLnYxQhVXb3Jrc3BhY2VTZXJ2aWNlUHJvdG9QAVo0Z2l0aHViLmNvbS9ieXRlYmFzZS9ieXRlYmFzZS9iYWNrZW5kL2dlbmVyYXRlZC1nby92MaICA0JYWKoCC0J5dGViYXNlLlYxygILQnl0ZWJhc2VcVjHiAhdCeXRlYmFzZVxWMVxHUEJNZXRhZGF0YeoCDEJ5dGViYXNlOjpWMWIGcHJvdG8z", [file_google_api_annotations, file_google_api_field_behavior, file_google_protobuf_field_mask, file_v1_annotation, file_v1_iam_policy]);
+
+/**
+ * Describes the message bytebase.v1.ListWorkspacesRequest.
+ * Use `create(ListWorkspacesRequestSchema)` to create a new message.
+ */
+export const ListWorkspacesRequestSchema = /*@__PURE__*/
+ messageDesc(file_v1_workspace_service, 0);
+
+/**
+ * Describes the message bytebase.v1.ListWorkspacesResponse.
+ * Use `create(ListWorkspacesResponseSchema)` to create a new message.
+ */
+export const ListWorkspacesResponseSchema = /*@__PURE__*/
+ messageDesc(file_v1_workspace_service, 1);
+
+/**
+ * Describes the message bytebase.v1.Workspace.
+ * Use `create(WorkspaceSchema)` to create a new message.
+ */
+export const WorkspaceSchema = /*@__PURE__*/
+ messageDesc(file_v1_workspace_service, 2);
+
+/**
+ * Describes the message bytebase.v1.UpdateWorkspaceRequest.
+ * Use `create(UpdateWorkspaceRequestSchema)` to create a new message.
+ */
+export const UpdateWorkspaceRequestSchema = /*@__PURE__*/
+ messageDesc(file_v1_workspace_service, 3);
/**
* WorkspaceService manages workspace-level operations and profile.
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 192fd61ebc..1bec8d659d 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -252,6 +252,7 @@ import {
featureToRef,
hasFeature,
pushNotification,
+ useActuatorV1Store,
useAuthStore,
useCurrentUserV1,
useSettingV1Store,
@@ -298,6 +299,7 @@ const settingV1Store = useSettingV1Store();
const currentUser = useCurrentUserV1();
const userStore = useUserStore();
const workspaceStore = useWorkspaceV1Store();
+const actuatorStore = useActuatorV1Store();
const state = reactive<LocalState>({
editing: false,
@@ -398,7 +400,12 @@ const allowEdit = computed(() => {
if (user.value.state !== State.ACTIVE) {
return false;
}
- return isSelf.value || hasWorkspacePermissionV2("bb.users.update");
+ if (isSelf.value) {
+ return true;
+ }
+ return (
+ !actuatorStore.isSaaSMode && hasWorkspacePermissionV2("bb.users.update")
+ );
});
// Only users with bb.users.updateEmail permission can change email.
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index b4feb288b0..f185874a3c 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -256,6 +256,28 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/bytebase.v1.ExchangeTokenResponse'
+ /v1/auth:switchWorkspace:
+ post:
+ tags:
+ - AuthService
+ summary: SwitchWorkspace
+ description: |-
+ Switches the current user's active workspace and issues new tokens.
+ The user must be a member of the target workspace.
+ operationId: AuthService_SwitchWorkspace
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.SwitchWorkspaceRequest'
+ required: true
+ responses:
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.LoginResponse'
/v1/cel/batchDeparse:
post:
tags:
@@ -15049,6 +15071,58 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/bytebase.v1.BatchUpdateWorksheetOrganizerResponse'
+ /v1/workspaces:
+ get:
+ tags:
+ - WorkspaceService
+ summary: ListWorkspaces
+ description: Lists all workspaces the current user is a member of.
+ operationId: WorkspaceService_ListWorkspaces
+ responses:
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.ListWorkspacesResponse'
+ /v1/workspaces/{workspace}:
+ patch:
+ tags:
+ - WorkspaceService
+ summary: UpdateWorkspace
+ description: Updates a workspace. Currently only title can be updated.
+ operationId: WorkspaceService_UpdateWorkspace
+ parameters:
+ - name: workspace
+ in: path
+ description: The workspace id.
+ required: true
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ workspace:
+ title: workspace
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
+ updateMask:
+ title: update_mask
+ $ref: '#/components/schemas/google.protobuf.FieldMask'
+ title: UpdateWorkspaceRequest
+ required:
+ - workspace
+ additionalProperties: false
+ required: true
+ responses:
+ "200":
+ description: Success
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
/v1/workspaces/{workspace}/actuator/info:
get:
tags:
@@ -22796,6 +22870,20 @@ components:
title: ListWorkloadIdentitiesResponse
additionalProperties: false
description: Response message for listing workload identities.
+ bytebase.v1.ListWorkspacesRequest:
+ type: object
+ title: ListWorkspacesRequest
+ additionalProperties: false
+ bytebase.v1.ListWorkspacesResponse:
+ type: object
+ properties:
+ workspaces:
+ type: array
+ items:
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
+ title: workspaces
+ title: ListWorkspacesResponse
+ additionalProperties: false
bytebase.v1.LoginRequest:
type: object
properties:
@@ -26467,6 +26555,39 @@ components:
readOnly: true
title: Subscription
additionalProperties: false
+ bytebase.v1.SwitchWorkspaceRequest:
+ type: object
+ properties:
+ workspace:
+ type: string
+ title: workspace
+ description: |-
+ The target workspace to switch to.
+ Format: workspaces/{workspace}
+ web:
+ type: boolean
+ title: web
+ description: If true, sets tokens as HTTP-only cookies (browser clients).
+ otpCode:
+ type:
+ - string
+ - "null"
+ title: otp_code
+ description: OTP code for MFA verification. Required if the target workspace enforces MFA.
+ recoveryCode:
+ type:
+ - string
+ - "null"
+ title: recovery_code
+ description: Recovery code for MFA verification (alternative to otp_code).
+ mfaTempToken:
+ type:
+ - string
+ - "null"
+ title: mfa_temp_token
+ description: Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token.
+ title: SwitchWorkspaceRequest
+ additionalProperties: false
bytebase.v1.SyncDatabaseRequest:
type: object
properties:
@@ -28388,6 +28509,19 @@ components:
required:
- worksheet
additionalProperties: false
+ bytebase.v1.UpdateWorkspaceRequest:
+ type: object
+ properties:
+ workspace:
+ title: workspace
+ $ref: '#/components/schemas/bytebase.v1.Workspace'
+ updateMask:
+ title: update_mask
+ $ref: '#/components/schemas/google.protobuf.FieldMask'
+ title: UpdateWorkspaceRequest
+ required:
+ - workspace
+ additionalProperties: false
bytebase.v1.User:
type: object
properties:
@@ -28781,6 +28915,18 @@ components:
required:
- worksheet
additionalProperties: false
+ bytebase.v1.Workspace:
+ type: object
+ properties:
+ name:
+ type: string
+ title: name
+ description: 'Format: workspaces/{workspace}'
+ title:
+ type: string
+ title: title
+ title: Workspace
+ additionalProperties: false
bytebase.v1.WorkspaceApprovalSetting:
type: object
properties:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index a1b576d81e..8dac9b391d 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -196,6 +196,7 @@
- [RefreshRequest](#bytebase-v1-RefreshRequest)
- [RefreshResponse](#bytebase-v1-RefreshResponse)
- [SignupRequest](#bytebase-v1-SignupRequest)
+ - [SwitchWorkspaceRequest](#bytebase-v1-SwitchWorkspaceRequest)
- [AuthService](#bytebase-v1-AuthService)
@@ -712,6 +713,11 @@
- [WorksheetService](#bytebase-v1-WorksheetService)
- [v1/workspace_service.proto](#v1_workspace_service-proto)
+ - [ListWorkspacesRequest](#bytebase-v1-ListWorkspacesRequest)
+ - [ListWorkspacesResponse](#bytebase-v1-ListWorkspacesResponse)
+ - [UpdateWorkspaceRequest](#bytebase-v1-UpdateWorkspaceRequest)
+ - [Workspace](#bytebase-v1-Workspace)
+
- [WorkspaceService](#bytebase-v1-WorkspaceService)
- [Scalar Value Types](#scalar-value-types)
@@ -3535,6 +3541,25 @@ Response from refreshing the access token.
+
+<a name="bytebase-v1-SwitchWorkspaceRequest"></a>
+
+### SwitchWorkspaceRequest
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| workspace | [string](#string) | | The target workspace to switch to. Format: workspaces/{workspace} |
+| web | [bool](#bool) | | If true, sets tokens as HTTP-only cookies (browser clients). |
+| otp_code | [string](#string) | optional | OTP code for MFA verification. Required if the target workspace enforces MFA. |
+| recovery_code | [string](#string) | optional | Recovery code for MFA verification (alternative to otp_code). |
+| mfa_temp_token | [string](#string) | optional | Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token. |
+
+
+
+
+
@@ -3554,6 +3579,7 @@ AuthService handles user authentication operations.
| ExchangeToken | [ExchangeTokenRequest](#bytebase-v1-ExchangeTokenRequest) | [ExchangeTokenResponse](#bytebase-v1-ExchangeTokenResponse) | Exchanges an external OIDC token for a Bytebase access token. Used by CI/CD pipelines with Workload Identity Federation. Permissions required: None (validates via OIDC token) |
| Signup | [SignupRequest](#bytebase-v1-SignupRequest) | [LoginResponse](#bytebase-v1-LoginResponse) | Registers a new user account. Creates a principal and assigns a workspace: - If the user&#39;s email was pre-invited to a workspace, joins that workspace. - Otherwise, creates a new workspace with the user as admin. Returns access tokens so the user is logged in immediately after signup. |
| Refresh | [RefreshRequest](#bytebase-v1-RefreshRequest) | [RefreshResponse](#bytebase-v1-RefreshResponse) | Refreshes the access token using the refresh token cookie. Permissions required: None (validates via refresh token cookie) |
+| SwitchWorkspace | [SwitchWorkspaceRequest](#bytebase-v1-SwitchWorkspaceRequest) | [LoginResponse](#bytebase-v1-LoginResponse) | Switches the current user&#39;s active workspace and issues new tokens. The user must be a member of the target workspace. |
@@ -11441,6 +11467,63 @@ WorksheetService manages SQL worksheets for query development.
## v1/workspace_service.proto
+
+<a name="bytebase-v1-ListWorkspacesRequest"></a>
+
+### ListWorkspacesRequest
+
+
+
+
+
+
+
+<a name="bytebase-v1-ListWorkspacesResponse"></a>
+
+### ListWorkspacesResponse
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| workspaces | [Workspace](#bytebase-v1-Workspace) | repeated | |
+
+
+
+
+
+
+<a name="bytebase-v1-UpdateWorkspaceRequest"></a>
+
+### UpdateWorkspaceRequest
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| workspace | [Workspace](#bytebase-v1-Workspace) | | |
+| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | |
+
+
+
+
+
+
+<a name="bytebase-v1-Workspace"></a>
+
+### Workspace
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| name | [string](#string) | | Format: workspaces/{workspace} |
+| title | [string](#string) | | |
+
+
+
+
+
@@ -11455,6 +11538,8 @@ WorkspaceService manages workspace-level operations and profile.
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
+| ListWorkspaces | [ListWorkspacesRequest](#bytebase-v1-ListWorkspacesRequest) | [ListWorkspacesResponse](#bytebase-v1-ListWorkspacesResponse) | Lists all workspaces the current user is a member of. |
+| UpdateWorkspace | [UpdateWorkspaceRequest](#bytebase-v1-UpdateWorkspaceRequest) | [Workspace](#bytebase-v1-Workspace) | Updates a workspace. Currently only title can be updated. |
| GetIamPolicy | [GetIamPolicyRequest](#bytebase-v1-GetIamPolicyRequest) | [IamPolicy](#bytebase-v1-IamPolicy) | Retrieves IAM policy for the workspace. Permissions required: bb.workspaces.getIamPolicy |
| SetIamPolicy | [SetIamPolicyRequest](#bytebase-v1-SetIamPolicyRequest) | [IamPolicy](#bytebase-v1-IamPolicy) | Sets IAM policy for the workspace. Permissions required: bb.workspaces.setIamPolicy |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 7208f696a9..bf3d6da9f3 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -916,6 +916,10 @@
<a href="#bytebase.v1.SignupRequest"><span class="badge">M</span>SignupRequest</a>
</li>
+ <li>
+ <a href="#bytebase.v1.SwitchWorkspaceRequest"><span class="badge">M</span>SwitchWorkspaceRequest</a>
+ </li>
+
@@ -2885,6 +2889,22 @@
<a href="#v1%2fworkspace_service.proto">v1/workspace_service.proto</a>
<ul>
+ <li>
+ <a href="#bytebase.v1.ListWorkspacesRequest"><span class="badge">M</span>ListWorkspacesRequest</a>
+ </li>
+
+ <li>
+ <a href="#bytebase.v1.ListWorkspacesResponse"><span class="badge">M</span>ListWorkspacesResponse</a>
+ </li>
+
+ <li>
+ <a href="#bytebase.v1.UpdateWorkspaceRequest"><span class="badge">M</span>UpdateWorkspaceRequest</a>
+ </li>
+
+ <li>
+ <a href="#bytebase.v1.Workspace"><span class="badge">M</span>Workspace</a>
+ </li>
+
@@ -10340,6 +10360,59 @@ Only returned when web=false. For web=true, the token is set as an HTTP-only coo
+ <h3 id="bytebase.v1.SwitchWorkspaceRequest">SwitchWorkspaceRequest</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>workspace</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>The target workspace to switch to.
+Format: workspaces/{workspace} </p></td>
+ </tr>
+
+ <tr>
+ <td>web</td>
+ <td><a href="#bool">bool</a></td>
+ <td></td>
+ <td><p>If true, sets tokens as HTTP-only cookies (browser clients). </p></td>
+ </tr>
+
+ <tr>
+ <td>otp_code</td>
+ <td><a href="#string">string</a></td>
+ <td>optional</td>
+ <td><p>OTP code for MFA verification. Required if the target workspace enforces MFA. </p></td>
+ </tr>
+
+ <tr>
+ <td>recovery_code</td>
+ <td><a href="#string">string</a></td>
+ <td>optional</td>
+ <td><p>Recovery code for MFA verification (alternative to otp_code). </p></td>
+ </tr>
+
+ <tr>
+ <td>mfa_temp_token</td>
+ <td><a href="#string">string</a></td>
+ <td>optional</td>
+ <td><p>Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token. </p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
+
+
+
@@ -10397,6 +10470,14 @@ Returns access tokens so the user is logged in immediately after signup.</p></td
Permissions required: None (validates via refresh token cookie)</p></td>
</tr>
+ <tr>
+ <td>SwitchWorkspace</td>
+ <td><a href="#bytebase.v1.SwitchWorkspaceRequest">SwitchWorkspaceRequest</a></td>
+ <td><a href="#bytebase.v1.LoginResponse">LoginResponse</a></td>
+ <td><p>Switches the current user&#39;s active workspace and issues new tokens.
+The user must be a member of the target workspace.</p></td>
+ </tr>
+
</tbody>
</table>
@@ -10465,6 +10546,16 @@ Permissions required: None (validates via refresh token cookie)</p></td>
</tr>
+
+
+ <tr>
+ <td>SwitchWorkspace</td>
+ <td>POST</td>
+ <td>/v1/auth:switchWorkspace</td>
+ <td>*</td>
+ </tr>
+
+
</tbody>
</table>
@@ -32370,6 +32461,99 @@ Permissions required: bb.worksheets.manage (or creator, or project member for PR
<p></p>
+ <h3 id="bytebase.v1.ListWorkspacesRequest">ListWorkspacesRequest</h3>
+ <p></p>
+
+
+
+
+
+ <h3 id="bytebase.v1.ListWorkspacesResponse">ListWorkspacesResponse</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>workspaces</td>
+ <td><a href="#bytebase.v1.Workspace">Workspace</a></td>
+ <td>repeated</td>
+ <td><p> </p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
+
+
+
+ <h3 id="bytebase.v1.UpdateWorkspaceRequest">UpdateWorkspaceRequest</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>workspace</td>
+ <td><a href="#bytebase.v1.Workspace">Workspace</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
+ <tr>
+ <td>update_mask</td>
+ <td><a href="#google.protobuf.FieldMask">google.protobuf.FieldMask</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
+
+
+
+ <h3 id="bytebase.v1.Workspace">Workspace</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>name</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>Format: workspaces/{workspace} </p></td>
+ </tr>
+
+ <tr>
+ <td>title</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
+
+
+
@@ -32384,6 +32568,20 @@ Permissions required: bb.worksheets.manage (or creator, or project member for PR
</thead>
<tbody>
+ <tr>
+ <td>ListWorkspaces</td>
+ <td><a href="#bytebase.v1.ListWorkspacesRequest">ListWorkspacesRequest</a></td>
+ <td><a href="#bytebase.v1.ListWorkspacesResponse">ListWorkspacesResponse</a></td>
+ <td><p>Lists all workspaces the current user is a member of.</p></td>
+ </tr>
+
+ <tr>
+ <td>UpdateWorkspace</td>
+ <td><a href="#bytebase.v1.UpdateWorkspaceRequest">UpdateWorkspaceRequest</a></td>
+ <td><a href="#bytebase.v1.Workspace">Workspace</a></td>
+ <td><p>Updates a workspace. Currently only title can be updated.</p></td>
+ </tr>
+
<tr>
<td>GetIamPolicy</td>
<td><a href="#bytebase.v1.GetIamPolicyRequest">GetIamPolicyRequest</a></td>
@@ -32420,6 +32618,26 @@ Permissions required: bb.workspaces.setIamPolicy</p></td>
+ <tr>
+ <td>ListWorkspaces</td>
+ <td>GET</td>
+ <td>/v1/workspaces</td>
+ <td></td>
+ </tr>
+
+
+
+
+ <tr>
+ <td>UpdateWorkspace</td>
+ <td>PATCH</td>
+ <td>/v1/{workspace.name=workspaces/*}</td>
+ <td>*</td>
+ </tr>
+
+
+
+
<tr>
<td>GetIamPolicy</td>
<td>GET</td>
diff --git a/proto/v1/v1/auth_service.proto b/proto/v1/v1/auth_service.proto
index 8ba9e217a3..f6e4df9231 100644
--- a/proto/v1/v1/auth_service.proto
+++ b/proto/v1/v1/auth_service.proto
@@ -67,6 +67,16 @@ service AuthService {
};
option (bytebase.v1.allow_without_credential) = true;
}
+
+ // Switches the current user's active workspace and issues new tokens.
+ // The user must be a member of the target workspace.
+ rpc SwitchWorkspace(SwitchWorkspaceRequest) returns (LoginResponse) {
+ option (google.api.http) = {
+ post: "/v1/auth:switchWorkspace"
+ body: "*"
+ };
+ option (bytebase.v1.auth_method) = CUSTOM;
+ }
}
message LoginRequest {
@@ -167,3 +177,21 @@ message RefreshRequest {}
// Response from refreshing the access token.
message RefreshResponse {}
+
+message SwitchWorkspaceRequest {
+ // The target workspace to switch to.
+ // Format: workspaces/{workspace}
+ string workspace = 1;
+
+ // If true, sets tokens as HTTP-only cookies (browser clients).
+ bool web = 2;
+
+ // OTP code for MFA verification. Required if the target workspace enforces MFA.
+ optional string otp_code = 3;
+
+ // Recovery code for MFA verification (alternative to otp_code).
+ optional string recovery_code = 4;
+
+ // Temporary MFA token from a previous SwitchWorkspace call that returned mfa_temp_token.
+ optional string mfa_temp_token = 5;
+}
diff --git a/proto/v1/v1/workspace_service.proto b/proto/v1/v1/workspace_service.proto
index 3d5e991b0f..e1bb02eb25 100644
--- a/proto/v1/v1/workspace_service.proto
+++ b/proto/v1/v1/workspace_service.proto
@@ -3,6 +3,8 @@ syntax = "proto3";
package bytebase.v1;
import "google/api/annotations.proto";
+import "google/api/field_behavior.proto";
+import "google/protobuf/field_mask.proto";
import "v1/annotation.proto";
import "v1/iam_policy.proto";
@@ -10,6 +12,23 @@ option go_package = "github.com/bytebase/bytebase/backend/generated-go/v1";
// WorkspaceService manages workspace-level operations and profile.
service WorkspaceService {
+ // Lists all workspaces the current user is a member of.
+ rpc ListWorkspaces(ListWorkspacesRequest) returns (ListWorkspacesResponse) {
+ option (google.api.http) = {get: "/v1/workspaces"};
+ option (bytebase.v1.auth_method) = CUSTOM;
+ }
+
+ // Updates a workspace. Currently only title can be updated.
+ rpc UpdateWorkspace(UpdateWorkspaceRequest) returns (Workspace) {
+ option (google.api.http) = {
+ patch: "/v1/{workspace.name=workspaces/*}"
+ body: "*"
+ };
+ option (bytebase.v1.permission) = "bb.workspaces.update";
+ option (bytebase.v1.auth_method) = IAM;
+ option (bytebase.v1.audit) = true;
+ }
+
// Retrieves IAM policy for the workspace.
// Permissions required: bb.workspaces.getIamPolicy
rpc GetIamPolicy(GetIamPolicyRequest) returns (IamPolicy) {
@@ -30,3 +49,22 @@ service WorkspaceService {
option (bytebase.v1.audit) = true;
}
}
+
+message ListWorkspacesRequest {}
+
+message ListWorkspacesResponse {
+ repeated Workspace workspaces = 1;
+}
+
+message Workspace {
+ // Format: workspaces/{workspace}
+ string name = 1;
+
+ string title = 2;
+}
+
+message UpdateWorkspaceRequest {
+ Workspace workspace = 1 [(google.api.field_behavior) = REQUIRED];
+
+ google.protobuf.FieldMask update_mask = 2;
+}