Documentation
¶
Overview ¶
Package licensing provides license validation and feature gating for the workflow engine.
Index ¶
- Constants
- type CompositeValidator
- func (c *CompositeValidator) CanLoadPlugin(tier string) bool
- func (c *CompositeValidator) CheckFeature(feature string) bool
- func (c *CompositeValidator) GetLicenseInfo() *LicenseInfo
- func (c *CompositeValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)
- func (c *CompositeValidator) ValidatePlugin(pluginName string) error
- 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 OfflineValidator
- func (v *OfflineValidator) CanLoadPlugin(tier string) bool
- func (v *OfflineValidator) CheckFeature(feature string) bool
- func (v *OfflineValidator) GetLicenseInfo() *LicenseInfo
- func (v *OfflineValidator) Validate(_ context.Context, key string) (*ValidationResult, error)
- func (v *OfflineValidator) ValidatePlugin(pluginName string) error
- 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 CompositeValidator ¶ added in v0.3.3
type CompositeValidator struct {
// contains filtered or unexported fields
}
CompositeValidator tries an offline validator first, falling back to an HTTP validator. This enables air-gapped or low-latency license checks while keeping the HTTP validator as a fallback for online validation.
func NewCompositeValidator ¶ added in v0.3.3
func NewCompositeValidator(offline *OfflineValidator, http *HTTPValidator) *CompositeValidator
NewCompositeValidator creates a CompositeValidator from an offline and an HTTP validator. Either may be nil (though at least one should be non-nil).
func (*CompositeValidator) CanLoadPlugin ¶ added in v0.3.3
func (c *CompositeValidator) CanLoadPlugin(tier string) bool
CanLoadPlugin returns true when the offline validator permits the tier, or when there is no offline validator and the HTTP validator permits it.
func (*CompositeValidator) CheckFeature ¶ added in v0.3.3
func (c *CompositeValidator) CheckFeature(feature string) bool
CheckFeature implements licensing.Validator. It uses the offline validator when available, otherwise falls back to the HTTP validator.
func (*CompositeValidator) GetLicenseInfo ¶ added in v0.3.3
func (c *CompositeValidator) GetLicenseInfo() *LicenseInfo
GetLicenseInfo implements licensing.Validator. It returns the offline license info when available (non-nil), otherwise falls back to the HTTP validator.
func (*CompositeValidator) Validate ¶ added in v0.3.3
func (c *CompositeValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)
Validate implements licensing.Validator. It tries the offline validator first; if the result is valid it is returned immediately. Otherwise it falls back to the HTTP validator.
func (*CompositeValidator) ValidatePlugin ¶ added in v0.3.3
func (c *CompositeValidator) ValidatePlugin(pluginName string) error
ValidatePlugin implements plugin.LicenseValidator. It delegates to the offline validator, which performs the authoritative check without network calls.
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 OfflineValidator ¶ added in v0.3.3
type OfflineValidator struct {
// contains filtered or unexported fields
}
OfflineValidator validates a license token using a local Ed25519 public key, with no network calls required after construction.
func NewOfflineValidator ¶ added in v0.3.3
func NewOfflineValidator(publicKeyPEM []byte, tokenStr string) (*OfflineValidator, error)
NewOfflineValidator parses publicKeyPEM and tokenStr, verifies the token signature, and returns an OfflineValidator ready for use.
func (*OfflineValidator) CanLoadPlugin ¶ added in v0.3.3
func (v *OfflineValidator) CanLoadPlugin(tier string) bool
CanLoadPlugin returns true when the given plugin tier is permitted by the license. Core and community plugins are always allowed. Premium plugins require a professional or enterprise tier that is not expired.
func (*OfflineValidator) CheckFeature ¶ added in v0.3.3
func (v *OfflineValidator) CheckFeature(feature string) bool
CheckFeature implements licensing.Validator.
func (*OfflineValidator) GetLicenseInfo ¶ added in v0.3.3
func (v *OfflineValidator) GetLicenseInfo() *LicenseInfo
GetLicenseInfo implements licensing.Validator. Returns nil if the token is expired.
func (*OfflineValidator) Validate ¶ added in v0.3.3
func (v *OfflineValidator) Validate(_ context.Context, key string) (*ValidationResult, error)
Validate implements licensing.Validator. It returns a valid result when key matches the stored token string, and an invalid result otherwise.
func (*OfflineValidator) ValidatePlugin ¶ added in v0.3.3
func (v *OfflineValidator) ValidatePlugin(pluginName string) error
ValidatePlugin implements plugin.LicenseValidator. It returns an error if the token is expired, the tier is not professional or enterprise, or the plugin name is not listed in the token's feature set.
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.