validateAndResolveCtx: port ctx validation from go/python SDKs#330
Open
vnykmshr wants to merge 1 commit into
Open
validateAndResolveCtx: port ctx validation from go/python SDKs#330vnykmshr wants to merge 1 commit into
vnykmshr wants to merge 1 commit into
Conversation
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.
Port
ValidateAndResolveCtxfrom the go SDK and_validate_and_resolve_ctxfrom the python SDK to node. The go and python SDKs validate ctx type and map-key format before embedding into JWT claims. Node currently passes ctx through as-is.Changes:
src/service-account/index.ts— addvalidateAndResolveCtxmatching go/python behavior (type-switch on string/bool/number/object, regex^[a-zA-Z0-9_]+$on map keys, empty/undefined = omit)getToken()andgetSignedTokens()claim constructionsrc/error/codes/index.ts—INVALID_CTX_TYPE,INVALID_CTX_MAP_KEYsrc/error/messages/index.ts— error messages matching existing formattest/service-account/token.test.js— 8 test cases covering valid/invalid/edge valuesjwt.signstripsundefinedvalues from claims, so{ ctx: undefined }produces the same JWT as omitting ctx entirely — no conditional spread needed at the call site.Go reference:
v2/internal/helpers/helpers.go:ValidateAndResolveCtxPython reference:
skyflow/service_account/_utils.py:_validate_and_resolve_ctx