MCPcopy Index your code
hub / github.com/coder/coder / AddFeature

Method AddFeature

codersdk/deployment.go:524–547  ·  view source on GitHub ↗

AddFeature will add the feature to the entitlements iff it expands the set of features granted by the entitlements. If it does not, it will be ignored and the existing feature with the same name will remain. Features that abide by usage period constraints should have the following fields set or the

(name FeatureName, add Feature)

Source from the content-addressed store, hash-verified

522// limit in grace period merging with a smaller one in an "entitled" state. This
523// could lead to the larger limit being extended as "entitled", which is not correct.
524func (e *Entitlements) AddFeature(name FeatureName, add Feature) {
525 existing, ok := e.Features[name]
526 if !ok {
527 e.Features[name] = add
528 return
529 }
530
531 // If we're trying to add a feature that uses a usage period and it's not
532 // set, then we should not add it.
533 if name.UsesUsagePeriod() {
534 if add.UsagePeriod == nil || add.UsagePeriod.IssuedAt.IsZero() || add.UsagePeriod.Start.IsZero() || add.UsagePeriod.End.IsZero() {
535 return
536 }
537 } else {
538 add.UsagePeriod = nil
539 }
540
541 // Compare the features, keep the one that is "better"
542 comparison := add.Compare(existing)
543 if comparison > 0 {
544 e.Features[name] = add
545 return
546 }
547}
548
549func (c *Client) Entitlements(ctx context.Context) (Entitlements, error) {
550 res, err := c.Request(ctx, http.MethodGet, "/api/v2/entitlements", nil)

Callers 2

LicensesEntitlementsFunction · 0.95
NewFunction · 0.80

Calls 3

UsesUsagePeriodMethod · 0.80
CompareMethod · 0.80
IsZeroMethod · 0.45

Tested by

no test coverage detected