Skip to content

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

chore: put external-url and disallow-signup flag into setting store (#4941)

ecmadaod7bcfca3dfcf
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index c4b50b43ea..f8ee6ee18a 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -81,7 +81,12 @@ func (s *AuthService) ListUsers(ctx context.Context, request *v1pb.ListUsersRequ
// CreateUser creates a user.
func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRequest) (*v1pb.User, error) {
- if s.profile.DisallowSignup {
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to find workspace setting, error: %v", err)
+ }
+
+ if setting.DisallowSignup {
return nil, status.Errorf(codes.PermissionDenied, "sign up is disallowed")
}
if request.User == nil {
@@ -492,6 +497,11 @@ func (s *AuthService) getOrCreateUserWithIDP(ctx context.Context, request *v1pb.
return nil, status.Errorf(codes.NotFound, "identity provider not found")
}
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
+ }
+
var userInfo *storepb.IdentityProviderUserInfo
var fieldMapping *storepb.FieldMapping
if idp.Type == storepb.IdentityProviderType_OAUTH2 {
@@ -503,7 +513,7 @@ func (s *AuthService) getOrCreateUserWithIDP(ctx context.Context, request *v1pb.
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create new OAuth2 identity provider: %v", err)
}
- redirectURL := fmt.Sprintf("%s/oauth/callback", s.profile.ExternalURL)
+ redirectURL := fmt.Sprintf("%s/oauth/callback", setting.ExternalUrl)
token, err := oauth2IdentityProvider.ExchangeToken(ctx, redirectURL, oauth2Context.Code)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to exchange token: %v", err)
@@ -532,7 +542,7 @@ func (s *AuthService) getOrCreateUserWithIDP(ctx context.Context, request *v1pb.
return nil, status.Errorf(codes.Internal, "failed to create new OIDC identity provider: %v", err)
}
- redirectURL := fmt.Sprintf("%s/oidc/callback", s.profile.ExternalURL)
+ redirectURL := fmt.Sprintf("%s/oidc/callback", setting.ExternalUrl)
token, err := oidcIDP.ExchangeToken(ctx, redirectURL, oauth2Context.Code)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to exchange token: %v", err)
diff --git a/backend/api/v1/idp_service.go b/backend/api/v1/idp_service.go
index b9411ec94f..1f03c6de54 100644
--- a/backend/api/v1/idp_service.go
+++ b/backend/api/v1/idp_service.go
@@ -11,7 +11,6 @@ import (
"github.com/pkg/errors"
- "github.com/bytebase/bytebase/backend/component/config"
enterpriseAPI "github.com/bytebase/bytebase/backend/enterprise/api"
"github.com/bytebase/bytebase/backend/plugin/idp/oauth2"
"github.com/bytebase/bytebase/backend/plugin/idp/oidc"
@@ -25,15 +24,13 @@ type IdentityProviderService struct {
v1pb.UnimplementedIdentityProviderServiceServer
store *store.Store
licenseService enterpriseAPI.LicenseService
- profile *config.Profile
}
// NewIdentityProviderService creates a new IdentityProviderService.
-func NewIdentityProviderService(store *store.Store, licenseService enterpriseAPI.LicenseService, profile *config.Profile) *IdentityProviderService {
+func NewIdentityProviderService(store *store.Store, licenseService enterpriseAPI.LicenseService) *IdentityProviderService {
return &IdentityProviderService{
store: store,
licenseService: licenseService,
- profile: profile,
}
}
@@ -192,6 +189,11 @@ func (s *IdentityProviderService) TestIdentityProvider(ctx context.Context, requ
return nil, status.Errorf(codes.NotFound, "identity provider not found")
}
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
+ }
+
if identityProvider.Type == v1pb.IdentityProviderType_OAUTH2 {
// Find client secret for those existed identity providers.
if request.IdentityProvider.Config.GetOauth2Config().ClientSecret == "" {
@@ -214,7 +216,7 @@ func (s *IdentityProviderService) TestIdentityProvider(ctx context.Context, requ
return nil, status.Errorf(codes.Internal, "failed to new oauth2 identity provider")
}
- redirectURL := fmt.Sprintf("%s/oauth/callback", s.profile.ExternalURL)
+ redirectURL := fmt.Sprintf("%s/oauth/callback", setting.ExternalUrl)
token, err := oauth2IdentityProvider.ExchangeToken(ctx, redirectURL, oauth2Context.Code)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to exchange access token, error: %s", err.Error())
@@ -249,7 +251,7 @@ func (s *IdentityProviderService) TestIdentityProvider(ctx context.Context, requ
return nil, status.Errorf(codes.Internal, "failed to create new OIDC identity provider: %v", err)
}
- redirectURL := fmt.Sprintf("%s/oidc/callback", s.profile.ExternalURL)
+ redirectURL := fmt.Sprintf("%s/oidc/callback", setting.ExternalUrl)
token, err := oidcIdentityProvider.ExchangeToken(ctx, redirectURL, oauth2Context.Code)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to exchange access token, error: %s", err.Error())
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index 233d46ead3..5c2fc65e69 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -20,7 +20,9 @@ type SettingService struct {
// NewSettingService creates a new setting service.
func NewSettingService(store *store.Store) *SettingService {
- return &SettingService{store: store}
+ return &SettingService{
+ store: store,
+ }
}
// Some settings contain secret info so we only return settings that are needed by the client.
@@ -68,13 +70,15 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
if settingName == "" {
return nil, status.Errorf(codes.InvalidArgument, "setting name is empty")
}
+ apiSettingName := api.SettingName(settingName)
setting, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
- Name: api.SettingName(settingName),
+ Name: apiSettingName,
Value: request.Setting.Value.GetStringValue(),
}, ctx.Value(common.PrincipalIDContextKey).(int))
if err != nil {
return nil, err
}
+
return convertToSettingMessage(setting), nil
}
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.go
index e828e68ab4..fc51f18915 100644
--- a/backend/bin/server/cmd/profile.go
+++ b/backend/bin/server/cmd/profile.go
@@ -23,7 +23,6 @@ func getBaseProfile(dataDir string) config.Profile {
ResourceDir: common.GetResourceDir(dataDir),
Debug: flags.debug,
DemoName: flags.demoName,
- DisallowSignup: flags.disallowSignup,
Version: version,
GitCommit: gitcommit,
PgURL: flags.pgURL,
diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.go
index 3c60416f79..225c243e59 100644
--- a/backend/bin/server/cmd/root.go
+++ b/backend/bin/server/cmd/root.go
@@ -9,7 +9,6 @@ import (
"os"
"os/signal"
"path/filepath"
- "strconv"
"strings"
"syscall"
@@ -20,6 +19,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/server"
+ "github.com/bytebase/bytebase/backend/utils"
)
// -----------------------------------Global constant BEGIN----------------------------------------.
@@ -76,8 +76,6 @@ var (
// empty means no demo.
demoName string
debug bool
- // disallowSignup will disallow the sign up, users can only be invited by the owner.
- disallowSignup bool
// pgURL must follow PostgreSQL connection URIs pattern.
// https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
pgURL string
@@ -124,8 +122,6 @@ func init() {
// Must be one of the subpath name in the ./store/demo/ directory
rootCmd.PersistentFlags().StringVar(&flags.demoName, "demo", "", "name of the demo to use. Empty means not running in demo mode.")
rootCmd.PersistentFlags().BoolVar(&flags.debug, "debug", false, "whether to enable debug level logging")
- // Disallow signup
- rootCmd.PersistentFlags().BoolVar(&flags.disallowSignup, "disallow-signup", false, "whether to disallow the sign up")
// Support environment variable for deploying to render.com using its blueprint file.
// Render blueprint allows to specify a postgres database along with a service.
// It allows to pass the postgres connection string as an ENV to the service.
@@ -141,32 +137,6 @@ func init() {
// -----------------------------------Command Line Config END--------------------------------------
-func normalizeExternalURL(url string) (string, error) {
- r := strings.TrimSpace(url)
- r = strings.TrimSuffix(r, "/")
- if !common.HasPrefixes(r, "http://", "https://") {
- return "", errors.Errorf("%s must start with http:// or https://", url)
- }
- parts := strings.Split(r, ":")
- if len(parts) > 3 {
- return "", errors.Errorf("%s malformed", url)
- }
- if len(parts) == 3 {
- port, err := strconv.Atoi(parts[2])
- if err != nil {
- return "", errors.Errorf("%s has non integer port", url)
- }
- // The external URL is used as the redirectURL in the get token process of OAuth, and the
- // RedirectURL needs to be consistent with the RedirectURL in the get code process.
- // The frontend gets it through window.location.origin in the get code
- // process, so port 80/443 need to be cropped.
- if port == 80 || port == 443 {
- r = strings.Join(parts[0:2], ":")
- }
- }
- return r, nil
-}
-
func checkDataDir() error {
// Clean data directory path.
flags.dataDir = filepath.Clean(flags.dataDir)
@@ -220,7 +190,7 @@ func start() {
defer log.Sync()
var err error
- flags.externalURL, err = normalizeExternalURL(flags.externalURL)
+ flags.externalURL, err = utils.NormalizeExternalURL(flags.externalURL)
if err != nil {
log.Error("invalid --external-url", zap.Error(err))
return
diff --git a/backend/bin/server/cmd/root_test.go b/backend/bin/server/cmd/root_test.go
deleted file mode 100644
index ec72110b81..0000000000
--- a/backend/bin/server/cmd/root_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package cmd
-
-import (
- "testing"
-)
-
-func TestNormalizeExternalURL(t *testing.T) {
- tests := []struct {
- url string
- want string
- wantErr bool
- }{
- {
- url: "http://localhost:3000",
- want: "http://localhost:3000",
- wantErr: false,
- },
- {
- url: "https://localhost:3000",
- want: "https://localhost:3000",
- wantErr: false,
- },
- {
- url: "https://localhost",
- want: "https://localhost",
- wantErr: false,
- },
- {
- url: "http://localhost:80",
- want: "http://localhost",
- wantErr: false,
- },
- {
- url: "https://localhost:443",
- want: "https://localhost",
- wantErr: false,
- },
- {
- url: " https://localhost:3000/ ",
- want: "https://localhost:3000",
- wantErr: false,
- },
- // Missing http:// or https://
- {
- url: "localhost:3000",
- want: "",
- wantErr: true,
- },
- // Invalid port
- {
- url: "http://localhost:xxx",
- want: "",
- wantErr: true,
- },
- }
- for _, tt := range tests {
- t.Run(tt.url, func(t *testing.T) {
- g, err := normalizeExternalURL(tt.url)
- if err != nil {
- if !tt.wantErr {
- t.Errorf("expect no error, got %s", err.Error())
- }
- } else {
- if tt.wantErr {
- t.Errorf("expect error")
- } else if tt.want != g {
- t.Errorf("expect %s, got %s", tt.want, g)
- }
- }
- })
- }
-}
diff --git a/backend/component/activity/manager.go b/backend/component/activity/manager.go
index 0bbe0ff249..0aadcf4235 100644
--- a/backend/component/activity/manager.go
+++ b/backend/component/activity/manager.go
@@ -13,7 +13,6 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
- "github.com/bytebase/bytebase/backend/component/config"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/webhook"
"github.com/bytebase/bytebase/backend/store"
@@ -25,8 +24,7 @@ import (
// Manager is the activity manager.
type Manager struct {
- store *store.Store
- profile config.Profile
+ store *store.Store
}
// Metadata is the activity metadata.
@@ -35,10 +33,9 @@ type Metadata struct {
}
// NewManager creates an activity manager.
-func NewManager(store *store.Store, profile config.Profile) *Manager {
+func NewManager(store *store.Store) *Manager {
return &Manager{
- store: store,
- profile: profile,
+ store: store,
}
}
@@ -87,6 +84,12 @@ func (m *Manager) BatchCreateTaskStatusUpdateApprovalActivity(ctx context.Contex
if len(webhookList) == 0 {
return nil
}
+
+ setting, err := m.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return errors.Wrapf(err, "failed to get workspace setting")
+ }
+
// Send one webhook post for all activities.
webhookCtx := webhook.Context{
Level: webhook.WebhookInfo,
@@ -104,7 +107,7 @@ func (m *Manager) BatchCreateTaskStatusUpdateApprovalActivity(ctx context.Contex
Name: issue.Project.Title,
},
Description: anyActivity.Comment,
- Link: fmt.Sprintf("%s/issue/%s-%d", m.profile.ExternalURL, slug.Make(issue.Title), issue.UID),
+ Link: fmt.Sprintf("%s/issue/%s-%d", setting.ExternalUrl, slug.Make(issue.Title), issue.UID),
CreatorID: anyActivity.CreatorID,
CreatorName: anyActivity.Creator.Name,
CreatorEmail: anyActivity.Creator.Email,
@@ -190,9 +193,15 @@ func postWebhookList(webhookCtx webhook.Context, webhookList []*api.ProjectWebho
func (m *Manager) getWebhookContext(ctx context.Context, activity *api.Activity, meta *Metadata, updater *store.UserMessage) (webhook.Context, error) {
var webhookCtx webhook.Context
var webhookTaskResult *webhook.TaskResult
+
+ setting, err := m.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return webhookCtx, errors.Wrapf(err, "failed to get workspace setting")
+ }
+
level := webhook.WebhookInfo
title := ""
- link := fmt.Sprintf("%s/issue/%s-%d", m.profile.ExternalURL, slug.Make(meta.Issue.Title), meta.Issue.UID)
+ link := fmt.Sprintf("%s/issue/%s-%d", setting.ExternalUrl, slug.Make(meta.Issue.Title), meta.Issue.UID)
switch activity.Type {
case api.ActivityIssueCreate:
title = fmt.Sprintf("Issue created - %s", meta.Issue.Title)
diff --git a/backend/component/config/profile.go b/backend/component/config/profile.go
index 113a9c17a0..54a7b12728 100644
--- a/backend/component/config/profile.go
+++ b/backend/component/config/profile.go
@@ -37,8 +37,6 @@ type Profile struct {
Debug bool
// DemoName specifies the demo name. Empty string means no demo.
DemoName string
- // DisallowSignup will disallow the sign up, users can only be invited by the owner.
- DisallowSignup bool
// AppRunnerInterval is the interval for application runner.
AppRunnerInterval time.Duration
// BackupRunnerInterval is the interval for backup runner.
diff --git a/backend/legacyapi/setting.go b/backend/legacyapi/setting.go
index 14bfde0a1f..2fe2b43679 100644
--- a/backend/legacyapi/setting.go
+++ b/backend/legacyapi/setting.go
@@ -14,6 +14,8 @@ const (
SettingBrandingLogo SettingName = "bb.branding.logo"
// SettingWorkspaceID is the setting name for workspace identifier.
SettingWorkspaceID SettingName = "bb.workspace.id"
+ // SettingWorkspaceGeneral is the setting name for workspace general settings.
+ SettingWorkspaceGeneral SettingName = "bb.workspace.general"
// SettingEnterpriseLicense is the setting name for enterprise license.
SettingEnterpriseLicense SettingName = "bb.enterprise.license"
// SettingEnterpriseTrial is the setting name for free trial.
diff --git a/backend/runner/apprun/runner.go b/backend/runner/apprun/runner.go
index 3acd2d9c56..1c59834ff9 100644
--- a/backend/runner/apprun/runner.go
+++ b/backend/runner/apprun/runner.go
@@ -499,6 +499,11 @@ func (r *Runner) createExternalApproval(ctx context.Context, issue *store.IssueM
taskList[i].Statement = statement
}
+ setting, err := r.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return errors.Wrapf(err, "failed to get workspace setting")
+ }
+
instanceCode, err := r.p.CreateExternalApproval(ctx,
feishu.TokenCtx{
AppID: settingValue.AppID,
@@ -507,7 +512,7 @@ func (r *Runner) createExternalApproval(ctx context.Context, issue *store.IssueM
feishu.Content{
Issue: fmt.Sprintf("#%d %s", issue.UID, issue.Title),
Stage: stage.Name,
- Link: fmt.Sprintf("%s/issue/%s-%d", r.profile.ExternalURL, slug.Make(issue.Title), issue.UID),
+ Link: fmt.Sprintf("%s/issue/%s-%d", setting.ExternalUrl, slug.Make(issue.Title), issue.UID),
TaskList: taskList,
},
settingValue.ExternalApproval.ApprovalDefinitionID,
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index f62657842d..03d445e67d 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -292,7 +292,7 @@ func setMigrationIDAndEndBinlogCoordinate(ctx context.Context, driver db.Driver,
return updatedTask, nil
}
-func postMigration(ctx context.Context, stores *store.Store, activityManager *activity.Manager, license enterpriseAPI.LicenseService, profile config.Profile, task *store.TaskMessage, vcsPushEvent *vcsPlugin.PushEvent, mi *db.MigrationInfo, migrationID string, schema string) (bool, *api.TaskRunResultPayload, error) {
+func postMigration(ctx context.Context, stores *store.Store, activityManager *activity.Manager, license enterpriseAPI.LicenseService, task *store.TaskMessage, vcsPushEvent *vcsPlugin.PushEvent, mi *db.MigrationInfo, migrationID string, schema string) (bool, *api.TaskRunResultPayload, error) {
instance, err := stores.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})
if err != nil {
return true, nil, err
@@ -372,7 +372,12 @@ func postMigration(ctx context.Context, stores *store.Store, activityManager *ac
bytebaseURL := ""
if issue != nil {
- bytebaseURL = fmt.Sprintf("%s/issue/%s-%d?stage=%d", profile.ExternalURL, slug.Make(issue.Title), issue.UID, task.StageID)
+ setting, err := stores.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return true, nil, errors.Wrapf(err, "failed to get workspace setting")
+ }
+
+ bytebaseURL = fmt.Sprintf("%s/issue/%s-%d?stage=%d", setting.ExternalUrl, slug.Make(issue.Title), issue.UID, task.StageID)
}
commitID, err := writeBackLatestSchema(ctx, stores, repo, vcsPushEvent, mi, writebackBranch, latestSchemaFile, schema, bytebaseURL)
@@ -509,7 +514,7 @@ func runMigration(ctx context.Context, store *store.Store, dbFactory *dbfactory.
if err != nil {
return true, nil, err
}
- return postMigration(ctx, store, activityManager, license, profile, task, vcsPushEvent, mi, migrationID, schema)
+ return postMigration(ctx, store, activityManager, license, task, vcsPushEvent, mi, migrationID, schema)
}
// Writes back the latest schema to the repository after migration.
diff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
index fda55e5105..15912ea489 100644
--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
@@ -184,7 +184,7 @@ func cutover(ctx context.Context, stores *store.Store, dbFactory *dbfactory.DBFa
return true, nil, err
}
- return postMigration(ctx, stores, activityManager, license, profile, task, vcsPushEvent, mi, migrationID, schema)
+ return postMigration(ctx, stores, activityManager, license, task, vcsPushEvent, mi, migrationID, schema)
}
func waitForCutover(ctx context.Context, migrationContext *base.MigrationContext) bool {
diff --git a/backend/server/actuator.go b/backend/server/actuator.go
index d56627b78b..eb33bc5325 100644
--- a/backend/server/actuator.go
+++ b/backend/server/actuator.go
@@ -13,13 +13,18 @@ func (s *Server) registerActuatorRoutes(g *echo.Group) {
g.GET("/actuator/info", func(c echo.Context) error {
ctx := c.Request().Context()
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
serverInfo := api.ServerInfo{
Version: s.profile.Version,
GitCommit: s.profile.GitCommit,
Readonly: s.profile.Readonly,
DemoName: s.profile.DemoName,
- ExternalURL: s.profile.ExternalURL,
- DisallowSignup: s.profile.DisallowSignup,
+ ExternalURL: setting.ExternalUrl,
+ DisallowSignup: setting.DisallowSignup,
}
findRole := api.Owner
diff --git a/backend/server/auth.go b/backend/server/auth.go
index 67124f42e5..41c81c5969 100644
--- a/backend/server/auth.go
+++ b/backend/server/auth.go
@@ -94,6 +94,11 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("vcs do not exist, name: %v, ID: %v", login.Name, login.Name)).SetInternal(err)
}
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
// Exchange OAuth Token
oauthToken, err := vcs.Get(vcsFound.Type, vcs.ProviderConfig{}).ExchangeOAuthToken(
ctx,
@@ -102,7 +107,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
ClientID: vcsFound.ApplicationID,
ClientSecret: vcsFound.Secret,
Code: login.Code,
- RedirectURL: fmt.Sprintf("%s/oauth/callback", s.profile.ExternalURL),
+ RedirectURL: fmt.Sprintf("%s/oauth/callback", setting.ExternalUrl),
},
)
if err != nil {
diff --git a/backend/server/oauth.go b/backend/server/oauth.go
index 96deb7ae3c..515da9f26d 100644
--- a/backend/server/oauth.go
+++ b/backend/server/oauth.go
@@ -67,7 +67,13 @@ func (s *Server) registerOAuthRoutes(g *echo.Group) {
}
}
- oauthExchange.RedirectURL = fmt.Sprintf("%s/oauth/callback", oauthRedirectURL(s.profile.ExternalURL))
+ ctx := c.Request().Context()
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
+ oauthExchange.RedirectURL = fmt.Sprintf("%s/oauth/callback", oauthRedirectURL(setting.ExternalUrl))
oauthToken, err := vcsPlugin.Get(vcsType, vcsPlugin.ProviderConfig{}).
ExchangeOAuthToken(
c.Request().Context(),
@@ -75,7 +81,7 @@ func (s *Server) registerOAuthRoutes(g *echo.Group) {
oauthExchange,
)
if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, oauthErrorMessage(s.profile.ExternalURL)).SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, oauthErrorMessage(setting.ExternalUrl)).SetInternal(err)
}
resp := &api.OAuthToken{
diff --git a/backend/server/project.go b/backend/server/project.go
index f4b3c097a9..eaad04a2fe 100644
--- a/backend/server/project.go
+++ b/backend/server/project.go
@@ -246,6 +246,11 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project %d is deleted", projectID))
}
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
repositoryCreate := &api.RepositoryCreate{
ProjectID: projectID,
ProjectResourceID: project.ResourceID,
@@ -299,7 +304,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find repository with web url: %s", repositoryCreate.WebURL)).SetInternal(err)
}
- repositoryCreate.WebhookURLHost = s.profile.ExternalURL
+ repositoryCreate.WebhookURLHost = setting.ExternalUrl
// If we can find at least one repository with the same web url, we will use the same webhook instead of creating a new one.
if len(repositories) > 0 {
repo := repositories[0]
@@ -309,7 +314,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
} else {
// Bytebase needs to create a webbook in the connecting repository pointing back to the
// Bytebase address exposed at --external-url.
- if s.profile.ExternalURL == common.ExternalURLPlaceholder {
+ if setting.ExternalUrl == common.ExternalURLPlaceholder {
return echo.NewHTTPError(http.StatusBadRequest, "Bytebase must start with --external-url to configure GitOps workflow")
}
@@ -320,7 +325,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
}
repositoryCreate.WebhookSecretToken = secretToken
- webhookID, err := s.createVCSWebhook(ctx, vcs.Type, repositoryCreate.WebhookEndpointID, secretToken, repositoryCreate.AccessToken, vcs.InstanceURL, repositoryCreate.ExternalID)
+ webhookID, err := createVCSWebhook(ctx, vcs.Type, repositoryCreate.WebhookEndpointID, secretToken, repositoryCreate.AccessToken, vcs.InstanceURL, repositoryCreate.ExternalID, setting.ExternalUrl)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create webhook for project ID: %v", repositoryCreate.ProjectID)).SetInternal(err)
}
@@ -957,6 +962,11 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
}
func (s *Server) setupVCSSQLReviewCI(ctx context.Context, repository *api.Repository) (*vcsPlugin.PullRequest, error) {
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return nil, err
+ }
+
branch, err := s.setupVCSSQLReviewBranch(ctx, repository)
if err != nil {
return nil, err
@@ -979,7 +989,7 @@ func (s *Server) setupVCSSQLReviewCI(ctx context.Context, repository *api.Reposi
return nil, err
}
- sqlReviewEndpoint := fmt.Sprintf("%s/hook/sql-review/%s", s.profile.ExternalURL, repository.WebhookEndpointID)
+ sqlReviewEndpoint := fmt.Sprintf("%s/hook/sql-review/%s", setting.ExternalUrl, repository.WebhookEndpointID)
switch repository.VCS.Type {
case vcsPlugin.GitHub:
@@ -1237,14 +1247,14 @@ func (s *Server) createOrUpdateVCSSQLReviewFileForGitLab(
)
}
-func (s *Server) createVCSWebhook(ctx context.Context, vcsType vcsPlugin.Type, webhookEndpointID, secretToken, accessToken, instanceURL, externalRepoID string) (string, error) {
+func createVCSWebhook(ctx context.Context, vcsType vcsPlugin.Type, webhookEndpointID, secretToken, accessToken, instanceURL, externalRepoID, externalURL string) (string, error) {
// Create a new webhook and retrieve the created webhook ID
var webhookCreatePayload []byte
var err error
switch vcsType {
case vcsPlugin.GitLab:
webhookCreate := gitlab.WebhookCreate{
- URL: fmt.Sprintf("%s/hook/gitlab/%s", s.profile.ExternalURL, webhookEndpointID),
+ URL: fmt.Sprintf("%s/hook/gitlab/%s", externalURL, webhookEndpointID),
SecretToken: secretToken,
PushEvents: true,
EnableSSLVerification: false, // TODO(tianzhou): This is set to false, be lax to not enable_ssl_verification
@@ -1256,7 +1266,7 @@ func (s *Server) createVCSWebhook(ctx context.Context, vcsType vcsPlugin.Type, w
case vcsPlugin.GitHub:
webhookPost := github.WebhookCreateOrUpdate{
Config: github.WebhookConfig{
- URL: fmt.Sprintf("%s/hook/github/%s", s.profile.ExternalURL, webhookEndpointID),
+ URL: fmt.Sprintf("%s/hook/github/%s", externalURL, webhookEndpointID),
ContentType: "json",
Secret: secretToken,
InsecureSSL: 1, // TODO: Allow user to specify this value through api.RepositoryCreate
diff --git a/backend/server/project_webhook.go b/backend/server/project_webhook.go
index f20f45b37c..3aad505c57 100644
--- a/backend/server/project_webhook.go
+++ b/backend/server/project_webhook.go
@@ -187,6 +187,11 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project webhook ID not found: %d", id))
}
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
result := &api.ProjectWebhookTestResult{}
err = webhookPlugin.Post(
webhook.Type,
@@ -196,7 +201,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
ActivityType: string(api.ActivityIssueCreate),
Title: fmt.Sprintf("Test webhook %q", webhook.Name),
Description: "This is a test",
- Link: fmt.Sprintf("%s/project/%s/webhook/%s", s.profile.ExternalURL, getProjectSlug(project), api.ProjectWebhookSlug(webhook)),
+ Link: fmt.Sprintf("%s/project/%s/webhook/%s", setting.ExternalUrl, getProjectSlug(project), api.ProjectWebhookSlug(webhook)),
CreatorID: api.SystemBotID,
CreatorName: "Bytebase",
CreatorEmail: "[email protected]",
diff --git a/backend/server/server.go b/backend/server/server.go
index fa7dd54e6a..2fe34990b7 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -69,6 +69,7 @@ import (
"github.com/bytebase/bytebase/backend/runner/taskrun"
"github.com/bytebase/bytebase/backend/store"
_ "github.com/bytebase/bytebase/docs/openapi" // initial the swagger doc
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
// Register clickhouse driver.
_ "github.com/bytebase/bytebase/backend/plugin/db/clickhouse"
@@ -209,11 +210,9 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
log.Info(fmt.Sprintf("mode=%s", profile.Mode))
log.Info(fmt.Sprintf("dataDir=%s", profile.DataDir))
log.Info(fmt.Sprintf("resourceDir=%s", profile.ResourceDir))
- log.Info(fmt.Sprintf("externalURL=%s", profile.ExternalURL))
log.Info(fmt.Sprintf("readonly=%t", profile.Readonly))
log.Info(fmt.Sprintf("debug=%t", profile.Debug))
log.Info(fmt.Sprintf("demoName=%s", profile.DemoName))
- log.Info(fmt.Sprintf("disallowSignup=%t", profile.DisallowSignup))
log.Info(fmt.Sprintf("backupStorageBackend=%s", profile.BackupStorageBackend))
log.Info(fmt.Sprintf("backupBucket=%s", profile.BackupBucket))
log.Info(fmt.Sprintf("backupRegion=%s", profile.BackupRegion))
@@ -298,14 +297,14 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
// Cache the license.
s.licenseService.LoadSubscription(ctx)
- config, err := getInitSetting(ctx, storeInstance)
+ config, err := s.getInitSetting(ctx, storeInstance)
if err != nil {
return nil, errors.Wrap(err, "failed to init config")
}
s.secret = config.secret
s.workspaceID = config.workspaceID
- s.ActivityManager = activity.NewManager(storeInstance, profile)
+ s.ActivityManager = activity.NewManager(storeInstance)
s.dbFactory = dbfactory.New(s.mysqlBinDir, s.mongoBinDir, s.pgBinDir, profile.DataDir, s.secret)
e := echo.New()
e.Debug = profile.Debug
@@ -477,7 +476,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
v1pb.RegisterDatabaseServiceServer(s.grpcServer, v1.NewDatabaseService(s.store, s.BackupRunner))
v1pb.RegisterInstanceRoleServiceServer(s.grpcServer, v1.NewInstanceRoleService(s.store, s.dbFactory))
v1pb.RegisterOrgPolicyServiceServer(s.grpcServer, v1.NewOrgPolicyService(s.store, s.licenseService))
- v1pb.RegisterIdentityProviderServiceServer(s.grpcServer, v1.NewIdentityProviderService(s.store, s.licenseService, &profile))
+ v1pb.RegisterIdentityProviderServiceServer(s.grpcServer, v1.NewIdentityProviderService(s.store, s.licenseService))
v1pb.RegisterSettingServiceServer(s.grpcServer, v1.NewSettingService(s.store))
v1pb.RegisterAnomalyServiceServer(s.grpcServer, v1.NewAnomalyService(s.store))
reflection.Register(s.grpcServer)
@@ -584,7 +583,7 @@ type workspaceConfig struct {
workspaceID string
}
-func getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConfig, error) {
+func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConfig, error) {
// secretLength is the length for the secret used to sign the JWT auto token.
const secretLength = 32
@@ -652,6 +651,22 @@ func getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConf
return nil, err
}
+ // initial workspace general setting
+ bytes, err := json.Marshal(storepb.WorkspaceGeneralSettingPayload{
+ ExternalUrl: s.profile.ExternalURL,
+ DisallowSignup: false,
+ })
+ if err != nil {
+ return nil, err
+ }
+ if _, _, err := datastore.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
+ Name: api.SettingWorkspaceGeneral,
+ Value: string(bytes),
+ Description: "Workspace general settings",
+ }, api.SystemBotID); err != nil {
+ return nil, err
+ }
+
return conf, nil
}
diff --git a/backend/server/setting.go b/backend/server/setting.go
index 9e7a5cb3e0..cf97861da0 100644
--- a/backend/server/setting.go
+++ b/backend/server/setting.go
@@ -11,6 +11,8 @@ import (
"github.com/bytebase/bytebase/backend/common"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/app/feishu"
+ "github.com/bytebase/bytebase/backend/utils"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
// Some settings contain secret info so we only return settings that are needed by the client.
@@ -18,6 +20,7 @@ var whitelistSettings = []api.SettingName{
api.SettingBrandingLogo,
api.SettingAppIM,
api.SettingWatermark,
+ api.SettingWorkspaceGeneral,
}
func (s *Server) registerSettingRoutes(g *echo.Group) {
@@ -61,6 +64,23 @@ func (s *Server) registerSettingRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed update setting request").SetInternal(err)
}
+ if settingPatch.Name == api.SettingWorkspaceGeneral {
+ payload := new(storepb.WorkspaceGeneralSettingPayload)
+ if err := json.Unmarshal([]byte(settingPatch.Value), payload); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal setting value").SetInternal(err)
+ }
+ externalURL, err := utils.NormalizeExternalURL(payload.ExternalUrl)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Invalid external url").SetInternal(err)
+ }
+ payload.ExternalUrl = externalURL
+ bytes, err := json.Marshal(payload)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal setting value").SetInternal(err)
+ }
+ settingPatch.Value = string(bytes)
+ }
+
if settingPatch.Name == api.SettingAppIM {
var value api.SettingAppIMValue
if err := json.Unmarshal([]byte(settingPatch.Value), &value); err != nil {
diff --git a/backend/server/webhook.go b/backend/server/webhook.go
index 86cf46a8cd..59b081ff03 100644
--- a/backend/server/webhook.go
+++ b/backend/server/webhook.go
@@ -148,6 +148,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
// id is the webhookEndpointID in repository
// This endpoint is generated and injected into GitHub action & GitLab CI during the VCS setup.
g.POST("/sql-review/:id", func(c echo.Context) error {
+ ctx := c.Request().Context()
body, err := io.ReadAll(c.Request().Body)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Failed to read SQL review request").SetInternal(err)
@@ -157,6 +158,11 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
zap.String("request", string(body)),
)
+ setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find workspace setting").SetInternal(err)
+ }
+
var request api.VCSSQLReviewRequest
if err := json.Unmarshal(body, &request); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed SQL review request").SetInternal(err)
@@ -187,7 +193,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
return c.Request().Header.Get("X-SQL-Review-Token") == repo.WebhookSecretToken, nil
}
- ctx := c.Request().Context()
+
repositoryList, err := s.filterRepository(ctx, c.Param("id"), request.RepositoryID, filter)
if err != nil {
return err
@@ -240,7 +246,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
wg.Add(1)
go func(file fileInfo) {
defer wg.Done()
- adviceList, err := s.sqlAdviceForFile(ctx, file)
+ adviceList, err := s.sqlAdviceForFile(ctx, file, setting.ExternalUrl)
if err != nil {
log.Debug(
"Failed to take SQL review for file",
@@ -280,6 +286,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
func (s *Server) sqlAdviceForFile(
ctx context.Context,
fileInfo fileInfo,
+ externalURL string,
) ([]advisor.Advice, error) {
log.Debug("Processing file",
zap.String("file", fileInfo.item.FileName),
@@ -398,7 +405,7 @@ func (s *Server) sqlAdviceForFile(
Status: advisor.Warn,
Code: advisor.NotFound,
Title: "SQL review policy not found",
- Content: fmt.Sprintf("You can configure the SQL review policy on %s/setting/sql-review", s.profile.ExternalURL),
+ Content: fmt.Sprintf("You can configure the SQL review policy on %s/setting/sql-review", externalURL),
Line: 1,
},
}, nil
diff --git a/backend/store/setting.go b/backend/store/setting.go
index b5b298ad27..28e43e2586 100644
--- a/backend/store/setting.go
+++ b/backend/store/setting.go
@@ -3,6 +3,7 @@ package store
import (
"context"
"database/sql"
+ "encoding/json"
"fmt"
"strings"
@@ -10,6 +11,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
api "github.com/bytebase/bytebase/backend/legacyapi"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
// FindSetting finds a list of Setting instances.
@@ -39,6 +41,26 @@ func (s *Store) GetSetting(ctx context.Context, find *api.SettingFind) (*api.Set
return setting.toAPISetting(), nil
}
+// GetWorkspaceGeneralSetting gets the workspace general setting payload.
+func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.WorkspaceGeneralSettingPayload, error) {
+ settingName := api.SettingWorkspaceGeneral
+ setting, err := s.GetSetting(ctx, &api.SettingFind{
+ Name: &settingName,
+ })
+ if err != nil {
+ return nil, err
+ }
+ if setting == nil {
+ return nil, errors.Errorf("cannot find setting %v", settingName)
+ }
+
+ payload := new(storepb.WorkspaceGeneralSettingPayload)
+ if err := json.Unmarshal([]byte(setting.Value), payload); err != nil {
+ return nil, err
+ }
+ return payload, nil
+}
+
// PatchSetting patches an instance of Setting.
func (s *Store) PatchSetting(ctx context.Context, patch *api.SettingPatch) (*api.Setting, error) {
setting, err := s.UpsertSettingV2(ctx, &SetSettingMessage{
diff --git a/backend/utils/utils.go b/backend/utils/utils.go
index b51fd7d0b2..9ddf960c06 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -463,3 +463,30 @@ func passCheck(taskCheckRunList []*store.TaskCheckRunMessage, checkType api.Task
return true, nil
}
+
+// NormalizeExternalURL will format the external url.
+func NormalizeExternalURL(url string) (string, error) {
+ r := strings.TrimSpace(url)
+ r = strings.TrimSuffix(r, "/")
+ if !common.HasPrefixes(r, "http://", "https://") {
+ return "", errors.Errorf("%s must start with http:// or https://", url)
+ }
+ parts := strings.Split(r, ":")
+ if len(parts) > 3 {
+ return "", errors.Errorf("%s malformed", url)
+ }
+ if len(parts) == 3 {
+ port, err := strconv.Atoi(parts[2])
+ if err != nil {
+ return "", errors.Errorf("%s has non integer port", url)
+ }
+ // The external URL is used as the redirectURL in the get token process of OAuth, and the
+ // RedirectURL needs to be consistent with the RedirectURL in the get code process.
+ // The frontend gets it through window.location.origin in the get code
+ // process, so port 80/443 need to be cropped.
+ if port == 80 || port == 443 {
+ r = strings.Join(parts[0:2], ":")
+ }
+ }
+ return r, nil
+}
diff --git a/backend/utils/utils_test.go b/backend/utils/utils_test.go
index 09bff6fa70..ea55af80d9 100644
--- a/backend/utils/utils_test.go
+++ b/backend/utils/utils_test.go
@@ -364,3 +364,70 @@ func TestMergeTaskCreateLists(t *testing.T) {
})
}
}
+
+func TestNormalizeExternalURL(t *testing.T) {
+ tests := []struct {
+ url string
+ want string
+ wantErr bool
+ }{
+ {
+ url: "http://localhost:3000",
+ want: "http://localhost:3000",
+ wantErr: false,
+ },
+ {
+ url: "https://localhost:3000",
+ want: "https://localhost:3000",
+ wantErr: false,
+ },
+ {
+ url: "https://localhost",
+ want: "https://localhost",
+ wantErr: false,
+ },
+ {
+ url: "http://localhost:80",
+ want: "http://localhost",
+ wantErr: false,
+ },
+ {
+ url: "https://localhost:443",
+ want: "https://localhost",
+ wantErr: false,
+ },
+ {
+ url: " https://localhost:3000/ ",
+ want: "https://localhost:3000",
+ wantErr: false,
+ },
+ // Missing http:// or https://
+ {
+ url: "localhost:3000",
+ want: "",
+ wantErr: true,
+ },
+ // Invalid port
+ {
+ url: "http://localhost:xxx",
+ want: "",
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.url, func(t *testing.T) {
+ g, err := NormalizeExternalURL(tt.url)
+ if err != nil {
+ if !tt.wantErr {
+ t.Errorf("expect no error, got %s", err.Error())
+ }
+ } else {
+ if tt.wantErr {
+ t.Errorf("expect error")
+ } else if tt.want != g {
+ t.Errorf("expect %s, got %s", tt.want, g)
+ }
+ }
+ })
+ }
+}
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 78cf0f632a..6979bbf97e 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -23,6 +23,9 @@
- [IdentityProviderType](#bytebase-store-IdentityProviderType)
+- [store/setting.proto](#store_setting-proto)
+ - [WorkspaceGeneralSettingPayload](#bytebase-store-WorkspaceGeneralSettingPayload)
+
- [Scalar Value Types](#scalar-value-types)
@@ -347,6 +350,40 @@ OIDCIdentityProviderConfig is the structure for OIDC identity provider config.
+<a name="store_setting-proto"></a>
+<p align="right"><a href="#top">Top</a></p>
+
+## store/setting.proto
+
+
+
+<a name="bytebase-store-WorkspaceGeneralSettingPayload"></a>
+
+### WorkspaceGeneralSettingPayload
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| external_url | [string](#string) | | The URL user visits Bytebase.
+
+The external URL is used for: 1. Constructing the correct callback URL when configuring the VCS provider. The callback URL points to the frontend. 2. Creating the correct webhook endpoint when configuring the project GitOps workflow. The webhook endpoint points to the backend. |
+| disallow_signup | [bool](#bool) | | Disallow self-service signup, users can only be invited by the owner. |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
## Scalar Value Types
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
diff --git a/proto/generated-go/store/setting.pb.go b/proto/generated-go/store/setting.pb.go
new file mode 100644
index 0000000000..9762e32578
--- /dev/null
+++ b/proto/generated-go/store/setting.pb.go
@@ -0,0 +1,162 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// protoc-gen-go v1.28.1
+// protoc (unknown)
+// source: store/setting.proto
+
+package store
+
+import (
+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ reflect "reflect"
+ sync "sync"
+)
+
+const (
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type WorkspaceGeneralSettingPayload struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // The URL user visits Bytebase.
+ //
+ // The external URL is used for:
+ // 1. Constructing the correct callback URL when configuring the VCS provider. The callback URL points to the frontend.
+ // 2. Creating the correct webhook endpoint when configuring the project GitOps workflow. The webhook endpoint points to the backend.
+ ExternalUrl string `protobuf:"bytes,1,opt,name=external_url,json=externalUrl,proto3" json:"external_url,omitempty"`
+ // Disallow self-service signup, users can only be invited by the owner.
+ DisallowSignup bool `protobuf:"varint,2,opt,name=disallow_signup,json=disallowSignup,proto3" json:"disallow_signup,omitempty"`
+}
+
+func (x *WorkspaceGeneralSettingPayload) Reset() {
+ *x = WorkspaceGeneralSettingPayload{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_store_setting_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *WorkspaceGeneralSettingPayload) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*WorkspaceGeneralSettingPayload) ProtoMessage() {}
+
+func (x *WorkspaceGeneralSettingPayload) ProtoReflect() protoreflect.Message {
+ mi := &file_store_setting_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use WorkspaceGeneralSettingPayload.ProtoReflect.Descriptor instead.
+func (*WorkspaceGeneralSettingPayload) Descriptor() ([]byte, []int) {
+ return file_store_setting_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *WorkspaceGeneralSettingPayload) GetExternalUrl() string {
+ if x != nil {
+ return x.ExternalUrl
+ }
+ return ""
+}
+
+func (x *WorkspaceGeneralSettingPayload) GetDisallowSignup() bool {
+ if x != nil {
+ return x.DisallowSignup
+ }
+ return false
+}
+
+var File_store_setting_proto protoreflect.FileDescriptor
+
+var file_store_setting_proto_rawDesc = []byte{
+ 0x0a, 0x13, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x2e,
+ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,
+ 0x73, 0x74, 0x6f, 0x72, 0x65, 0x22, 0x6c, 0x0a, 0x1e, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61,
+ 0x63, 0x65, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67,
+ 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x78, 0x74, 0x65, 0x72,
+ 0x6e, 0x61, 0x6c, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x65,
+ 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x55, 0x72, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x69,
+ 0x73, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x75, 0x70, 0x18, 0x02, 0x20,
+ 0x01, 0x28, 0x08, 0x52, 0x0e, 0x64, 0x69, 0x73, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x69, 0x67,
+ 0x6e, 0x75, 0x70, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64,
+ 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+ 0x33,
+}
+
+var (
+ file_store_setting_proto_rawDescOnce sync.Once
+ file_store_setting_proto_rawDescData = file_store_setting_proto_rawDesc
+)
+
+func file_store_setting_proto_rawDescGZIP() []byte {
+ file_store_setting_proto_rawDescOnce.Do(func() {
+ file_store_setting_proto_rawDescData = protoimpl.X.CompressGZIP(file_store_setting_proto_rawDescData)
+ })
+ return file_store_setting_proto_rawDescData
+}
+
+var file_store_setting_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
+var file_store_setting_proto_goTypes = []interface{}{
+ (*WorkspaceGeneralSettingPayload)(nil), // 0: bytebase.store.WorkspaceGeneralSettingPayload
+}
+var file_store_setting_proto_depIdxs = []int32{
+ 0, // [0:0] is the sub-list for method output_type
+ 0, // [0:0] 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
+}
+
+func init() { file_store_setting_proto_init() }
+func file_store_setting_proto_init() {
+ if File_store_setting_proto != nil {
+ return
+ }
+ if !protoimpl.UnsafeEnabled {
+ file_store_setting_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*WorkspaceGeneralSettingPayload); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ }
+ type x struct{}
+ out := protoimpl.TypeBuilder{
+ File: protoimpl.DescBuilder{
+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+ RawDescriptor: file_store_setting_proto_rawDesc,
+ NumEnums: 0,
+ NumMessages: 1,
+ NumExtensions: 0,
+ NumServices: 0,
+ },
+ GoTypes: file_store_setting_proto_goTypes,
+ DependencyIndexes: file_store_setting_proto_depIdxs,
+ MessageInfos: file_store_setting_proto_msgTypes,
+ }.Build()
+ File_store_setting_proto = out.File
+ file_store_setting_proto_rawDesc = nil
+ file_store_setting_proto_goTypes = nil
+ file_store_setting_proto_depIdxs = nil
+}
diff --git a/proto/store/setting.proto b/proto/store/setting.proto
new file mode 100644
index 0000000000..378c380b11
--- /dev/null
+++ b/proto/store/setting.proto
@@ -0,0 +1,17 @@
+syntax = "proto3";
+
+package bytebase.store;
+
+option go_package = "generated-go/store";
+
+message WorkspaceGeneralSettingPayload {
+ // The URL user visits Bytebase.
+ //
+ // The external URL is used for:
+ // 1. Constructing the correct callback URL when configuring the VCS provider. The callback URL points to the frontend.
+ // 2. Creating the correct webhook endpoint when configuring the project GitOps workflow. The webhook endpoint points to the backend.
+ string external_url = 1;
+
+ // Disallow self-service signup, users can only be invited by the owner.
+ bool disallow_signup = 2;
+}