@@ -3,22 +3,29 @@ package vo
33import "time"
44
55const (
6- TrialMemberLimit = 5
6+ TrialMemberLimit = 5
7+ TrialDeploymentLimit = 5000
78)
89
910const (
10- LicenseKindTrial LicenseKind = "trial"
11+ // LicenseKindOSS is a license for the community edition.
12+ LicenseKindOSS LicenseKind = "oss"
13+ // LicenseKindTrial is a trial license of the enterprise edition.
14+ LicenseKindTrial LicenseKind = "trial"
15+ // LicenseKindStandard is a license of the enterprise edition.
1116 LicenseKindStandard LicenseKind = "standard"
1217)
1318
1419type (
1520 LicenseKind string
1621
1722 License struct {
18- Kind LicenseKind `json:"kind"`
19- MemberCount int `json:"member_count"`
20- MemberLimit int `json:"memeber_limit"`
21- ExpiredAt time.Time `json:"expired_at"`
23+ Kind LicenseKind `json:"kind"`
24+ MemberCount int `json:"member_count"`
25+ MemberLimit int `json:"memeber_limit"`
26+ DeploymentCount int `json:"deployment_count"`
27+ DeploymentLimit int `json:"deployment_limit"`
28+ ExpiredAt time.Time `json:"expired_at"`
2229 }
2330
2431 // SigningData marshal and unmarshal the content of license.
@@ -28,31 +35,52 @@ type (
2835 }
2936)
3037
31- func NewTrialLicense ( cnt int ) * License {
38+ func NewOSSLicense ( ) * License {
3239 return & License {
33- Kind : LicenseKindTrial ,
34- MemberCount : cnt ,
35- MemberLimit : TrialMemberLimit ,
40+ Kind : LicenseKindOSS ,
41+ MemberCount : - 1 ,
42+ DeploymentCount : - 1 ,
3643 }
3744}
3845
39- func NewStandardLicense ( cnt int , d * SigningData ) * License {
46+ func NewTrialLicense ( memberCnt , deploymentCnt int ) * License {
4047 return & License {
41- Kind : LicenseKindStandard ,
42- MemberCount : cnt ,
43- MemberLimit : d .MemberLimit ,
44- ExpiredAt : d .ExpiredAt ,
48+ Kind : LicenseKindTrial ,
49+ MemberCount : memberCnt ,
50+ MemberLimit : TrialMemberLimit ,
51+ DeploymentCount : deploymentCnt ,
52+ DeploymentLimit : TrialDeploymentLimit ,
4553 }
4654}
4755
56+ func NewStandardLicense (memberCnt int , d * SigningData ) * License {
57+ return & License {
58+ Kind : LicenseKindStandard ,
59+ MemberCount : memberCnt ,
60+ MemberLimit : d .MemberLimit ,
61+ DeploymentCount : - 1 ,
62+ ExpiredAt : d .ExpiredAt ,
63+ }
64+ }
65+
66+ func (l * License ) IsOSS () bool {
67+ return l .Kind == LicenseKindOSS
68+ }
69+
4870func (l * License ) IsTrial () bool {
4971 return l .Kind == LicenseKindTrial
5072}
5173
74+ func (l * License ) IsStandard () bool {
75+ return l .Kind == LicenseKindStandard
76+ }
77+
78+ // IsOverLimit verify it is over the limit of the license.
5279func (l * License ) IsOverLimit () bool {
53- return l .MemberCount > l .MemberLimit
80+ return l .MemberCount > l .MemberLimit || l . DeploymentCount > l . DeploymentLimit
5481}
5582
83+ // IsExpired verify that the license is expired or not.
5684func (l * License ) IsExpired () bool {
5785 return l .ExpiredAt .Before (time .Now ())
5886}
0 commit comments