Repository navigation
feat: send the entitlement window, warning threshold and grant allowance - #5
Merged
Merged
Conversation
EntitlementInput gains ResetPeriod, ResetAnchor, WarningThresholdPercent and the sale-unit trio, with constants for the reset periods and anchors. Licenses.AssociateEntitlement and UpdateEntitlement take an optional WithOveragePercent. The two bodies declare these fields and internal/gen already reads them back, but no input could send them. Both PUTs replace rather than patch, so the gap was more than missing features: - Entitlements.Update failed on every periodic entitlement: once a reset period is set, the API refuses an update that does not carry it back, 400 UpdateEntitlement.ImmutableResetPeriod. - Entitlements.Update turned the warning threshold off and cleared the sale unit on every call. - Licenses.UpdateEntitlement turned every soft limit into a hard one: an omitted allowance is the server's default, 0 for a finite value. Without the option the grant bodies are byte for byte what they were, so every call site compiles and behaves as before. The doc comments say what each PUT does with an omitted field. TestEntitlementAndGrantWritesReachEveryWritableKey reads the body keys off the generated request types, so a field the spec adds to these bodies fails the tests until an input can send it. Signed-off-by: Alexandre Bergere <alexandre.bergere@kaiten.sh> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 10, 2026
Signed-off-by: Alexandre Bergere <alexandre.bergere@kaiten.sh> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fuzcap
approved these changes
Oct 12, 2026
| } | ||
|
|
||
| // jsonKeys returns the JSON names of a generated struct's fields, sorted. | ||
| func jsonKeys(t *testing.T, structType reflect.Type) []string { |
Contributor
There was a problem hiding this comment.
this could be moved up to a common go package maybe
Alex (Alexkuva)
added a commit
to kaitencloud/cli
that referenced
this pull request
Oct 13, 2026
The API replaces an entitlement or a grant with what it is sent, and the two update commands sent only what their flags held: - `entitlements update --description ...` reset the warning threshold, the icon, the unit and sale-unit labels, userFacing and the display order, and on a periodic entitlement it was refused outright (400 UpdateEntitlement.ImmutableResetPeriod): the window has to be sent back. - `licenses entitlements update --number ...` turned a soft limit into a hard one, since the API derives an omitted allowance from the value. With inline flags, `entitlements update` now reads the entitlement first and sends back every field the flags do not name; --name is no longer required there. --file and --payload are still sent as written. `licenses entitlements update` reads the grant and keeps its allowance when the new value is a finite number, unless --overage-percent gives one. New flags, on create and update: --reset-period, --reset-anchor, --warning-threshold-percent, --icon, --unit-singular, --unit-plural, --sale-unit-singular, --sale-unit-plural, --sale-unit-factor, --user-facing and --display-order; an empty label or icon removes it. --overage-percent on `licenses entitlements associate` and `update`. This needs kaitencloud/sdk-go#5, which adds these fields and the allowance to the SDK: go.mod is pinned to its commit until it is tagged v0.1.0. Signed-off-by: Alexandre Bergere <alexandre.bergere@kaiten.sh> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR change?
EntitlementInputgainsResetPeriod,ResetAnchor,WarningThresholdPercentand the sale-unit trio (SaleUnitSingular,SaleUnitPlural,SaleUnitFactor), withEntitlementResetPeriod*andEntitlementResetAnchor*constants.Licenses.AssociateEntitlementandLicenses.UpdateEntitlementtake an optional...LicenseEntitlementOption.WithOveragePercent(n)sends the grant'slimitCapExceededOveragePercent.EntitlementInput,Entitlements.UpdateandLicenses.UpdateEntitlement, and the README, say what eachPUTdoes with an omitted field.Why?
The Core request bodies declare these fields and
internal/genalready reads them back, but no input could send them. BothPUTs replace rather than patch, so the gap was a set of bugs and not only missing features:Entitlements.Updateon a periodic entitlementUpdateEntitlement.ImmutableResetPeriod: the API reads an omitted period as an attempt to remove itEntitlements.Updateon any entitlementLicenses.UpdateEntitlementon a soft limitIt is also what keeps a dataset seeded over the API from matching the OSS
demoprofile: the monthly window onmonthly-orders, and the per-License allowances of 0, 10 and 20 %. The other SDKs already have all of this. sdk-python 1.0.0 exposesreset_period,reset_anchor,warning_threshold_percent, the sale units andoverage_percent;@kaitencloud/servergets them through its generatedEntitlementWritableandLicenseEntitlementWritable.Server behavior this is written against, from kaiten
main(c04b6b86):entitlements/updateentitlement/handler.go: the immutability checks, and an absent threshold resets to 0.entitlement.sql,UpdateEntitlement:COALESCEon the window only; every other optional column is overwritten.licenses/associateentitlementwithlicense/repository.go,resolveOveragePercent: the default is derived from the value, and -1 is accepted exactly when the value is unlimited. The update path is the same, with 400…InvalidLimitCapExceededOveragePercent.pkg/apierrors:KindValidationanswers 400.Compatibility
task release:check(gorelease) reports:LicenseEntitlementOptionandWithOveragePercent.Without the option, the grant bodies are byte for byte what they were (pinned by
TestGrantWritesRenderTheOveragePercentOnlyWhenSet). Consumers checked:kaitencloud/clibuilds against this branch, and every other call site we know of uses the four-argument form.Testing
task test(race, shuffle),task lint(0 issues),task fmt(no change),task deadcode.TestRequestBodiesMatchTheirSpecBodies: six new cases, covering a periodic entitlement's create and update, and a grant's associate and update with and without an allowance.TestEntitlementAndGrantWritesReachEveryWritableKey.gen.CreateEntitlementJSONRequestBodyand the three other request types, minus the spec's readOnly fields, so a regenerated client with a new writable key fails until an input sends it.warningThresholdPercentfrom the update payload fails it.TestEntitlementWritesRenderTheWindowAndThresholdOnlyWhenSet, plusTestEntitlementUpdateCarriesThePeriodBackfor the Get-then-Update round trip.TestGrantWritesRenderTheOveragePercentOnlyWhenSet: 0 and -1 are rendered, a nil option is skipped, the last option wins.After merge
Tag
v0.1.0(there is no release workflow, so the tag is the release). Then bump the consumers, the CLI among them. It merges cleanly with #1 (feat/billing).Checklist
CONTRIBUTING.md.Signed-off-byline.🤖 Generated with Claude Code · ✅ Tested and approved by Alex (@Alexkuva), maintainer