license

package
v1.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const DefaultGracePeriod = 7 * 24 * time.Hour // 7 days

DefaultGracePeriod is the default grace period after license expiration

Variables

View Source
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

func LoadPublicKeyFromFile(path string) (ed25519.PublicKey, error)

LoadPublicKeyFromFile loads a public key from a file This can be used for custom deployments with their own keys

func RequireFeature

func RequireFeature(license *License, feature string) error

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

func (l *License) CustomerID() string

CustomerID returns the customer identifier

func (*License) DaysUntilExpiry

func (l *License) DaysUntilExpiry() int

DaysUntilExpiry returns days until license expires (negative if already expired)

func (*License) ExpiresAt

func (l *License) ExpiresAt() time.Time

ExpiresAt returns the license expiration time

func (*License) Features

func (l *License) Features() []string

Features returns the list of features included in the license

func (*License) GraceDaysRemaining

func (l *License) GraceDaysRemaining() int

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

func (l *License) HasFeature(feature string) bool

HasFeature checks if the license includes a specific feature

func (*License) IsExpired

func (l *License) IsExpired() bool

IsExpired returns true if the license is expired beyond the grace period

func (*License) IsExpiredAt

func (l *License) IsExpiredAt(t time.Time) bool

IsExpiredAt checks expiration at a specific time (for testing)

func (*License) IsInGracePeriod

func (l *License) IsInGracePeriod() bool

IsInGracePeriod returns true if the license is expired but still within grace period

func (*License) IsInGracePeriodAt

func (l *License) IsInGracePeriodAt(t time.Time) bool

IsInGracePeriodAt checks grace period status at a specific time

func (*License) LicenseType

func (l *License) LicenseType() string

LicenseType returns the license type (trial, commercial, enterprise)

func (*License) MaxNodes

func (l *License) MaxNodes() int

MaxNodes returns the maximum allowed cluster nodes (0 = unlimited)

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

func (v *Validator) LoadFromFile(path string) (*License, error)

LoadFromFile loads and validates a license from a file path

func (*Validator) ParseAndValidate

func (v *Validator) ParseAndValidate(tokenString string) (*License, error)

ParseAndValidate parses a JWT string and validates it

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL