Skip to content

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

chore: protofying store user type (#16386)

Danny Xu4cc91133afe1
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 76b0afda75..a3777776cf 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -6,6 +6,8 @@
"typescriptreact",
"vue"
],
+ "git.openRepositoryInParentFolders": "always",
+ "diffEditor.useInlineViewWhenSpaceIsLimited": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
@@ -38,11 +40,17 @@
"i18n-ally.editor.preferEditor": true,
"i18n-ally.enabledFrameworks": ["vue"],
"i18n-ally.parserOptions": {},
- "go.lintOnSave": "workspace",
+ "go.lintOnSave": "off",
"go.lintTool": "staticcheck",
+ "go.languageServerFlags": [
+ "-rpc.trace"
+ ],
+ "go.toolsManagement.checkForUpdates": "off",
"gopls": {
- "formatting.local": "github.com/bytebase/bytebase"
},
"go.testTimeout": "300s",
- "workbench.editor.enablePreview": false
+ "workbench.editor.enablePreview": false,
+ "go.survey.prompt": false,
+ "go.vetOnSave": "off",
+ "eslint.codeActionsOnSave.mode": "problems"
}
diff --git a/backend/api/directory-sync/webhook.go b/backend/api/directory-sync/webhook.go
index aaab1f1bb7..fbb51e4f77 100644
--- a/backend/api/directory-sync/webhook.go
+++ b/backend/api/directory-sync/webhook.go
@@ -66,7 +66,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {
newUser, err := s.store.CreateUser(ctx, &store.UserMessage{
Name: aadUser.DisplayName,
Email: aadUser.UserName,
- Type: base.EndUser,
+ Type: storepb.PrincipalType_END_USER,
MemberDeleted: !aadUser.Active,
PasswordHash: string(passwordHash),
Profile: &storepb.UserProfile{
diff --git a/backend/api/v1/actuator_service.go b/backend/api/v1/actuator_service.go
index 5b16fdf303..3cfaf59f49 100644
--- a/backend/api/v1/actuator_service.go
+++ b/backend/api/v1/actuator_service.go
@@ -253,7 +253,7 @@ func (s *ActuatorService) generateInstance(
}
func (s *ActuatorService) getServerInfo(ctx context.Context) (*v1pb.ActuatorInfo, error) {
- count, err := s.store.CountUsers(ctx, base.EndUser)
+ count, err := s.store.CountUsers(ctx, storepb.PrincipalType_END_USER)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 24bdc61285..3a5a6d2942 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -126,7 +126,7 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*v
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check user roles, error: %v", err)
}
- if !isWorkspaceAdmin && loginUser.Type == base.EndUser && !mfaSecondLogin {
+ if !isWorkspaceAdmin && loginUser.Type == storepb.PrincipalType_END_USER && !mfaSecondLogin {
// Disallow password signin for end users.
if setting.DisallowPasswordSignin && !loginViaIDP {
return nil, status.Errorf(codes.PermissionDenied, "password signin is disallowed")
@@ -151,13 +151,13 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*v
}
switch loginUser.Type {
- case base.EndUser:
+ case storepb.PrincipalType_END_USER:
token, err := auth.GenerateAccessToken(loginUser.Name, loginUser.ID, s.profile.Mode, s.secret, tokenDuration)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to generate API access token")
}
response.Token = token
- case base.ServiceAccount:
+ case storepb.PrincipalType_SERVICE_ACCOUNT:
token, err := auth.GenerateAPIToken(loginUser.Name, loginUser.ID, s.profile.Mode, s.secret)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to generate API access token")
@@ -208,7 +208,7 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*v
func (s *AuthService) needResetPassword(ctx context.Context, user *store.UserMessage) bool {
// Reset password restriction only works for end user with email & password login.
- if user.Type != base.EndUser {
+ if user.Type != storepb.PrincipalType_END_USER {
return false
}
if err := s.licenseService.IsFeatureEnabled(base.FeaturePasswordRestriction); err != nil {
@@ -225,7 +225,7 @@ func (s *AuthService) needResetPassword(ctx context.Context, user *store.UserMes
if !passwordRestriction.RequireResetPasswordForFirstLogin {
return false
}
- count, err := s.store.CountUsers(ctx, base.EndUser)
+ count, err := s.store.CountUsers(ctx, storepb.PrincipalType_END_USER)
if err != nil {
slog.Error("failed to count end users", log.BBError(err))
return false
@@ -428,7 +428,7 @@ func (s *AuthService) getOrCreateUserWithIDP(ctx context.Context, request *v1pb.
Name: userInfo.DisplayName,
Email: email,
Phone: userInfo.Phone,
- Type: base.EndUser,
+ Type: storepb.PrincipalType_END_USER,
PasswordHash: string(passwordHash),
})
if err != nil {
diff --git a/backend/api/v1/group_service.go b/backend/api/v1/group_service.go
index 5034a71603..6059122e0e 100644
--- a/backend/api/v1/group_service.go
+++ b/backend/api/v1/group_service.go
@@ -7,7 +7,6 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
- "github.com/bytebase/bytebase/backend/base"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/iam"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
@@ -228,7 +227,7 @@ func (s *GroupService) convertToGroupPayload(ctx context.Context, group *v1pb.Gr
if user == nil {
return nil, status.Errorf(codes.InvalidArgument, "cannot found member %s", member.Member)
}
- if user.Type != base.EndUser {
+ if user.Type != storepb.PrincipalType_END_USER {
return nil, status.Errorf(codes.InvalidArgument, "only allow add end users to the group")
}
diff --git a/backend/api/v1/user_service.go b/backend/api/v1/user_service.go
index 7ddb55fc10..dd7198dd6b 100644
--- a/backend/api/v1/user_service.go
+++ b/backend/api/v1/user_service.go
@@ -345,7 +345,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
return nil, status.Errorf(codes.InvalidArgument, "support user and service account only")
}
- count, err := s.store.CountUsers(ctx, base.EndUser)
+ count, err := s.store.CountUsers(ctx, storepb.PrincipalType_END_USER)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to count users, error: %v", err)
}
@@ -357,7 +357,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
}
}
- if err := validateEmailWithDomains(ctx, s.licenseService, s.store, request.User.Email, principalType == base.ServiceAccount, false); err != nil {
+ if err := validateEmailWithDomains(ctx, s.licenseService, s.store, request.User.Email, principalType == storepb.PrincipalType_SERVICE_ACCOUNT, false); err != nil {
return nil, err
}
existingUser, err := s.store.GetUserByEmail(ctx, request.User.Email)
@@ -503,7 +503,7 @@ func (s *UserService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
for _, path := range request.UpdateMask.Paths {
switch path {
case "email":
- if err := validateEmailWithDomains(ctx, s.licenseService, s.store, request.User.Email, user.Type == base.ServiceAccount, false); err != nil {
+ if err := validateEmailWithDomains(ctx, s.licenseService, s.store, request.User.Email, user.Type == storepb.PrincipalType_SERVICE_ACCOUNT, false); err != nil {
return nil, err
}
existedUser, err := s.store.GetUserByEmail(ctx, request.User.Email)
@@ -517,7 +517,7 @@ func (s *UserService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
case "title":
patch.Name = &request.User.Title
case "password":
- if user.Type != base.EndUser {
+ if user.Type != storepb.PrincipalType_END_USER {
return nil, status.Errorf(codes.InvalidArgument, "password can be mutated for end users only")
}
if err := s.validatePassword(ctx, request.User.Password); err != nil {
@@ -525,7 +525,7 @@ func (s *UserService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
}
passwordPatch = &request.User.Password
case "service_key":
- if user.Type != base.ServiceAccount {
+ if user.Type != storepb.PrincipalType_SERVICE_ACCOUNT {
return nil, status.Errorf(codes.InvalidArgument, "service key can be mutated for service accounts only")
}
val, err := common.RandomString(20)
@@ -692,7 +692,7 @@ func (s *UserService) getActiveUserCount(ctx context.Context) (int, error) {
}
activeEndUserCount := 0
for _, stat := range userStat {
- if !stat.Deleted && stat.Type == base.EndUser {
+ if !stat.Deleted && stat.Type == storepb.PrincipalType_END_USER {
activeEndUserCount = stat.Count
break
}
@@ -721,7 +721,7 @@ func (s *UserService) hasExtraWorkspaceAdmin(ctx context.Context, policy *storep
}
users := utils.GetUsersByMember(ctx, s.store, member)
for _, user := range users {
- if !user.MemberDeleted && user.Type == base.EndUser {
+ if !user.MemberDeleted && user.Type == storepb.PrincipalType_END_USER {
return true, nil
}
}
@@ -770,13 +770,13 @@ func (s *UserService) UndeleteUser(ctx context.Context, request *v1pb.UndeleteUs
return convertToUser(user), nil
}
-func convertToV1UserType(userType base.PrincipalType) v1pb.UserType {
+func convertToV1UserType(userType storepb.PrincipalType) v1pb.UserType {
switch userType {
- case base.EndUser:
+ case storepb.PrincipalType_END_USER:
return v1pb.UserType_USER
- case base.SystemBot:
+ case storepb.PrincipalType_SYSTEM_BOT:
return v1pb.UserType_SYSTEM_BOT
- case base.ServiceAccount:
+ case storepb.PrincipalType_SERVICE_ACCOUNT:
return v1pb.UserType_SERVICE_ACCOUNT
default:
return v1pb.UserType_USER_TYPE_UNSPECIFIED
@@ -806,15 +806,15 @@ func convertToUser(user *store.UserMessage) *v1pb.User {
return convertedUser
}
-func convertToPrincipalType(userType v1pb.UserType) (base.PrincipalType, error) {
- var t base.PrincipalType
+func convertToPrincipalType(userType v1pb.UserType) (storepb.PrincipalType, error) {
+ var t storepb.PrincipalType
switch userType {
case v1pb.UserType_USER:
- t = base.EndUser
+ t = storepb.PrincipalType_END_USER
case v1pb.UserType_SYSTEM_BOT:
- t = base.SystemBot
+ t = storepb.PrincipalType_SYSTEM_BOT
case v1pb.UserType_SERVICE_ACCOUNT:
- t = base.ServiceAccount
+ t = storepb.PrincipalType_SERVICE_ACCOUNT
default:
return t, status.Errorf(codes.InvalidArgument, "invalid user type %s", userType)
}
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 047f0b7c7a..c44d8a11d2 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -11,6 +11,7 @@ import (
"github.com/bytebase/bytebase/backend/component/iam"
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/utils"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
@@ -89,7 +90,7 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIa
func containsActiveEndUser(users []*store.UserMessage) bool {
for _, user := range users {
- if user.Type == base.EndUser && !user.MemberDeleted {
+ if user.Type == storepb.PrincipalType_END_USER && !user.MemberDeleted {
return true
}
}
diff --git a/backend/base/principal.go b/backend/base/principal.go
index 037cf79b22..d59a85485d 100644
--- a/backend/base/principal.go
+++ b/backend/base/principal.go
@@ -6,20 +6,7 @@ const SystemBotID = 1
// AllUsers is the email of the pseudo allUsers account.
const AllUsers = "allUsers"
-// PrincipalType is the type of a principal.
-type PrincipalType string
-
const (
- // EndUser is the principal type for END_USER.
- // EndUser represents the human being using Bytebase.
- EndUser PrincipalType = "END_USER"
- // ServiceAccount is the principal type for SERVICE_ACCOUNT.
- // ServiceAcount represents the external service calling Bytebase OpenAPI.
- ServiceAccount PrincipalType = "SERVICE_ACCOUNT"
- // SystemBot is the principal type for SYSTEM_BOT.
- // SystemBot represents the internal system bot performing operations.
- SystemBot PrincipalType = "SYSTEM_BOT"
-
// PrincipalIDForFirstUser is the principal id for the first user in workspace.
PrincipalIDForFirstUser = 101
diff --git a/backend/base/task_run.go b/backend/base/task_run.go
deleted file mode 100644
index 22f1111448..0000000000
--- a/backend/base/task_run.go
+++ /dev/null
@@ -1 +0,0 @@
-package base
diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.go
index ac98f3a259..1ce24c3710 100644
--- a/backend/component/webhook/manager.go
+++ b/backend/component/webhook/manager.go
@@ -265,7 +265,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, even
var mentionEndUsers []*store.UserMessage
for _, u := range mentionUsers {
- if u.Type == base.EndUser {
+ if u.Type == storepb.PrincipalType_END_USER {
mentionEndUsers = append(mentionEndUsers, u)
}
}
diff --git a/backend/store/principal.go b/backend/store/principal.go
index b593a3d47a..b72eaa4411 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -22,7 +22,7 @@ var systemBotUser = &UserMessage{
ID: base.SystemBotID,
Name: "Bytebase",
- Type: base.SystemBot,
+ Type: storepb.PrincipalType_SYSTEM_BOT,
}
// FindUserMessage is the message for finding users.
@@ -30,7 +30,7 @@ type FindUserMessage struct {
ID *int
Email *string
ShowDeleted bool
- Type *base.PrincipalType
+ Type *storepb.PrincipalType
Limit *int
Offset *int
Filter *ListResourceFilter
@@ -54,7 +54,7 @@ type UserMessage struct {
// Email must be lower case.
Email string
Name string
- Type base.PrincipalType
+ Type storepb.PrincipalType
PasswordHash string
MemberDeleted bool
MFAConfig *storepb.MFAConfig
@@ -66,7 +66,7 @@ type UserMessage struct {
}
type UserStat struct {
- Type base.PrincipalType
+ Type storepb.PrincipalType
Deleted bool
Count int
}
@@ -129,13 +129,19 @@ func (s *Store) StatUsers(ctx context.Context) ([]*UserStat, error) {
for rows.Next() {
var stat UserStat
+ var typeString string
if err := rows.Scan(
&stat.Count,
- &stat.Type,
+ &typeString,
&stat.Deleted,
); err != nil {
return nil, err
}
+ if typeValue, ok := storepb.PrincipalType_value[typeString]; ok {
+ stat.Type = storepb.PrincipalType(typeValue)
+ } else {
+ return nil, errors.Errorf("invalid principal type string: %s", typeString)
+ }
stats = append(stats, &stat)
}
if err := rows.Err(); err != nil {
@@ -210,7 +216,7 @@ func listUserImpl(ctx context.Context, txn *sql.Tx, find *FindUserMessage) ([]*U
}
}
if v := find.Type; v != nil {
- where, args = append(where, fmt.Sprintf("principal.type = $%d", len(args)+1)), append(args, *v)
+ where, args = append(where, fmt.Sprintf("principal.type = $%d", len(args)+1)), append(args, v.String())
}
if !find.ShowDeleted {
where, args = append(where, fmt.Sprintf("principal.deleted = $%d", len(args)+1)), append(args, false)
@@ -262,12 +268,13 @@ func listUserImpl(ctx context.Context, txn *sql.Tx, find *FindUserMessage) ([]*U
var userMessage UserMessage
var mfaConfigBytes []byte
var profileBytes []byte
+ var typeString string
if err := rows.Scan(
&userMessage.ID,
&userMessage.MemberDeleted,
&userMessage.Email,
&userMessage.Name,
- &userMessage.Type,
+ &typeString,
&userMessage.PasswordHash,
&mfaConfigBytes,
&userMessage.Phone,
@@ -276,6 +283,11 @@ func listUserImpl(ctx context.Context, txn *sql.Tx, find *FindUserMessage) ([]*U
); err != nil {
return nil, err
}
+ if typeValue, ok := storepb.PrincipalType_value[typeString]; ok {
+ userMessage.Type = storepb.PrincipalType(typeValue)
+ } else {
+ return nil, errors.Errorf("invalid principal type string: %s", typeString)
+ }
mfaConfig := storepb.MFAConfig{}
if err := common.ProtojsonUnmarshaler.Unmarshal(mfaConfigBytes, &mfaConfig); err != nil {
@@ -320,7 +332,7 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage) (*UserMessa
}
set := []string{"email", "name", "type", "password_hash", "phone", "profile"}
- args := []any{create.Email, create.Name, create.Type, create.PasswordHash, create.Phone, profileBytes}
+ args := []any{create.Email, create.Name, create.Type.String(), create.PasswordHash, create.Phone, profileBytes}
placeholder := []string{}
for index := range set {
placeholder = append(placeholder, fmt.Sprintf("$%d", index+1))
diff --git a/backend/store/stats.go b/backend/store/stats.go
index a4aaa059cb..8ac4838a48 100644
--- a/backend/store/stats.go
+++ b/backend/store/stats.go
@@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
- "github.com/bytebase/bytebase/backend/base"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/metric"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -20,7 +19,7 @@ type CountInstanceMessage struct {
}
// CountUsers counts the principal.
-func (s *Store) CountUsers(ctx context.Context, userType base.PrincipalType) (int, error) {
+func (s *Store) CountUsers(ctx context.Context, userType storepb.PrincipalType) (int, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return 0, err
@@ -33,7 +32,7 @@ func (s *Store) CountUsers(ctx context.Context, userType base.PrincipalType) (in
SELECT COUNT(*)
FROM principal
WHERE principal.type = $1`,
- userType).Scan(&count); err != nil {
+ userType.String()).Scan(&count); err != nil {
return 0, err
}
@@ -86,7 +85,7 @@ func (s *Store) CountActiveUsers(ctx context.Context) (int, error) {
FROM principal
WHERE principal.deleted = $1 AND (principal.type = $2 OR principal.type = $3)`
var count int
- if err := tx.QueryRowContext(ctx, query, false, base.EndUser, base.ServiceAccount).Scan(&count); err != nil {
+ if err := tx.QueryRowContext(ctx, query, false, storepb.PrincipalType_END_USER.String(), storepb.PrincipalType_SERVICE_ACCOUNT.String()).Scan(&count); err != nil {
if err == sql.ErrNoRows {
return 0, common.FormatDBErrorEmptyRowWithQuery(query)
}
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index e89337a108..598f50359f 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -328,6 +328,8 @@
- [MFAConfig](#bytebase-store-MFAConfig)
- [UserProfile](#bytebase-store-UserProfile)
+ - [PrincipalType](#bytebase-store-PrincipalType)
+
- [Scalar Value Types](#scalar-value-types)
@@ -5091,6 +5093,20 @@ MFAConfig is the MFA configuration for a user.
+
+<a name="bytebase-store-PrincipalType"></a>
+
+### PrincipalType
+PrincipalType is the type of a principal.
+
+| Name | Number | Description |
+| ---- | ------ | ----------- |
+| PRINCIPAL_TYPE_UNSPECIFIED | 0 | |
+| END_USER | 1 | END_USER represents the human being using Bytebase. |
+| SERVICE_ACCOUNT | 2 | SERVICE_ACCOUNT represents the external service calling Bytebase OpenAPI. |
+| SYSTEM_BOT | 3 | SYSTEM_BOT represents the internal system bot performing operations. |
+
+
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index c567e1de22..49cd54ff0c 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -1496,6 +1496,10 @@
</li>
+ <li>
+ <a href="#bytebase.store.PrincipalType"><span class="badge">E</span>PrincipalType</a>
+ </li>
+
</ul>
@@ -12919,6 +12923,41 @@ Format: instances/{instance}/databases/{database} </p></td>
+ <h3 id="bytebase.store.PrincipalType">PrincipalType</h3>
+ <p>PrincipalType is the type of a principal.</p>
+ <table class="enum-table">
+ <thead>
+ <tr><td>Name</td><td>Number</td><td>Description</td></tr>
+ </thead>
+ <tbody>
+
+ <tr>
+ <td>PRINCIPAL_TYPE_UNSPECIFIED</td>
+ <td>0</td>
+ <td><p></p></td>
+ </tr>
+
+ <tr>
+ <td>END_USER</td>
+ <td>1</td>
+ <td><p>END_USER represents the human being using Bytebase.</p></td>
+ </tr>
+
+ <tr>
+ <td>SERVICE_ACCOUNT</td>
+ <td>2</td>
+ <td><p>SERVICE_ACCOUNT represents the external service calling Bytebase OpenAPI.</p></td>
+ </tr>
+
+ <tr>
+ <td>SYSTEM_BOT</td>
+ <td>3</td>
+ <td><p>SYSTEM_BOT represents the internal system bot performing operations.</p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
diff --git a/proto/generated-go/store/user.pb.go b/proto/generated-go/store/user.pb.go
index ef853188ae..338625acad 100644
--- a/proto/generated-go/store/user.pb.go
+++ b/proto/generated-go/store/user.pb.go
@@ -22,6 +22,62 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
+// PrincipalType is the type of a principal.
+type PrincipalType int32
+
+const (
+ PrincipalType_PRINCIPAL_TYPE_UNSPECIFIED PrincipalType = 0
+ // END_USER represents the human being using Bytebase.
+ PrincipalType_END_USER PrincipalType = 1
+ // SERVICE_ACCOUNT represents the external service calling Bytebase OpenAPI.
+ PrincipalType_SERVICE_ACCOUNT PrincipalType = 2
+ // SYSTEM_BOT represents the internal system bot performing operations.
+ PrincipalType_SYSTEM_BOT PrincipalType = 3
+)
+
+// Enum value maps for PrincipalType.
+var (
+ PrincipalType_name = map[int32]string{
+ 0: "PRINCIPAL_TYPE_UNSPECIFIED",
+ 1: "END_USER",
+ 2: "SERVICE_ACCOUNT",
+ 3: "SYSTEM_BOT",
+ }
+ PrincipalType_value = map[string]int32{
+ "PRINCIPAL_TYPE_UNSPECIFIED": 0,
+ "END_USER": 1,
+ "SERVICE_ACCOUNT": 2,
+ "SYSTEM_BOT": 3,
+ }
+)
+
+func (x PrincipalType) Enum() *PrincipalType {
+ p := new(PrincipalType)
+ *p = x
+ return p
+}
+
+func (x PrincipalType) String() string {
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (PrincipalType) Descriptor() protoreflect.EnumDescriptor {
+ return file_store_user_proto_enumTypes[0].Descriptor()
+}
+
+func (PrincipalType) Type() protoreflect.EnumType {
+ return &file_store_user_proto_enumTypes[0]
+}
+
+func (x PrincipalType) Number() protoreflect.EnumNumber {
+ return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use PrincipalType.Descriptor instead.
+func (PrincipalType) EnumDescriptor() ([]byte, []int) {
+ return file_store_user_proto_rawDescGZIP(), []int{0}
+}
+
// MFAConfig is the MFA configuration for a user.
type MFAConfig struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -170,7 +226,13 @@ const file_store_user_proto_rawDesc = "" +
"\vUserProfile\x12B\n" +
"\x0flast_login_time\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\rlastLoginTime\x12U\n" +
"\x19last_change_password_time\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\x16lastChangePasswordTime\x12\x16\n" +
- "\x06source\x18\x03 \x01(\tR\x06sourceB\x14Z\x12generated-go/storeb\x06proto3"
+ "\x06source\x18\x03 \x01(\tR\x06source*b\n" +
+ "\rPrincipalType\x12\x1e\n" +
+ "\x1aPRINCIPAL_TYPE_UNSPECIFIED\x10\x00\x12\f\n" +
+ "\bEND_USER\x10\x01\x12\x13\n" +
+ "\x0fSERVICE_ACCOUNT\x10\x02\x12\x0e\n" +
+ "\n" +
+ "SYSTEM_BOT\x10\x03B\x14Z\x12generated-go/storeb\x06proto3"
var (
file_store_user_proto_rawDescOnce sync.Once
@@ -184,15 +246,17 @@ func file_store_user_proto_rawDescGZIP() []byte {
return file_store_user_proto_rawDescData
}
+var file_store_user_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_store_user_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_store_user_proto_goTypes = []any{
- (*MFAConfig)(nil), // 0: bytebase.store.MFAConfig
- (*UserProfile)(nil), // 1: bytebase.store.UserProfile
- (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp
+ (PrincipalType)(0), // 0: bytebase.store.PrincipalType
+ (*MFAConfig)(nil), // 1: bytebase.store.MFAConfig
+ (*UserProfile)(nil), // 2: bytebase.store.UserProfile
+ (*timestamppb.Timestamp)(nil), // 3: google.protobuf.Timestamp
}
var file_store_user_proto_depIdxs = []int32{
- 2, // 0: bytebase.store.UserProfile.last_login_time:type_name -> google.protobuf.Timestamp
- 2, // 1: bytebase.store.UserProfile.last_change_password_time:type_name -> google.protobuf.Timestamp
+ 3, // 0: bytebase.store.UserProfile.last_login_time:type_name -> google.protobuf.Timestamp
+ 3, // 1: bytebase.store.UserProfile.last_change_password_time:type_name -> google.protobuf.Timestamp
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
@@ -210,13 +274,14 @@ func file_store_user_proto_init() {
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_store_user_proto_rawDesc), len(file_store_user_proto_rawDesc)),
- NumEnums: 0,
+ NumEnums: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_store_user_proto_goTypes,
DependencyIndexes: file_store_user_proto_depIdxs,
+ EnumInfos: file_store_user_proto_enumTypes,
MessageInfos: file_store_user_proto_msgTypes,
}.Build()
File_store_user_proto = out.File
diff --git a/proto/store/store/user.proto b/proto/store/store/user.proto
index 16c5902be6..23433f91c8 100644
--- a/proto/store/store/user.proto
+++ b/proto/store/store/user.proto
@@ -6,6 +6,17 @@ import "google/protobuf/timestamp.proto";
option go_package = "generated-go/store";
+// PrincipalType is the type of a principal.
+enum PrincipalType {
+ PRINCIPAL_TYPE_UNSPECIFIED = 0;
+ // END_USER represents the human being using Bytebase.
+ END_USER = 1;
+ // SERVICE_ACCOUNT represents the external service calling Bytebase OpenAPI.
+ SERVICE_ACCOUNT = 2;
+ // SYSTEM_BOT represents the internal system bot performing operations.
+ SYSTEM_BOT = 3;
+}
+
// MFAConfig is the MFA configuration for a user.
message MFAConfig {
// The otp_secret is the secret key used to validate the OTP code.