Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove local trial implementation (#9765)
Tianzhou (天舟)11c909ceff3a
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.goindex d71e04ad86..57c046965e 100644--- a/backend/api/v1/setting_service.go+++ b/backend/api/v1/setting_service.go@@ -64,7 +64,6 @@ var whitelistSettings = []api.SettingName{api.SettingWorkspaceMailDelivery,api.SettingWorkspaceProfile,api.SettingWorkspaceExternalApproval,- api.SettingEnterpriseTrial,api.SettingSchemaTemplate,api.SettingDataClassification,api.SettingSemanticTypes,@@ -378,8 +377,6 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettinreturn nil, status.Errorf(codes.Internal, "failed to marshal external approval setting, error: %v", err)}storeSettingValue = string(bytes)- case api.SettingEnterpriseTrial:- return nil, status.Errorf(codes.InvalidArgument, "cannot set setting %s", settingName)case api.SettingSchemaTemplate:schemaTemplateSetting := request.Setting.Value.GetSchemaTemplateSettingValue()if schemaTemplateSetting == nil {diff --git a/backend/api/v1/subscription_service.go b/backend/api/v1/subscription_service.goindex e18fdcc972..ed7164a838 100644--- a/backend/api/v1/subscription_service.go+++ b/backend/api/v1/subscription_service.go@@ -2,8 +2,6 @@ package v1import ("context"- "encoding/json"- "fmt""time""google.golang.org/grpc/codes"@@ -14,8 +12,6 @@ import ("github.com/bytebase/bytebase/backend/component/config"enterprise "github.com/bytebase/bytebase/backend/enterprise/api"api "github.com/bytebase/bytebase/backend/legacyapi"- metricapi "github.com/bytebase/bytebase/backend/metric"- "github.com/bytebase/bytebase/backend/plugin/metric""github.com/bytebase/bytebase/backend/runner/metricreport""github.com/bytebase/bytebase/backend/store"v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"@@ -69,13 +65,6 @@ func (*SubscriptionService) GetFeatureMatrix(_ context.Context, _ *v1pb.GetFeatu// UpdateSubscription updates the subscription license.func (s *SubscriptionService) UpdateSubscription(ctx context.Context, request *v1pb.UpdateSubscriptionRequest) (*v1pb.Subscription, error) {- // clear the trialing setting for dev test- if request.Patch.License == "" && s.profile.Mode == common.ReleaseModeDev {- if err := s.store.DeleteSettingV2(ctx, api.SettingEnterpriseTrial); err != nil {- return nil, status.Errorf(codes.Internal, "failed to delete the trialing license: %v", err.Error())- }- }-principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)if !ok {return nil, status.Errorf(codes.Internal, "principal ID not found")@@ -93,89 +82,6 @@ func (s *SubscriptionService) UpdateSubscription(ctx context.Context, request *vreturn s.loadSubscription(ctx)}-// TrialSubscription creates a trial subscription.-func (s *SubscriptionService) TrialSubscription(ctx context.Context, request *v1pb.TrialSubscriptionRequest) (*v1pb.Subscription, error) {- planType := api.FREE- switch request.Trial.Plan {- case v1pb.PlanType_TEAM:- planType = api.TEAM- case v1pb.PlanType_ENTERPRISE:- planType = api.ENTERPRISE- }-- workspaceID, err := s.store.GetWorkspaceID(ctx)- if err != nil {- return nil, status.Errorf(codes.Internal, err.Error())- }-- license := &enterprise.License{- InstanceCount: enterprise.InstanceLimitForTrial,- ExpiresTs: time.Now().AddDate(0, 0, enterprise.TrialDaysLimit).Unix(),- IssuedTs: time.Now().Unix(),- Plan: planType,- // the subject format for license should be {org id in hub}.{subscription id in hub}- // as we just need to simply generate the trialing license in console, we can use the workspace id instead.- Subject: fmt.Sprintf("%s.%s", workspaceID, ""),- Trialing: true,- OrgName: workspaceID,- }-- subscription := s.licenseService.LoadSubscription(ctx)- basePlan := subscription.Plan-- if license.Plan.Priority() <= subscription.Plan.Priority() {- return s.loadSubscription(ctx)- }-- if subscription.Trialing {- license.ExpiresTs = subscription.ExpiresTs- license.IssuedTs = subscription.StartedTs- }-- value, err := json.Marshal(license)- if err != nil {- return nil, status.Errorf(codes.Internal, err.Error())- }-- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)- if !ok {- return nil, status.Errorf(codes.Internal, "principal ID not found")- }- _, created, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{- Name: api.SettingEnterpriseTrial,- Value: string(value),- }, principalID)- if err != nil {- return nil, status.Errorf(codes.Internal, "failed to create license: %v", err.Error())- }- if !created {- return nil, status.Errorf(codes.InvalidArgument, "your trial already exists")- }-- // we need to override the SettingEnterpriseLicense with an empty value to get the valid free trial.- if err := s.licenseService.StoreLicense(ctx, &enterprise.SubscriptionPatch{- UpdaterID: principalID,- License: "",- }); err != nil {- return nil, status.Errorf(codes.Internal, "failed to remove license: %v", err.Error())- }-- s.licenseService.RefreshCache(ctx)- subscription = s.licenseService.LoadSubscription(ctx)- currentPlan := subscription.Plan- s.metricReporter.Report(ctx, &metric.Metric{- Name: metricapi.SubscriptionTrialMetricName,- Value: 1,- Labels: map[string]any{- "trial_plan": currentPlan.String(),- "from_plan": basePlan.String(),- "lark_notified": false,- },- })-- return s.loadSubscription(ctx)-}-func (s *SubscriptionService) loadSubscription(ctx context.Context) (*v1pb.Subscription, error) {sub := s.licenseService.LoadSubscription(ctx)diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.goindex 34e35af5ab..cd4136a546 100644--- a/backend/enterprise/plugin/hub/hub.go+++ b/backend/enterprise/plugin/hub/hub.go@@ -2,7 +2,6 @@ package hubimport ("context"- "encoding/json""log/slog""time"@@ -121,12 +120,6 @@ func (p *Provider) loadLicense(ctx context.Context) *enterprise.License {if err != nil {slog.Debug("failed to load enterprise license", log.BBError(err))}- if license == nil {- license, err = p.findTrialingLicense(ctx)- if err != nil {- slog.Debug("failed to load trialing license", log.BBError(err))- }- }if license == nil {license, err = p.fetchLicense(ctx)@@ -182,29 +175,6 @@ func (p *Provider) findEnterpriseLicense(ctx context.Context) (*enterprise.Licenreturn nil, nil}-func (p *Provider) findTrialingLicense(ctx context.Context) (*enterprise.License, error) {- settingName := api.SettingEnterpriseTrial- setting, err := p.store.GetSettingV2(ctx, &store.FindSettingMessage{- Name: &settingName,- })- if err != nil {- return nil, errors.Wrapf(err, "failed to load trial license from settings")- }- if setting != nil && setting.Value != "" {- var data enterprise.License- if err := json.Unmarshal([]byte(setting.Value), &data); err != nil {- return nil, errors.Wrapf(err, "failed to parse trial license")- }- data.InstanceCount = enterprise.InstanceLimitForTrial- if time.Now().AddDate(0, 0, -enterprise.TrialDaysLimit).Unix() >= setting.CreatedTs {- return nil, nil- }- return &data, nil- }-- return nil, nil-}-// parseClaims will valid and parse JWT claims to license instance.func (p *Provider) parseClaims(claim *claims) (*enterprise.License, error) {verifyIssuer := claim.VerifyIssuer(p.config.Issuer, true)diff --git a/backend/legacyapi/setting.go b/backend/legacyapi/setting.goindex 3a3d2e69e3..5805164459 100644--- a/backend/legacyapi/setting.go+++ b/backend/legacyapi/setting.go@@ -22,8 +22,6 @@ const (SettingWorkspaceExternalApproval SettingName = "bb.workspace.approval.external"// SettingEnterpriseLicense is the setting name for enterprise license.SettingEnterpriseLicense SettingName = "bb.enterprise.license"- // SettingEnterpriseTrial is the setting name for free trial.- SettingEnterpriseTrial SettingName = "bb.enterprise.trial"// SettingAppIM is the setting name for IM applications.SettingAppIM SettingName = "bb.app.im"// SettingWatermark is the setting name for watermark displaying.diff --git a/backend/tests/subscription.go b/backend/tests/subscription.goindex 03f3594476..0244ce9b5b 100644--- a/backend/tests/subscription.go+++ b/backend/tests/subscription.go@@ -9,11 +9,12 @@ import ()func (ctl *controller) setLicense(ctx context.Context) error {- return ctl.trialPlan(ctx, &v1pb.TrialSubscription{- InstanceCount: 100,- Plan: v1pb.PlanType_ENTERPRISE,- Days: 1,- })+ if _, err := ctl.subscriptionServiceClient.UpdateSubscription(ctx, &v1pb.UpdateSubscriptionRequest{+ Patch: &v1pb.PatchSubscription{License: "eyJhbGciOiJSUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJpbnN0YW5jZUNvdW50Ijo5OTksInRyaWFsaW5nIjpmYWxzZSwicGxhbiI6IkVOVEVSUFJJU0UiLCJvcmdOYW1lIjoiYmIiLCJhdWQiOiJiYi5saWNlbnNlIiwiZXhwIjo3OTc0OTc5MjAwLCJpYXQiOjE2NjM2Njc1NjEsImlzcyI6ImJ5dGViYXNlIiwic3ViIjoiMDAwMDEwMDAuIn0.JjYCMeAAMB9FlVeDFLdN3jvFcqtPsbEzaIm1YEDhUrfekthCbIOeX_DB2Bg2OUji3HSX5uDvG9AkK4Gtrc4gLMPI3D5mk3L-6wUKZ0L4REztS47LT4oxVhpqPQayYa9lKJB1YoHaqeMV4Z5FXeOXwuACoELznlwpT6pXo9xXm_I6QwQiO7-zD83XOTO4PRjByc-q3GKQu_64zJMIKiCW0I8a3GvrdSnO7jUuYU1KPmCuk0ZRq3I91m29LTo478BMST59HqCLj1GGuCKtR3SL_376XsZfUUM0iSAur5scg99zNGWRj-sUo05wbAadYx6V6TKaWrBUi_8_0RnJyP5gbA"},+ }); err != nil {+ return errors.Wrap(err, "failed to remove license")+ }+ return nil}func (ctl *controller) removeLicense(ctx context.Context) error {@@ -29,15 +30,6 @@ func (ctl *controller) getSubscription(ctx context.Context) (*v1pb.Subscription,return ctl.subscriptionServiceClient.GetSubscription(ctx, &v1pb.GetSubscriptionRequest{})}-func (ctl *controller) trialPlan(ctx context.Context, trial *v1pb.TrialSubscription) error {- if _, err := ctl.subscriptionServiceClient.TrialSubscription(ctx, &v1pb.TrialSubscriptionRequest{- Trial: trial,- }); err != nil {- return errors.Wrap(err, "failed to start trial")- }- return nil-}-func (ctl *controller) getWorkspaceID(ctx context.Context) (string, error) {resp, err := ctl.actuatorServiceClient.GetActuatorInfo(ctx, &v1pb.GetActuatorInfoRequest{})if err != nil {diff --git a/backend/tests/subscription_test.go b/backend/tests/subscription_test.goindex 3d542e37a6..d475b06ef9 100644--- a/backend/tests/subscription_test.go+++ b/backend/tests/subscription_test.go@@ -10,14 +10,6 @@ import (v1pb "github.com/bytebase/bytebase/proto/generated-go/v1")-type trial struct {- instanceCount int32- expectInstanceCount int32- plan v1pb.PlanType- expectPlan v1pb.PlanType- days int32-}-func TestSubscription(t *testing.T) {a := require.New(t)ctx := context.Background()@@ -35,29 +27,4 @@ func TestSubscription(t *testing.T) {subscription, err := ctl.getSubscription(ctx)a.NoError(err)a.Equal(v1pb.PlanType_FREE, subscription.Plan)-- trialList := []trial{- {- // Test trial the TEAM plan.- instanceCount: 10,- expectInstanceCount: 10,- plan: v1pb.PlanType_ENTERPRISE,- expectPlan: v1pb.PlanType_ENTERPRISE,- days: 7,- },- }-- for _, trial := range trialList {- err = ctl.trialPlan(ctx, &v1pb.TrialSubscription{- InstanceCount: trial.instanceCount,- Plan: trial.plan,- Days: trial.days,- })- a.NoError(err)-- subscription, err = ctl.getSubscription(ctx)- a.NoError(err)- a.Equal(trial.expectPlan, subscription.Plan)- a.Equal(trial.expectInstanceCount, subscription.InstanceCount)- }}diff --git a/proto/v1/subscription_service.proto b/proto/v1/subscription_service.protoindex 309ca094dc..bb4bb27203 100644--- a/proto/v1/subscription_service.proto+++ b/proto/v1/subscription_service.proto@@ -25,13 +25,6 @@ service SubscriptionService {};option (google.api.method_signature) = "patch";}- rpc TrialSubscription(TrialSubscriptionRequest) returns (Subscription) {- option (google.api.http) = {- post: "/v1/subscription/trial"- body: "trial"- };- option (google.api.method_signature) = "trial";- }}message GetSubscriptionRequest {}@@ -42,10 +35,6 @@ message UpdateSubscriptionRequest {PatchSubscription patch = 1;}-message TrialSubscriptionRequest {- TrialSubscription trial = 1;-}-enum PlanType {PLAN_TYPE_UNSPECIFIED = 0;@@ -60,14 +49,6 @@ message PatchSubscription {string license = 1;}-message TrialSubscription {- PlanType plan = 1;-- int32 days = 2;-- int32 instance_count = 4;-}-message Subscription {int32 instance_count = 2 [(google.api.field_behavior) = OUTPUT_ONLY];