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
Add a new license type for OSS #186
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build oss | ||
|
||
package interactor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gitploy-io/gitploy/vo" | ||
) | ||
|
||
func (i *Interactor) GetLicense(ctx context.Context) (*vo.License, error) { | ||
return vo.NewOSSLicense(), nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package interactor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/gitploy-io/gitploy/internal/interactor/mock" | ||
"github.com/gitploy-io/gitploy/vo" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestStore_GetLicense(t *testing.T) { | ||
t.Run("Return the trial license when the signing data is nil.", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
store := mock.NewMockStore(ctrl) | ||
|
||
t.Log("MOCK - return the count of users.") | ||
store. | ||
EXPECT(). | ||
CountUsers(gomock.AssignableToTypeOf(context.Background())). | ||
Return(vo.TrialMemberLimit, nil) | ||
|
||
store. | ||
EXPECT(). | ||
CountDeployments(gomock.AssignableToTypeOf(context.Background())). | ||
Return(vo.TrialDeploymentLimit, nil) | ||
|
||
i := &Interactor{Store: store} | ||
|
||
lic, err := i.GetLicense(context.Background()) | ||
if err != nil { | ||
t.Fatalf("GetLicense returns an error: %s", err) | ||
} | ||
|
||
if !lic.IsTrial() { | ||
t.Fatalf("GetLicense = %v, wanted %v", lic.Kind, vo.LicenseKindTrial) | ||
} | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,29 @@ package vo | |
import "time" | ||
|
||
const ( | ||
TrialMemberLimit = 5 | ||
TrialMemberLimit = 5 | ||
TrialDeploymentLimit = 5000 | ||
) | ||
|
||
const ( | ||
LicenseKindTrial LicenseKind = "trial" | ||
// 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"` | ||
ExpiredAt time.Time `json:"expired_at"` | ||
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. | ||
|
@@ -28,31 +35,52 @@ type ( | |
} | ||
) | ||
|
||
func NewTrialLicense(cnt int) *License { | ||
func NewOSSLicense() *License { | ||
return &License{ | ||
Kind: LicenseKindTrial, | ||
MemberCount: cnt, | ||
MemberLimit: TrialMemberLimit, | ||
Kind: LicenseKindOSS, | ||
MemberCount: -1, | ||
DeploymentCount: -1, | ||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
} | ||
|
||
func NewStandardLicense(cnt int, d *SigningData) *License { | ||
func NewTrialLicense(memberCnt, deploymentCnt int) *License { | ||
return &License{ | ||
Kind: LicenseKindStandard, | ||
MemberCount: cnt, | ||
MemberLimit: d.MemberLimit, | ||
ExpiredAt: d.ExpiredAt, | ||
Kind: LicenseKindTrial, | ||
MemberCount: memberCnt, | ||
MemberLimit: TrialMemberLimit, | ||
DeploymentCount: deploymentCnt, | ||
DeploymentLimit: TrialDeploymentLimit, | ||
} | ||
} | ||
|
||
func NewStandardLicense(memberCnt int, d *SigningData) *License { | ||
return &License{ | ||
Kind: LicenseKindStandard, | ||
MemberCount: memberCnt, | ||
MemberLimit: d.MemberLimit, | ||
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 | ||
return l.MemberCount > l.MemberLimit || l.DeploymentCount > l.DeploymentLimit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add deployment limit to verify the license. |
||
} | ||
|
||
// IsExpired verify that the license is expired or not. | ||
func (l *License) IsExpired() bool { | ||
return l.ExpiredAt.Before(time.Now()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip when the license is
oss