license
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package license provides the license parsing and validation logic for Coderd.Licensing in Coderd defines what features are allowed to be used in agiven deployment. Without a license, or with a license that grants 0 features,Coderd will refuse to execute some feature code paths. These features aretypically gated with a middleware that checks the license before allowingthe http request to proceed.
Terms:
- FeatureName: A specific functionality that Coderd provides, such asexternal provisioners.
- Feature: Entitlement definition for a FeatureName. A feature can be:
- "entitled": The feature is allowed to be used by the deployment.
- "grace period": The feature is allowed to be used by the deployment,but the license is expired. There is a grace periodbefore the feature is disabled.
- "not entitled": The deployment is not allowed to use the feature.Either by expiration, or by not being includedin the license.A feature can also be "disabled" that prevents usage of the featureeven if entitled. This is usually a deployment configuration option.
- License: A signed JWT that lists the features that are allowed to be used bya given deployment. A license can have extra properties like,`IsTrial`, `DeploymentIDs`, etc that can be used to further defineusage of the license.
- Entitlements: A parsed set of licenses. Yes you can have more than 1 licenseon a deployment! Entitlements will enumerate all features thatare allowed to be used.
Index¶
- Constants
- Variables
- func Entitlements(ctx context.Context, db database.Store, replicaCount int, ...) (codersdk.Entitlements, error)
- func LicensesEntitlements(now time.Time, licenses []database.License, ...) (codersdk.Entitlements, error)
- func ParseRaw(l string, keys map[string]ed25519.PublicKey) (jwt.MapClaims, error)
- type Claims
- type FeatureArguments
- type Features
- type MetricsCollector
Constants¶
const (CurrentVersion = 3HeaderKeyID = "kid"AccountTypeSalesforce = "salesforce"VersionClaim = "version")
Variables¶
var (ValidMethods = []string{"EdDSA"}ErrInvalidVersion =xerrors.New("license must be version 3")ErrMissingKeyID =xerrors.Errorf("JOSE header must contain %s",HeaderKeyID)ErrMissingLicenseExpires =xerrors.New("license missing license_expires")ErrMissingExp =xerrors.New("exp claim missing or not parsable")ErrMultipleIssues =xerrors.New("license has multiple issues; contact support"))
Functions¶
funcEntitlements¶
func Entitlements(ctxcontext.Context,dbdatabase.Store,replicaCountint,externalAuthCountint,keys map[string]ed25519.PublicKey,enablements map[codersdk.FeatureName]bool,) (codersdk.Entitlements,error)
Entitlements processes licenses to return whether features are enabled or not.
funcLicensesEntitlements¶added inv2.14.0
func LicensesEntitlements(nowtime.Time,licenses []database.License,enablements map[codersdk.FeatureName]bool,keys map[string]ed25519.PublicKey,featureArgumentsFeatureArguments,) (codersdk.Entitlements,error)
LicensesEntitlements returns the entitlements for licenses. Entitlements aremerged from all licenses and the highest entitlement is used for each feature.Arguments:
now: The time to use for checking license expiration.license: The license to check.enablements: Features can be explicitly disabled by the deployment even if the license has the feature entitled. Features can also have the 'feat.AlwaysEnable()' return true to disallow disabling.featureArguments: Additional arguments required by specific features.
Types¶
typeClaims¶
type Claims struct {jwt.RegisteredClaims// LicenseExpires is the end of the legit license term, and the start of the grace period, if// there is one. The standard JWT claim "exp" (ExpiresAt in jwt.RegisteredClaims, above) is// the end of the grace period (identical to LicenseExpires if there is no grace period).// The reason we use the standard claim for the end of the grace period is that we want JWT// processing libraries to consider the token "valid" until then.LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`AccountTypestring `json:"account_type,omitempty"`AccountIDstring `json:"account_id,omitempty"`// DeploymentIDs enforces the license can only be used on a set of deployments.DeploymentIDs []string `json:"deployment_ids,omitempty"`Trialbool `json:"trial"`FeatureSetcodersdk.FeatureSet `json:"feature_set"`// AllFeatures represents 'FeatureSet = FeatureSetEnterprise'// Deprecated: AllFeatures is deprecated in favor of FeatureSet.AllFeaturesbool `json:"all_features,omitempty"`Versionuint64 `json:"version"`FeaturesFeatures `json:"features"`RequireTelemetrybool `json:"require_telemetry,omitempty"`}
funcParseClaims¶
ParseClaims validates a raw JWT, and if valid, returns the claims. Ifunparsable or invalid, it returns an error
funcParseClaimsIgnoreNbf¶added inv2.14.3
ParseClaimsIgnoreNbf validates a raw JWT, but ignores `nbf` claim. If otherwise valid, it returnsthe claims. If unparsable or invalid, it returns an error. Ignoring the `nbf` (not before) isuseful to determine if a JWT _will_ become valid at any point now or in the future.
typeFeatureArguments¶added inv2.14.0
typeFeatures¶
type Features map[codersdk.FeatureName]int64
typeMetricsCollector¶added inv2.3.1
type MetricsCollector struct {Entitlements *entitlements.Set}
func (*MetricsCollector)Collect¶added inv2.3.1
func (mc *MetricsCollector) Collect(metricsCh chan<-prometheus.Metric)
func (*MetricsCollector)Describe¶added inv2.3.1
func (*MetricsCollector) Describe(descCh chan<- *prometheus.Desc)