(ctx context.Context, workspaceID string)
| 234 | } |
| 235 | |
| 236 | func (s *LicenseService) loadSubscriptionFromDB(ctx context.Context, workspaceID string) *v1pb.Subscription { |
| 237 | setting, err := s.store.GetSystemSetting(ctx, workspaceID) |
| 238 | if err != nil { |
| 239 | slog.Debug("failed to get system setting", log.BBError(err)) |
| 240 | return defaultFreeSubscription |
| 241 | } |
| 242 | |
| 243 | if setting.License == "" { |
| 244 | return defaultFreeSubscription |
| 245 | } |
| 246 | |
| 247 | subscription, err := s.parseLicense(setting.License, workspaceID) |
| 248 | if err != nil { |
| 249 | slog.Debug("failed to parse enterprise license", log.BBError(err)) |
| 250 | return defaultFreeSubscription |
| 251 | } |
| 252 | |
| 253 | slog.Debug( |
| 254 | "Load valid license", |
| 255 | slog.String("workspace", workspaceID), |
| 256 | slog.String("plan", subscription.Plan.String()), |
| 257 | slog.Time("expiresAt", subscription.ExpiresTime.AsTime()), |
| 258 | slog.Int("activeInstances", int(subscription.ActiveInstances)), |
| 259 | slog.Int("instances", int(subscription.Instances)), |
| 260 | slog.Int("seats", int(subscription.Seats)), |
| 261 | ) |
| 262 | |
| 263 | // Switch to free plan if the subscription is expired. |
| 264 | if isExpired(subscription) { |
| 265 | return &v1pb.Subscription{ |
| 266 | Plan: v1pb.PlanType_FREE, |
| 267 | ExpiresTime: subscription.ExpiresTime, |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return subscription |
| 272 | } |
| 273 | |
| 274 | func isExpired(sub *v1pb.Subscription) bool { |
| 275 | if sub == nil { |
no test coverage detected