From 73d4261f3a0ba809cbd1573e7141e8b34f659e3a Mon Sep 17 00:00:00 2001 From: Simon Emms Date: Fri, 4 Mar 2022 15:45:36 +0000 Subject: [PATCH] [licensor]: introduce concept of a fallback license with limited features --- .../licensor/ee/pkg/licensor/licensor.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/components/licensor/ee/pkg/licensor/licensor.go b/components/licensor/ee/pkg/licensor/licensor.go index 3c6f3aa0a114a8..8cecf8d26454ea 100644 --- a/components/licensor/ee/pkg/licensor/licensor.go +++ b/components/licensor/ee/pkg/licensor/licensor.go @@ -117,9 +117,18 @@ func (lvl LicenseLevel) allowance() allowance { return a } +// Fallback license is used when the instance exceeds the number of licenses - it allows limited access +var fallbackLicense = LicensePayload{ + ID: "fallback-license", + Level: LevelTeam, + Seats: 0, + // Domain, ValidUntil are free for all +} + +// Default license is used when no valid license is given - it allows full access up to 10 users var defaultLicense = LicensePayload{ ID: "default-license", - Level: LevelTeam, + Level: LevelEnterprise, Seats: 10, // Domain, ValidUntil are free for all } @@ -163,7 +172,15 @@ func (e *Evaluator) Enabled(feature Feature, seats int) bool { return false } - _, ok := e.lic.Level.allowance().Features[feature] + var ok bool + if e.lic.Seats == 0 || seats <= e.lic.Seats { + // License has enough seats available - evaluate this license + _, ok = e.lic.Level.allowance().Features[feature] + } else { + // License has run out of seats - use the fallback license + _, ok = fallbackLicense.Level.allowance().Features[feature] + } + return ok }