Documentation
¶
Overview ¶
Package licensing provides license validation and feature gating for the workflow engine.
Index ¶
- Constants
- type HTTPValidator
- func (v *HTTPValidator) CanLoadPlugin(tier string) bool
- func (v *HTTPValidator) CheckFeature(feature string) bool
- func (v *HTTPValidator) GetLicenseInfo() *LicenseInfo
- func (v *HTTPValidator) Start(ctx context.Context) error
- func (v *HTTPValidator) Stop(_ context.Context)
- func (v *HTTPValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)
- type LicenseInfo
- type ValidationResult
- type Validator
- type ValidatorConfig
Constants ¶
const DefaultCacheTTL = 1 * time.Hour
DefaultCacheTTL is the default time to cache a valid license result.
const DefaultGracePeriod = 72 * time.Hour
DefaultGracePeriod is how long offline operation is allowed after the last successful validation before the license is considered expired.
const DefaultRefreshInterval = 1 * time.Hour
DefaultRefreshInterval is how often the background goroutine re-validates.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPValidator ¶
type HTTPValidator struct {
// contains filtered or unexported fields
}
HTTPValidator validates licenses against a remote server with local caching and a grace period for offline operation.
func NewHTTPValidator ¶
func NewHTTPValidator(cfg ValidatorConfig, logger *slog.Logger) *HTTPValidator
NewHTTPValidator creates a new HTTPValidator with the given config.
func (*HTTPValidator) CanLoadPlugin ¶
func (v *HTTPValidator) CanLoadPlugin(tier string) bool
CanLoadPlugin returns true if the current license permits loading a plugin of the given tier.
- TierCore and TierCommunity: always allowed
- TierPremium: only allowed when license tier is "professional" or "enterprise"
func (*HTTPValidator) CheckFeature ¶
func (v *HTTPValidator) CheckFeature(feature string) bool
CheckFeature returns true if the current license includes the given feature.
func (*HTTPValidator) GetLicenseInfo ¶
func (v *HTTPValidator) GetLicenseInfo() *LicenseInfo
GetLicenseInfo returns the current cached license info, or nil if no valid license is cached.
func (*HTTPValidator) Start ¶
func (v *HTTPValidator) Start(ctx context.Context) error
Start performs an initial validation and starts a background refresh goroutine.
func (*HTTPValidator) Stop ¶
func (v *HTTPValidator) Stop(_ context.Context)
Stop signals the background refresh goroutine to exit.
func (*HTTPValidator) Validate ¶
func (v *HTTPValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)
Validate returns the current license validation result. If a valid cached result exists, it is returned immediately. If the cached result is expired, remote validation is attempted. If remote validation fails, the grace period is checked.
type LicenseInfo ¶
type LicenseInfo struct {
Key string `json:"key"`
Tier string `json:"tier"` // starter, professional, enterprise
Organization string `json:"organization"`
ExpiresAt time.Time `json:"expires_at"`
MaxWorkflows int `json:"max_workflows"`
MaxPlugins int `json:"max_plugins"`
Features []string `json:"features"`
}
LicenseInfo contains the details of a validated license.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
License LicenseInfo `json:"license,omitempty"`
Error string `json:"error,omitempty"`
CachedUntil time.Time `json:"cached_until"`
}
ValidationResult holds the outcome of a license validation attempt.
type Validator ¶
type Validator interface {
Validate(ctx context.Context, key string) (*ValidationResult, error)
CheckFeature(feature string) bool
GetLicenseInfo() *LicenseInfo
}
Validator is the interface for license validation and feature checking.