license

package
v0.0.0-...-bf444b6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultValidityPeriod = 365 // default validity period in days

	FeatureComponents        Feature = "components"         // allow components
	FeatureCustomStatuses    Feature = "custom_statuses"    // allow custom statuses
	FeatureCustomFields      Feature = "custom_fields"      // allow custom fields
	FeatureMultipleAssignees Feature = "multiple_assignees" // allow multiple assignees per task
	FeatureReleases          Feature = "releases"           // allow releases

	QuotaDocuments     Quota = "documents"     // number of documents
	QuotaNamespaces    Quota = "namespaces"    // number of namespaces
	QuotaOrganizations Quota = "organizations" // number of organizations
	QuotaProjects      Quota = "projects"      // number of projects
	QuotaRoles         Quota = "roles"         // number of roles
	QuotaUsers         Quota = "users"         // number of users
)

Variables

View Source
var (
	ErrLicenseExpired          = errors.New("license expired")                     // license is expired
	ErrLicenseInvalid          = errors.New("invalid or expired license provided") // license is expired
	ErrLicenseInvalidSignature = errors.New("invalid license signature")           // license signature is invalid
	ErrNoLicense               = errors.New("no license provided")                 // no license provided

	// DefaultFeatures is the default set of features for a license.
	DefaultFeatures = []Feature{
		FeatureComponents,
		FeatureCustomStatuses,
		FeatureCustomFields,
		FeatureMultipleAssignees,
		FeatureReleases,
	}

	// DefaultQuotas is the default set of quotas for a license.
	DefaultQuotas = map[Quota]uint32{
		QuotaDocuments:     10,
		QuotaNamespaces:    1,
		QuotaOrganizations: 1,
		QuotaProjects:      10,
		QuotaRoles:         5,
		QuotaUsers:         5,
	}
)

Functions

This section is empty.

Types

type Feature

type Feature string

Feature represents a license feature.

type License

type License struct {
	ID           xid.ID           `json:"id"`           // license id
	Email        string           `json:"email"`        // organization email
	Organization string           `json:"organization"` // organization name
	Quotas       map[Quota]uint32 `json:"quotas"`       // quotas
	Features     []Feature        `json:"features"`     // features
	ExpiresAt    time.Time        `json:"expires_at"`   // expiration time
}

License represents the license information.

The license information is parsed from the license key. The license key is generated by the license server. The license is valid for a specific organization for a given period.

The license is validated locally by the hardcoded public key. The public key is used to verify the signature of the license key.

func NewLicense

func NewLicense(licenseKey, pubKey string) (*License, error)

NewLicense validates the license key.

If the license is valid, the validated license is returned. Otherwise, an error is returned.

func (*License) Expired

func (l *License) Expired() bool

Expired returns true if the license is expired.

func (*License) HasFeature

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

HasFeature returns true if the license has the given feature.

func (*License) Valid

func (l *License) Valid() bool

Valid validates the license fields and returns false if any of the required license fields are missing, quotas does not meet minimum expectations, or the license is expired.

func (*License) WithinThreshold

func (l *License) WithinThreshold(quota Quota, value int) bool

WithinThreshold returns true if the given value is within the threshold.

type Quota

type Quota string

Quota represents a license quota.

Jump to

Keyboard shortcuts

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