licensing

package
v0.180.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package licensing implements WunderGraph license management functions

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoPublicKey indicates no public key is available to validate licenses
	ErrNoPublicKey = errors.New("public key for license signature is not available")
	// ErrNoLicenseFound is returned when trying to load a stored license and no data is found
	ErrNoLicenseFound = errors.New("no license found")
	// ErrLicenseExpired is returned from Manager.Check() when the stored license is expired
	ErrLicenseExpired = errors.New("license is expired")
)

Functions

This section is empty.

Types

type ErrInvalidLicense

type ErrInvalidLicense struct {
	Err error
}

ErrInvalidLicense signals that the underlying error was caused by an invalid license key

func (*ErrInvalidLicense) Error

func (e *ErrInvalidLicense) Error() string

func (*ErrInvalidLicense) Unwrap

func (e *ErrInvalidLicense) Unwrap() error

type License

type License struct {
	// ID is the unique license ID
	ID uuid.UUID `json:"u"`
	// Email used to register the license
	Email string `json:"e"`
	// ExpiresAt is the license expiration date
	ExpiresAt time.Time `json:"exp"`
}

License represents decoded license data

func (*License) IsExpired

func (lic *License) IsExpired() bool

IsExpired returns true iff the license expiration is in the past

func (*License) Print

func (lic *License) Print(w io.Writer) (int, error)

Print writes a human-readable description of the license to the given io.Writer

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager stores and loads license from the system. To initialize a Manager, call NewManager()

func NewManager

func NewManager(publicKey string) *Manager

NewManager initializes a new Manager with the given public key

func (*Manager) LicenseCheck

func (m *Manager) LicenseCheck(wunderGraphDir string, exit func(), w io.Writer) error

func (*Manager) Read

func (m *Manager) Read() (*License, error)

Read reads the stored license, if any. If no license is found, it returns ErrNoLicenseFound. If the license is invalid, the error type will be ErrInvalidLicense. Note that no expiration checks are performed by Read().

func (*Manager) Remove

func (m *Manager) Remove() error

Remove removes an existing license from the store. If there's no license stored, it returns an error.

func (*Manager) Validate

func (m *Manager) Validate() (*License, error)

Validate reads the stored license using Manager.Read() and checks whether it's expired. If the license is not found, not valid or expired it returns an error. Otherwise, it returns the license.

func (*Manager) Write

func (m *Manager) Write(licenseKey string) (*License, error)

Write validates the given licenseKey and writes it to disk. If the license is invalid or if the data can't be written it returns an error. If there's already a license stored, it gets overwritten.

Jump to

Keyboard shortcuts

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