This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlicense.go
More file actions
91 lines (77 loc) · 2.19 KB
/
Copy pathlicense.go
File metadata and controls
91 lines (77 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package extent
import (
"math"
"time"
)
const (
TrialMemberLimit = 5
TrialDeploymentLimit = 5000
InfiniteMemberLimit = math.MaxInt
InfiniteDeploymentLimit = math.MaxInt
)
const (
// LicenseKindOSS is a license for the community edition.
LicenseKindOSS LicenseKind = "oss"
// LicenseKindTrial is a trial license of the enterprise edition.
LicenseKindTrial LicenseKind = "trial"
// LicenseKindStandard is a license of the enterprise edition.
LicenseKindStandard LicenseKind = "standard"
)
type (
LicenseKind string
License struct {
Kind LicenseKind `json:"kind"`
MemberCount int `json:"member_count"`
MemberLimit int `json:"memeber_limit"`
DeploymentCount int `json:"deployment_count"`
DeploymentLimit int `json:"deployment_limit"`
ExpiredAt time.Time `json:"expired_at"`
}
// SigningData marshal and unmarshal the content of license.
SigningData struct {
MemberLimit int `json:"memeber_limit"`
ExpiredAt time.Time `json:"expired_at"`
}
)
func NewOSSLicense() *License {
return &License{
Kind: LicenseKindOSS,
MemberCount: -1,
DeploymentCount: -1,
}
}
func NewTrialLicense(memberCnt, deploymentCnt int) *License {
return &License{
Kind: LicenseKindTrial,
MemberCount: memberCnt,
MemberLimit: InfiniteMemberLimit,
DeploymentCount: deploymentCnt,
DeploymentLimit: InfiniteMemberLimit,
}
}
func NewStandardLicense(memberCnt int, d *SigningData) *License {
return &License{
Kind: LicenseKindStandard,
MemberCount: memberCnt,
MemberLimit: InfiniteMemberLimit,
DeploymentCount: -1,
ExpiredAt: d.ExpiredAt,
}
}
func (l *License) IsOSS() bool {
return l.Kind == LicenseKindOSS
}
func (l *License) IsTrial() bool {
return l.Kind == LicenseKindTrial
}
func (l *License) IsStandard() bool {
return l.Kind == LicenseKindStandard
}
// IsOverLimit verify it is over the limit of the license.
func (l *License) IsOverLimit() bool {
return l.MemberCount > l.MemberLimit || l.DeploymentCount > l.DeploymentLimit
}
// IsExpired verify that the license is expired or not.
func (l *License) IsExpired() bool {
return l.ExpiredAt.Before(time.Now())
}