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)
| 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. |
| 524 | func (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 | |
| 549 | func (c *Client) Entitlements(ctx context.Context) (Entitlements, error) { |
| 550 | res, err := c.Request(ctx, http.MethodGet, "/api/v2/entitlements", nil) |
no test coverage detected