Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: refresh expired license (#5546)
ecmadaoe56e6ea95e5b
diff --git a/backend/enterprise/api/subscription.go b/backend/enterprise/api/subscription.goindex 6dab5ee7e7..8669d2ee2b 100644--- a/backend/enterprise/api/subscription.go+++ b/backend/enterprise/api/subscription.go@@ -1,6 +1,10 @@package api-import api "github.com/bytebase/bytebase/backend/legacyapi"+import (+ "time"++ api "github.com/bytebase/bytebase/backend/legacyapi"+)// SubscriptionPatch is the API message for update the subscription.type SubscriptionPatch struct {@@ -18,3 +22,11 @@ type Subscription struct {OrgID string `jsonapi:"attr,orgId"`OrgName string `jsonapi:"attr,orgName"`}++// IsExpired returns if the subscription is expired.+func (s *Subscription) IsExpired() bool {+ if s.Plan == api.FREE || s.ExpiresTs < 0 {+ return false+ }+ return time.Unix(s.ExpiresTs, 0).Before(time.Now())+}diff --git a/backend/enterprise/service/license.go b/backend/enterprise/service/license.goindex 6fec5eaddb..adf7e26e0b 100644--- a/backend/enterprise/service/license.go+++ b/backend/enterprise/service/license.go@@ -71,6 +71,10 @@ func (s *LicenseService) StoreLicense(ctx context.Context, patch *enterpriseAPI.// LoadSubscription will load subscription.func (s *LicenseService) LoadSubscription(ctx context.Context) enterpriseAPI.Subscription {+ if s.cachedSubscription != nil && s.cachedSubscription.IsExpired() {+ // refresh expired subscription+ s.cachedSubscription = nil+ }if s.cachedSubscription != nil {return *s.cachedSubscription}@@ -173,6 +177,13 @@ func (s *LicenseService) loadLicense(ctx context.Context) *enterpriseAPI.Licenselog.Debug("failed to fetch license", zap.Error(err))}}+ if license == nil {+ return nil+ }+ if err := license.Valid(); err != nil {+ log.Debug("license is invalid", zap.Error(err))+ return nil+ }return license}@@ -260,10 +271,6 @@ func (s *LicenseService) parseClaims(claims *Claims) (*enterpriseAPI.License, erOrgName: claims.OrgName,}- if err := license.Valid(); err != nil {- return nil, common.Wrap(err, common.Invalid)- }-return license, nil}diff --git a/backend/server/server.go b/backend/server/server.goindex aa7c018b91..c53b06b46e 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -669,7 +669,7 @@ func (s *Server) registerOpenAPIRoutes(e *echo.Echo, ce *casbin.Enforcer, prof c// initMetricReporter will initial the metric scheduler.func (s *Server) initMetricReporter() {- enabled := s.profile.Mode == common.ReleaseModeProd && s.profile.DemoName != "" && !s.profile.DisableMetric+ enabled := s.profile.Mode == common.ReleaseModeProd && s.profile.DemoName == "" && !s.profile.DisableMetricmetricReporter := metricreport.NewReporter(s.store, s.licenseService, s.profile, enabled)metricReporter.Register(metric.InstanceCountMetricName, metricCollector.NewInstanceCountCollector(s.store))metricReporter.Register(metric.IssueCountMetricName, metricCollector.NewIssueCountCollector(s.store))diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.tsindex 7d59e47f63..7a5b2ad9e4 100644--- a/frontend/src/store/modules/subscription.ts+++ b/frontend/src/store/modules/subscription.ts@@ -117,7 +117,7 @@ export const useSubscriptionStore = defineStore("subscription", {for (let i = 0; i < matrix.length; i++) {if (matrix[i]) {- return i as PlanType;+ return (i + 1) as PlanType;}}return PlanType.FREE;