Skip to content

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

chore: annotate PrincipalType (#3571)

Tianzhou (天舟)e6ecff56f4b3
diff --git a/api/principal.go b/api/principal.go
index f2b53581e1..daa4da0ca0 100644
--- a/api/principal.go
+++ b/api/principal.go
@@ -12,11 +12,14 @@ 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"
- // BOT is the principal type for BOT.
- BOT PrincipalType = "BOT"
+ // SystemBot is the principal type for SYSTEM_BOT.
+ // SystemBot represents the internal system bot performing operations.
+ SystemBot PrincipalType = "SYSTEM_BOT"
)
// PrincipalAuthProvider is the type of an authentication provider.
diff --git a/server/jwt.go b/server/jwt.go
index 2c7f7f7d01..45fb5dc320 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -46,6 +46,11 @@ const (
// The key name used to store principal id in the context
// principal id is extracted from the jwt token subject field.
principalIDContextKey = "principal-id"
+
+ // Various access key / token prefix.
+
+ // serviceAccountAccessKeyPrefix is the prefix for service account access key.
+ serviceAccountAccessKeyPrefix = "bbs_"
)
// Claims creates a struct that will be encoded to a JWT.
diff --git a/server/principal.go b/server/principal.go
index d9f81ae411..7baa53766e 100644
--- a/server/principal.go
+++ b/server/principal.go
@@ -28,7 +28,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate access key for service account.").SetInternal(err)
}
- principalCreate.Password = fmt.Sprintf("bbs_%s", pwd)
+ principalCreate.Password = fmt.Sprintf("%s%s", serviceAccountAccessKeyPrefix, pwd)
}
passwordHash, err := bcrypt.GenerateFromPassword([]byte(principalCreate.Password), bcrypt.DefaultCost)
@@ -115,7 +115,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate access key for service account.").SetInternal(err)
}
- password := fmt.Sprintf("bbs_%s", val)
+ password := fmt.Sprintf("%s%s", serviceAccountAccessKeyPrefix, val)
principalPatch.Password = &password
}