Skip to content

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

refactor: refactor the license service (#9336)

ecmadao8709c44d9ac1
diff --git a/backend/enterprise/api/license.go b/backend/enterprise/api/license.go
index f0796e545c..ebbf3fad9a 100644
--- a/backend/enterprise/api/license.go
+++ b/backend/enterprise/api/license.go
@@ -62,7 +62,7 @@ type LicenseService interface {
// StoreLicense will store license into file.
StoreLicense(ctx context.Context, patch *SubscriptionPatch) error
// LoadSubscription will load subscription.
- LoadSubscription(ctx context.Context) Subscription
+ LoadSubscription(ctx context.Context) *Subscription
// IsFeatureEnabled returns whether a feature is enabled.
IsFeatureEnabled(feature api.FeatureType) error
// IsFeatureEnabledForInstance returns whether a feature is enabled for the instance.
diff --git a/backend/enterprise/plugin/aws/aws.go b/backend/enterprise/plugin/aws/aws.go
new file mode 100644
index 0000000000..9a24ce13e2
--- /dev/null
+++ b/backend/enterprise/plugin/aws/aws.go
@@ -0,0 +1,47 @@
+package aws
+
+import (
+ "context"
+
+ enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
+ "github.com/bytebase/bytebase/backend/enterprise/config"
+ "github.com/bytebase/bytebase/backend/enterprise/plugin"
+ api "github.com/bytebase/bytebase/backend/legacyapi"
+)
+
+var _ plugin.LicenseProvider = (*Provider)(nil)
+
+// Provider is the AWS license provider.
+type Provider struct {
+ config *config.Config
+}
+
+// NewProvider will create a new AWS license provider.
+func NewProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
+ config, err := config.NewConfig(providerConfig.Mode)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Provider{
+ config: config,
+ }, nil
+}
+
+// StoreLicense will store the hub license.
+func (*Provider) StoreLicense(_ context.Context, _ *enterprise.SubscriptionPatch) error {
+ return nil
+}
+
+// LoadSubscription will load the hub subscription.
+func (*Provider) LoadSubscription(_ context.Context) *enterprise.Subscription {
+ return &enterprise.Subscription{
+ InstanceCount: 0,
+ Plan: api.FREE,
+ }
+}
+
+// GetEffectivePlan gets the effective plan.
+func (*Provider) GetEffectivePlan(_ context.Context) api.PlanType {
+ return api.FREE
+}
diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.go
new file mode 100644
index 0000000000..6743f49ca2
--- /dev/null
+++ b/backend/enterprise/plugin/hub/hub.go
@@ -0,0 +1,258 @@
+package hub
+
+import (
+ "context"
+ "encoding/json"
+ "log/slog"
+ "time"
+
+ "github.com/golang-jwt/jwt/v4"
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/common/log"
+ enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
+ "github.com/bytebase/bytebase/backend/enterprise/config"
+ "github.com/bytebase/bytebase/backend/enterprise/plugin"
+ api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/store"
+)
+
+var _ plugin.LicenseProvider = (*Provider)(nil)
+
+// Provider is the Bytebase Hub license provider.
+type Provider struct {
+ config *config.Config
+ store *store.Store
+ remoteProvider *remoteLicenseProvider
+}
+
+// claims creates a struct that will be encoded to a JWT.
+// We add jwt.RegisteredClaims as an embedded type, to provide fields such as name.
+type claims struct {
+ InstanceCount int `json:"instanceCount"`
+ Trialing bool `json:"trialing"`
+ Plan string `json:"plan"`
+ OrgName string `json:"orgName"`
+ jwt.RegisteredClaims
+}
+
+// NewProvider will create a new hub license provider.
+func NewProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
+ config, err := config.NewConfig(providerConfig.Mode)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Provider{
+ store: providerConfig.Store,
+ config: config,
+ remoteProvider: newRemoteLicenseProvider(config, providerConfig.Store),
+ }, nil
+}
+
+// StoreLicense will store the hub license.
+func (p *Provider) StoreLicense(ctx context.Context, patch *enterprise.SubscriptionPatch) error {
+ if patch.License != "" {
+ if _, err := p.parseLicense(patch.License); err != nil {
+ return err
+ }
+ }
+ if _, err := p.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
+ Name: api.SettingEnterpriseLicense,
+ Value: patch.License,
+ }, patch.UpdaterID); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// LoadSubscription will load the hub subscription.
+func (p *Provider) LoadSubscription(ctx context.Context) *enterprise.Subscription {
+ license := p.loadLicense(ctx)
+ if license == nil {
+ return &enterprise.Subscription{
+ Plan: api.FREE,
+ // -1 means not expire, just for free plan
+ ExpiresTs: -1,
+ // Instance license count.
+ InstanceCount: 0,
+ }
+ }
+
+ return &enterprise.Subscription{
+ Plan: license.Plan,
+ ExpiresTs: license.ExpiresTs,
+ StartedTs: license.IssuedTs,
+ InstanceCount: license.InstanceCount,
+ Trialing: license.Trialing,
+ OrgID: license.OrgID(),
+ OrgName: license.OrgName,
+ }
+}
+
+// GetEffectivePlan gets the effective plan.
+func (p *Provider) GetEffectivePlan(ctx context.Context) api.PlanType {
+ subscription := p.LoadSubscription(ctx)
+ if expireTime := time.Unix(subscription.ExpiresTs, 0); expireTime.Before(time.Now()) {
+ return api.FREE
+ }
+ return subscription.Plan
+}
+
+func (p *Provider) fetchLicense(ctx context.Context) (*enterprise.License, error) {
+ license, err := p.remoteProvider.FetchLicense(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if license == "" {
+ return nil, nil
+ }
+ result, err := p.parseLicense(license)
+ if err != nil {
+ return nil, err
+ }
+
+ if _, err := p.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
+ Name: api.SettingEnterpriseLicense,
+ Value: license,
+ }, api.SystemBotID); err != nil {
+ return nil, errors.Wrapf(err, "failed to store the license")
+ }
+
+ return result, nil
+}
+
+// loadLicense will load license and validate it.
+func (p *Provider) loadLicense(ctx context.Context) *enterprise.License {
+ license, err := p.findEnterpriseLicense(ctx)
+ 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)
+ if err != nil {
+ slog.Debug("failed to fetch license", log.BBError(err))
+ }
+ }
+ if license == nil {
+ return nil
+ }
+ if err := license.Valid(); err != nil {
+ slog.Debug("license is invalid", log.BBError(err))
+ return nil
+ }
+
+ return license
+}
+
+func (p *Provider) parseLicense(license string) (*enterprise.License, error) {
+ claim := &claims{}
+ if err := parseJWTToken(license, p.config.Version, p.config.PublicKey, claim); err != nil {
+ return nil, common.Wrap(err, common.Invalid)
+ }
+
+ return p.parseClaims(claim)
+}
+
+func (p *Provider) findEnterpriseLicense(ctx context.Context) (*enterprise.License, error) {
+ // Find enterprise license.
+ settingName := api.SettingEnterpriseLicense
+ setting, err := p.store.GetSettingV2(ctx, &store.FindSettingMessage{
+ Name: &settingName,
+ })
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to load enterprise license from settings")
+ }
+ if setting != nil && setting.Value != "" {
+ license, err := p.parseLicense(setting.Value)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse enterprise license")
+ }
+ if license != nil {
+ slog.Debug(
+ "Load valid license",
+ slog.String("plan", license.Plan.String()),
+ slog.Time("expiresAt", time.Unix(license.ExpiresTs, 0)),
+ slog.Int("instanceCount", license.InstanceCount),
+ )
+ return license, nil
+ }
+ }
+
+ return 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)
+ if !verifyIssuer {
+ return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", p.config.Issuer, claim.Issuer)
+ }
+
+ verifyAudience := claim.VerifyAudience(p.config.Audience, true)
+ if !verifyAudience {
+ return nil, common.Errorf(common.Invalid, "aud is not valid, expect %s but found '%v'", p.config.Audience, claim.Audience)
+ }
+
+ planType, err := convertPlanType(claim.Plan)
+ if err != nil {
+ return nil, common.Errorf(common.Invalid, "plan type %q is not valid", planType)
+ }
+
+ license := &enterprise.License{
+ InstanceCount: claim.InstanceCount,
+ ExpiresTs: claim.ExpiresAt.Unix(),
+ IssuedTs: claim.IssuedAt.Unix(),
+ Plan: planType,
+ Subject: claim.Subject,
+ Trialing: claim.Trialing,
+ OrgName: claim.OrgName,
+ }
+
+ return license, nil
+}
+
+func convertPlanType(candidate string) (api.PlanType, error) {
+ switch candidate {
+ case api.TEAM.String():
+ return api.TEAM, nil
+ case api.ENTERPRISE.String():
+ return api.ENTERPRISE, nil
+ case api.FREE.String():
+ return api.FREE, nil
+ default:
+ return api.FREE, errors.Errorf("cannot conver plan type %q", candidate)
+ }
+}
diff --git a/backend/enterprise/service/provider.go b/backend/enterprise/plugin/hub/remote_provider.go
similarity index 84%
rename from backend/enterprise/service/provider.go
rename to backend/enterprise/plugin/hub/remote_provider.go
index c2a88b3139..ace5ef79b0 100644
--- a/backend/enterprise/service/provider.go
+++ b/backend/enterprise/plugin/hub/remote_provider.go
@@ -1,4 +1,4 @@
-package service
+package hub
import (
"context"
@@ -37,17 +37,17 @@ type internalTokenClaims struct {
jwt.RegisteredClaims
}
-// LicenseProvider is the service to fetch license from the hub.
-type LicenseProvider struct {
+// remoteLicenseProvider is the service to fetch license from the hub.
+type remoteLicenseProvider struct {
config *config.Config
store *store.Store
client *http.Client
lastFetchTime int64
}
-// NewLicenseProvider will create a new license provider.
-func NewLicenseProvider(config *config.Config, store *store.Store) *LicenseProvider {
- return &LicenseProvider{
+// newRemoteLicenseProvider will create a new license provider.
+func newRemoteLicenseProvider(config *config.Config, store *store.Store) *remoteLicenseProvider {
+ return &remoteLicenseProvider{
store: store,
config: config,
client: &http.Client{
@@ -58,7 +58,7 @@ func NewLicenseProvider(config *config.Config, store *store.Store) *LicenseProvi
}
// FetchLicense will fetch the license from the hub.
-func (p *LicenseProvider) FetchLicense(ctx context.Context) (string, error) {
+func (p *remoteLicenseProvider) FetchLicense(ctx context.Context) (string, error) {
nextFetchTime := p.lastFetchTime + int64(fetchLicenseInterval.Seconds())
if time.Now().Unix() < nextFetchTime {
slog.Debug(fmt.Sprintf("skip fetching license until %d", nextFetchTime))
@@ -90,7 +90,7 @@ func (p *LicenseProvider) FetchLicense(ctx context.Context) (string, error) {
return p.requestLicense(ctx, payload.Url, payload.Token)
}
-func (p *LicenseProvider) requestLicense(ctx context.Context, agentURL, agentToken string) (string, error) {
+func (p *remoteLicenseProvider) requestLicense(ctx context.Context, agentURL, agentToken string) (string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, agentURL, nil)
if err != nil {
return "", errors.Wrapf(err, "construct GET %s", agentURL)
@@ -120,7 +120,7 @@ func (p *LicenseProvider) requestLicense(ctx context.Context, agentURL, agentTok
return response.License, nil
}
-func (p *LicenseProvider) parseJWTToken(tokenStr string) (*internalTokenClaims, error) {
+func (p *remoteLicenseProvider) parseJWTToken(tokenStr string) (*internalTokenClaims, error) {
claims := &internalTokenClaims{}
if err := parseJWTToken(tokenStr, p.config.Version, p.config.PublicKey, claims); err != nil {
return nil, common.Wrap(err, common.Invalid)
diff --git a/backend/enterprise/service/utils.go b/backend/enterprise/plugin/hub/utils.go
similarity index 98%
rename from backend/enterprise/service/utils.go
rename to backend/enterprise/plugin/hub/utils.go
index d6d93b81a8..bd1eb7fe35 100644
--- a/backend/enterprise/service/utils.go
+++ b/backend/enterprise/plugin/hub/utils.go
@@ -1,4 +1,4 @@
-package service
+package hub
import (
"github.com/golang-jwt/jwt"
diff --git a/backend/enterprise/plugin/license.go b/backend/enterprise/plugin/license.go
new file mode 100644
index 0000000000..40b9be6c26
--- /dev/null
+++ b/backend/enterprise/plugin/license.go
@@ -0,0 +1,26 @@
+package plugin
+
+import (
+ "context"
+
+ "github.com/bytebase/bytebase/backend/common"
+ enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
+ api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/store"
+)
+
+// LicenseProvider is the license provider.
+type LicenseProvider interface {
+ // StoreLicense will store the license.
+ StoreLicense(ctx context.Context, patch *enterprise.SubscriptionPatch) error
+ // LoadSubscription will load the subscription.
+ LoadSubscription(ctx context.Context) *enterprise.Subscription
+ // GetEffectivePlan gets the effective plan.
+ GetEffectivePlan(ctx context.Context) api.PlanType
+}
+
+// ProviderConfig is the provider configuration.
+type ProviderConfig struct {
+ Mode common.ReleaseMode
+ Store *store.Store
+}
diff --git a/backend/enterprise/service/license.go b/backend/enterprise/service/license.go
index d410579464..da53901446 100644
--- a/backend/enterprise/service/license.go
+++ b/backend/enterprise/service/license.go
@@ -3,28 +3,26 @@ package service
import (
"context"
- "encoding/json"
- "log/slog"
"math"
- "time"
"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"
"github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/common/log"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
- "github.com/bytebase/bytebase/backend/enterprise/config"
+ "github.com/bytebase/bytebase/backend/enterprise/plugin"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
)
+var _ enterprise.LicenseService = (*LicenseService)(nil)
+
// LicenseService is the service for enterprise license.
type LicenseService struct {
- config *config.Config
store *store.Store
- provider *LicenseProvider
cachedSubscription *enterprise.Subscription
+
+ provider plugin.LicenseProvider
}
// Claims creates a struct that will be encoded to a JWT.
@@ -39,29 +37,23 @@ type Claims struct {
// NewLicenseService will create a new enterprise license service.
func NewLicenseService(mode common.ReleaseMode, store *store.Store) (*LicenseService, error) {
- config, err := config.NewConfig(mode)
+ provider, err := getLicenseProvider(&plugin.ProviderConfig{
+ Mode: mode,
+ Store: store,
+ })
if err != nil {
return nil, err
}
return &LicenseService{
store: store,
- config: config,
- provider: NewLicenseProvider(config, store),
+ provider: provider,
}, nil
}
// StoreLicense will store license into file.
func (s *LicenseService) StoreLicense(ctx context.Context, patch *enterprise.SubscriptionPatch) error {
- if patch.License != "" {
- if _, err := s.parseLicense(patch.License); err != nil {
- return err
- }
- }
- if _, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
- Name: api.SettingEnterpriseLicense,
- Value: patch.License,
- }, patch.UpdaterID); err != nil {
+ if err := s.provider.StoreLicense(ctx, patch); err != nil {
return err
}
@@ -70,37 +62,18 @@ func (s *LicenseService) StoreLicense(ctx context.Context, patch *enterprise.Sub
}
// LoadSubscription will load subscription.
-func (s *LicenseService) LoadSubscription(ctx context.Context) enterprise.Subscription {
+func (s *LicenseService) LoadSubscription(ctx context.Context) *enterprise.Subscription {
if s.cachedSubscription != nil && s.cachedSubscription.IsExpired() {
// refresh expired subscription
s.cachedSubscription = nil
}
if s.cachedSubscription != nil {
- return *s.cachedSubscription
- }
-
- license := s.loadLicense(ctx)
- if license == nil {
- return enterprise.Subscription{
- Plan: api.FREE,
- // -1 means not expire, just for free plan
- ExpiresTs: -1,
- // Instance license count.
- InstanceCount: 0,
- }
+ return s.cachedSubscription
}
// Cache the subscription.
- s.cachedSubscription = &enterprise.Subscription{
- Plan: license.Plan,
- ExpiresTs: license.ExpiresTs,
- StartedTs: license.IssuedTs,
- InstanceCount: license.InstanceCount,
- Trialing: license.Trialing,
- OrgID: license.OrgID(),
- OrgName: license.OrgName,
- }
- return *s.cachedSubscription
+ s.cachedSubscription = s.provider.LoadSubscription(ctx)
+ return s.cachedSubscription
}
// IsFeatureEnabled returns whether a feature is enabled.
@@ -143,11 +116,7 @@ func (s *LicenseService) GetInstanceLicenseCount(ctx context.Context) int {
// GetEffectivePlan gets the effective plan.
func (s *LicenseService) GetEffectivePlan() api.PlanType {
ctx := context.Background()
- subscription := s.LoadSubscription(ctx)
- if expireTime := time.Unix(subscription.ExpiresTs, 0); expireTime.Before(time.Now()) {
- return api.FREE
- }
- return subscription.Plan
+ return s.provider.GetEffectivePlan(ctx)
}
// GetPlanLimitValue gets the limit value for the plan.
@@ -175,161 +144,3 @@ func (s *LicenseService) RefreshCache(ctx context.Context) {
s.cachedSubscription = nil
s.LoadSubscription(ctx)
}
-
-func (s *LicenseService) fetchLicense(ctx context.Context) (*enterprise.License, error) {
- license, err := s.provider.FetchLicense(ctx)
- if err != nil {
- return nil, err
- }
- if license == "" {
- return nil, nil
- }
- result, err := s.parseLicense(license)
- if err != nil {
- return nil, err
- }
-
- if _, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
- Name: api.SettingEnterpriseLicense,
- Value: license,
- }, api.SystemBotID); err != nil {
- return nil, errors.Wrapf(err, "failed to store the license")
- }
-
- s.RefreshCache(ctx)
-
- return result, nil
-}
-
-// loadLicense will load license and validate it.
-func (s *LicenseService) loadLicense(ctx context.Context) *enterprise.License {
- license, err := s.findEnterpriseLicense(ctx)
- if err != nil {
- slog.Debug("failed to load enterprise license", log.BBError(err))
- }
- if license == nil {
- license, err = s.findTrialingLicense(ctx)
- if err != nil {
- slog.Debug("failed to load trialing license", log.BBError(err))
- }
- }
-
- if license == nil {
- license, err = s.fetchLicense(ctx)
- if err != nil {
- slog.Debug("failed to fetch license", log.BBError(err))
- }
- }
- if license == nil {
- return nil
- }
- if err := license.Valid(); err != nil {
- slog.Debug("license is invalid", log.BBError(err))
- return nil
- }
-
- return license
-}
-
-func (s *LicenseService) parseLicense(license string) (*enterprise.License, error) {
- claims := &Claims{}
- if err := parseJWTToken(license, s.config.Version, s.config.PublicKey, claims); err != nil {
- return nil, common.Wrap(err, common.Invalid)
- }
-
- return s.parseClaims(claims)
-}
-
-func (s *LicenseService) findEnterpriseLicense(ctx context.Context) (*enterprise.License, error) {
- // Find enterprise license.
- settingName := api.SettingEnterpriseLicense
- setting, err := s.store.GetSettingV2(ctx, &store.FindSettingMessage{
- Name: &settingName,
- })
- if err != nil {
- return nil, errors.Wrapf(err, "failed to load enterprise license from settings")
- }
- if setting != nil && setting.Value != "" {
- license, err := s.parseLicense(setting.Value)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to parse enterprise license")
- }
- if license != nil {
- slog.Debug(
- "Load valid license",
- slog.String("plan", license.Plan.String()),
- slog.Time("expiresAt", time.Unix(license.ExpiresTs, 0)),
- slog.Int("instanceCount", license.InstanceCount),
- )
- return license, nil
- }
- }
-
- return nil, nil
-}
-
-func (s *LicenseService) findTrialingLicense(ctx context.Context) (*enterprise.License, error) {
- settingName := api.SettingEnterpriseTrial
- setting, err := s.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 (s *LicenseService) parseClaims(claims *Claims) (*enterprise.License, error) {
- verifyIssuer := claims.VerifyIssuer(s.config.Issuer, true)
- if !verifyIssuer {
- return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", s.config.Issuer, claims.Issuer)
- }
-
- verifyAudience := claims.VerifyAudience(s.config.Audience, true)
- if !verifyAudience {
- return nil, common.Errorf(common.Invalid, "aud is not valid, expect %s but found '%v'", s.config.Audience, claims.Audience)
- }
-
- planType, err := convertPlanType(claims.Plan)
- if err != nil {
- return nil, common.Errorf(common.Invalid, "plan type %q is not valid", planType)
- }
-
- license := &enterprise.License{
- InstanceCount: claims.InstanceCount,
- ExpiresTs: claims.ExpiresAt.Unix(),
- IssuedTs: claims.IssuedAt.Unix(),
- Plan: planType,
- Subject: claims.Subject,
- Trialing: claims.Trialing,
- OrgName: claims.OrgName,
- }
-
- return license, nil
-}
-
-func convertPlanType(candidate string) (api.PlanType, error) {
- switch candidate {
- case api.TEAM.String():
- return api.TEAM, nil
- case api.ENTERPRISE.String():
- return api.ENTERPRISE, nil
- case api.FREE.String():
- return api.FREE, nil
- default:
- return api.FREE, errors.Errorf("cannot conver plan type %q", candidate)
- }
-}
diff --git a/backend/enterprise/service/provider_aws.go b/backend/enterprise/service/provider_aws.go
new file mode 100644
index 0000000000..f08db03fe4
--- /dev/null
+++ b/backend/enterprise/service/provider_aws.go
@@ -0,0 +1,12 @@
+//go:build aws
+
+package service
+
+import (
+ "github.com/bytebase/bytebase/backend/enterprise/plugin"
+ "github.com/bytebase/bytebase/backend/enterprise/plugin/aws"
+)
+
+func getLicenseProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
+ return aws.NewProvider(providerConfig)
+}
diff --git a/backend/enterprise/service/provider_hub.go b/backend/enterprise/service/provider_hub.go
new file mode 100644
index 0000000000..518eeb4724
--- /dev/null
+++ b/backend/enterprise/service/provider_hub.go
@@ -0,0 +1,12 @@
+//go:build !aws
+
+package service
+
+import (
+ "github.com/bytebase/bytebase/backend/enterprise/plugin"
+ "github.com/bytebase/bytebase/backend/enterprise/plugin/hub"
+)
+
+func getLicenseProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
+ return hub.NewProvider(providerConfig)
+}