feat: add is-allowed API to JS, Python, and Go SDKs#221
feat: add is-allowed API to JS, Python, and Go SDKs#221
Conversation
Three new endpoints across all SDKs:
- checkCvmIsAllowed: POST /cvms/{cvmId}/is-allowed
- checkAppIsAllowed: POST /apps/{appId}/is-allowed
- checkAppCvmsIsAllowed: POST /apps/{appId}/cvms/is-allowed (batch)
📋 Check Results✨ JS SDK - Code FormattingShow format check results🔍 JS SDK - TypeScript Type CheckShow type check output🧪 JS SDK - Test ResultsShow test output📝 JS SDK - Lint CheckShow lint results🌐 JS SDK - Browser CompatibilityShow browser test results🌐 Browser Compatibility ReportBrowser compatibility tests completed across:
The SDK has been verified to work in modern browser environments. Check run: https://github.com/Phala-Network/phala-cloud/actions/runs/23397583430 |
| class CheckCvmIsAllowedRequest(CloudModel): | ||
| cvm_id: str = Field(..., alias="cvmId") |
There was a problem hiding this comment.
Bug: The new request models lack populate_by_name=True, causing them to reject idiomatic snake_case arguments and only accept camelCase aliases, which will lead to ValidationError for SDK users.
Severity: HIGH
Suggested Fix
Update the base class for CheckCvmIsAllowedRequest, CheckAppIsAllowedRequest, and CheckAppCvmsIsAllowedRequest to one that includes populate_by_name=True in its Pydantic model configuration, similar to the existing _AliasModel. Alternatively, add ConfigDict(populate_by_name=True) to each of the new models directly.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: python/src/phala_cloud/models/cvms.py#L231-L232
Potential issue: The new request models `CheckCvmIsAllowedRequest`,
`CheckAppIsAllowedRequest`, and `CheckAppCvmsIsAllowedRequest` inherit from
`CloudModel`, which does not set `populate_by_name=True` in its Pydantic configuration.
In Pydantic v2, this means that fields with an alias, such as `cvm_id: str = Field(...,
alias="cvmId")`, can only be populated using the alias name (`"cvmId"`). Consequently,
when SDK users attempt to instantiate these models using idiomatic Python snake_case
arguments (e.g., `cvm_id="..."`), a `ValidationError` will be raised at runtime,
breaking the functionality of the associated API client methods.
Did we get this right? 👍 / 👎 to inform future reviews.
Summary
Three new actions across all three SDKs for checking on-chain DStack App contract allowance:
checkCvmIsAllowed—POST /cvms/{cvmId}/is-allowed(single CVM, optional param overrides)checkAppIsAllowed—POST /apps/{appId}/is-allowed(pure contract query)checkAppCvmsIsAllowed—POST /apps/{appId}/cvms/is-allowed(batch all CVMs under app)JS (
sdks/js/)src/actions/cvms/check_cvm_is_allowed.tssrc/actions/apps/check_app_is_allowed.tssrc/actions/apps/check_app_cvms_is_allowed.tsIsAllowedResultSchema/IsAllowedResulttypePython (
sdks/python/)models/cvms.py:IsAllowedResult,AppCvmsBatchIsAllowedResponse, request typesfull_client.pywith safe variantsGo (
sdks/go/)types_cvms.go:IsAllowedResult,CheckCvmIsAllowedRequest,AppCvmsBatchIsAllowedResponsecvms.goandapps.goTest plan
go build+go vet+go testpass