-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: license-checker * fix: format license * feat: plan check via grpc * docs: add reference to FAQ * fix: test * ci: goimports * fix: remove check based on rest endpoint
- Loading branch information
Showing
13 changed files
with
735 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -11,4 +11,5 @@ type ProContext struct { | |
EnvID string | ||
OrgID string | ||
Migrate string | ||
ConnectionTimeout int | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,7 @@ | ||
# Testkube Operator - TCL Package | ||
|
||
This folder contains special code with the Testkube Community license. | ||
|
||
## License | ||
|
||
The code in this folder is licensed under the Testkube Community License. Please see the [LICENSE](../../licenses/TCL.txt) file and consult the [FAQ](../../docs/docs/articles/testkube-licensing-FAQ.md) for more information. |
This file contains 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,50 @@ | ||
// Copyright 2024 Testkube. | ||
// | ||
// Licensed as a Testkube Pro file under the Testkube Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt | ||
|
||
package checktcl | ||
|
||
// Enterprise / Pro mode. | ||
type OrganizationPlanTestkubeMode string | ||
|
||
const ( | ||
OrganizationPlanTestkubeModeEnterprise OrganizationPlanTestkubeMode = "enterprise" | ||
// TODO: Use "pro" in the future when refactoring TK Pro API server to use "pro" instead of "cloud" | ||
OrganizationPlanTestkubeModePro OrganizationPlanTestkubeMode = "cloud" | ||
) | ||
|
||
// Ref: #/components/schemas/PlanStatus | ||
type PlanStatus string | ||
|
||
const ( | ||
PlanStatusActive PlanStatus = "Active" | ||
PlanStatusCanceled PlanStatus = "Canceled" | ||
PlanStatusIncomplete PlanStatus = "Incomplete" | ||
PlanStatusIncompleteExpired PlanStatus = "IncompleteExpired" | ||
PlanStatusPastDue PlanStatus = "PastDue" | ||
PlanStatusTrailing PlanStatus = "Trailing" | ||
PlanStatusUnpaid PlanStatus = "Unpaid" | ||
PlanStatusDeleted PlanStatus = "Deleted" | ||
PlanStatusLocked PlanStatus = "Locked" | ||
PlanStatusBlocked PlanStatus = "Blocked" | ||
) | ||
|
||
// Ref: #/components/schemas/OrganizationPlan | ||
type OrganizationPlan struct { | ||
// Enterprise / Pro mode. | ||
TestkubeMode OrganizationPlanTestkubeMode `json:"testkubeMode"` | ||
// Is current plan trial. | ||
IsTrial bool `json:"isTrial"` | ||
PlanStatus PlanStatus `json:"planStatus"` | ||
} | ||
|
||
type GetOrganizationPlanRequest struct{} | ||
type GetOrganizationPlanResponse struct { | ||
TestkubeMode string | ||
IsTrial bool | ||
PlanStatus string | ||
} |
This file contains 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,83 @@ | ||
// Copyright 2024 Testkube. | ||
// | ||
// Licensed as a Testkube Pro file under the Testkube Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt | ||
|
||
package checktcl | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/kubeshop/testkube/internal/config" | ||
"github.com/kubeshop/testkube/pkg/cloud" | ||
cloudconfig "github.com/kubeshop/testkube/pkg/cloud/data/config" | ||
"github.com/kubeshop/testkube/pkg/cloud/data/executor" | ||
) | ||
|
||
type SubscriptionChecker struct { | ||
proContext config.ProContext | ||
orgPlan *OrganizationPlan | ||
} | ||
|
||
// NewSubscriptionChecker creates a new subscription checker using the agent token | ||
func NewSubscriptionChecker(ctx context.Context, proContext config.ProContext, cloudClient cloud.TestKubeCloudAPIClient, grpcConn *grpc.ClientConn) (*SubscriptionChecker, error) { | ||
executor := executor.NewCloudGRPCExecutor(cloudClient, grpcConn, proContext.APIKey) | ||
|
||
req := GetOrganizationPlanRequest{} | ||
response, err := executor.Execute(ctx, cloudconfig.CmdConfigGetOrganizationPlan, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var commandResponse GetOrganizationPlanResponse | ||
if err := json.Unmarshal(response, &commandResponse); err != nil { | ||
return nil, err | ||
} | ||
|
||
subscription := OrganizationPlan{ | ||
TestkubeMode: OrganizationPlanTestkubeMode(commandResponse.TestkubeMode), | ||
IsTrial: commandResponse.IsTrial, | ||
PlanStatus: PlanStatus(commandResponse.PlanStatus), | ||
} | ||
|
||
return &SubscriptionChecker{proContext: proContext, orgPlan: &subscription}, nil | ||
} | ||
|
||
// GetCurrentOrganizationPlan returns current organization plan | ||
func (c *SubscriptionChecker) GetCurrentOrganizationPlan() (*OrganizationPlan, error) { | ||
if c.orgPlan == nil { | ||
return nil, errors.New("organization plan is not set") | ||
} | ||
return c.orgPlan, nil | ||
} | ||
|
||
// IsOrgPlanEnterprise checks if organization plan is enterprise | ||
func (c *SubscriptionChecker) IsOrgPlanEnterprise() (bool, error) { | ||
if c.orgPlan == nil { | ||
return false, errors.New("organization plan is not set") | ||
} | ||
return c.orgPlan.TestkubeMode == OrganizationPlanTestkubeModeEnterprise, nil | ||
} | ||
|
||
// IsOrgPlanCloud checks if organization plan is cloud | ||
func (c *SubscriptionChecker) IsOrgPlanPro() (bool, error) { | ||
if c.orgPlan == nil { | ||
return false, errors.New("organization plan is not set") | ||
} | ||
return c.orgPlan.TestkubeMode == OrganizationPlanTestkubeModePro, nil | ||
} | ||
|
||
// IsOrgPlanActive checks if organization plan is active | ||
func (c *SubscriptionChecker) IsOrgPlanActive() (bool, error) { | ||
if c.orgPlan == nil { | ||
return false, errors.New("organization plan is not set") | ||
} | ||
return c.orgPlan.PlanStatus == PlanStatusActive, nil | ||
} |
Oops, something went wrong.