Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateJWT(claims Claims, privateKey ed25519.PrivateKey) (string, error)
- func LoadPublicKeyFromFile(path string) (ed25519.PublicKey, error)
- func RequireFeature(license *License, feature string) error
- type Claims
- type License
- func (l *License) CustomerID() string
- func (l *License) DaysUntilExpiry() int
- func (l *License) ExpiresAt() time.Time
- func (l *License) Features() []string
- func (l *License) GraceDaysRemaining() int
- func (l *License) HasFeature(feature string) bool
- func (l *License) IsExpired() bool
- func (l *License) IsExpiredAt(t time.Time) bool
- func (l *License) IsInGracePeriod() bool
- func (l *License) IsInGracePeriodAt(t time.Time) bool
- func (l *License) LicenseType() string
- func (l *License) MaxNodes() int
- type Validator
- type ValidatorOption
Constants ¶
const ( FeatureHA = "ha" // High Availability clustering FeatureKubernetes = "kubernetes" // Kubernetes integration FeatureAWS = "aws" // AWS integration FeatureGCP = "gcp" // GCP integration FeatureTerraform = "terraform" // Terraform provider )
Feature constants for license gating
const DefaultGracePeriod = 7 * 24 * time.Hour // 7 days
DefaultGracePeriod is the default grace period after license expiration
Variables ¶
var ( // ErrLicenseExpired is returned when a license has expired beyond its grace period ErrLicenseExpired = errors.New("license expired") // ErrLicenseInvalid is returned when a license cannot be parsed or verified ErrLicenseInvalid = errors.New("invalid license") // ErrFeatureNotLicensed is returned when attempting to use an unlicensed feature ErrFeatureNotLicensed = errors.New("feature not licensed") // ErrNoLicenseFile is returned when no license file is specified or found ErrNoLicenseFile = errors.New("no license file") )
Functions ¶
func GenerateJWT ¶
func GenerateJWT(claims Claims, privateKey ed25519.PrivateKey) (string, error)
GenerateJWT creates a signed JWT from claims using the provided private key This is primarily used for license generation tooling
func LoadPublicKeyFromFile ¶
LoadPublicKeyFromFile loads a public key from a file This can be used for custom deployments with their own keys
func RequireFeature ¶
RequireFeature validates that a license has a specific feature
Types ¶
type Claims ¶
type Claims struct {
// Standard JWT claims
Issuer string `json:"iss"` // "neuwerk.io"
Subject string `json:"sub"` // License holder identifier
ExpiresAt int64 `json:"exp"` // Expiration timestamp
IssuedAt int64 `json:"iat"` // Issuance timestamp
NotBefore int64 `json:"nbf,omitempty"` // Not valid before timestamp
JTI string `json:"jti,omitempty"` // JWT ID (unique identifier)
// Custom claims
Features []string `json:"features"` // Enabled features: ["ha", "kubernetes"]
CustomerID string `json:"customer_id,omitempty"` // Customer identifier
MaxNodes int `json:"max_nodes,omitempty"` // Max cluster nodes (0 = unlimited)
LicenseType string `json:"license_type,omitempty"` // "trial", "commercial", "enterprise"
}
Claims represents the JWT claims structure for Neuwerk licenses
type License ¶
type License struct {
Claims Claims
Raw string // Original JWT string for debugging
GracePeriod time.Duration // Configurable grace period
// contains filtered or unexported fields
}
License represents a validated Neuwerk license
func (*License) CustomerID ¶
CustomerID returns the customer identifier
func (*License) DaysUntilExpiry ¶
DaysUntilExpiry returns days until license expires (negative if already expired)
func (*License) GraceDaysRemaining ¶
GraceDaysRemaining returns the number of grace period days remaining Returns 0 if not in grace period or if license is not expired
func (*License) HasFeature ¶
HasFeature checks if the license includes a specific feature
func (*License) IsExpired ¶
IsExpired returns true if the license is expired beyond the grace period
func (*License) IsExpiredAt ¶
IsExpiredAt checks expiration at a specific time (for testing)
func (*License) IsInGracePeriod ¶
IsInGracePeriod returns true if the license is expired but still within grace period
func (*License) IsInGracePeriodAt ¶
IsInGracePeriodAt checks grace period status at a specific time
func (*License) LicenseType ¶
LicenseType returns the license type (trial, commercial, enterprise)
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles license validation
func NewValidator ¶
func NewValidator(opts ...ValidatorOption) (*Validator, error)
NewValidator creates a new license validator
func (*Validator) LoadFromFile ¶
LoadFromFile loads and validates a license from a file path
type ValidatorOption ¶
type ValidatorOption func(*Validator)
ValidatorOption configures a Validator
func WithGracePeriod ¶
func WithGracePeriod(d time.Duration) ValidatorOption
WithGracePeriod sets a custom grace period
func WithPublicKey ¶
func WithPublicKey(key ed25519.PublicKey) ValidatorOption
WithPublicKey sets a custom public key (for testing or custom deployments)