-
Notifications
You must be signed in to change notification settings - Fork 6
feat: two-phase CVM deploy support (prepareOnly + commitCvmUpdate) #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
38d6bf4
feat(sdk): add prepareOnly support to patchCvm and new commitCvmUpdat…
Leechael 99edfc0
feat(cli): add --prepare-only and --commit flags for multisig CVM upd…
Leechael f874b65
fix(cli): warn when --prepare-only used on non-on-chain KMS CVM
Leechael 6a4abb8
fix(cli): add missing return after --prepare-only warning on non-on-c…
Leechael 39bdd7a
fix(cli): --commit mode no longer requires API key
Leechael 732cbb8
fix(cli): fix --prepare-only output formatting for shell continuation
Leechael 6de7e4a
feat(cli): show chain ID and block explorer URL in --prepare-only output
Leechael 62e4122
fix(cli): add 0x prefix to compose hash in --prepare-only output
Leechael 36da5c3
Merge pull request #218 from Phala-Network/fix/cli-prepare-only-forma…
Leechael a84d43a
Merge pull request #219 from Phala-Network/fix/cli-prepare-only-chain…
Leechael e2bd3ad
Merge pull request #220 from Phala-Network/fix/cli-compose-hash-prefix
Leechael 4cb7398
fix(cli): 0x prefix on explorer URL, expired token hint
Leechael f98f614
feat: display on-chain status in --prepare-only output
Leechael 79e695f
fix(cli): fix --prepare-only output indentation, make --transaction-h…
Leechael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { z } from "zod"; | ||
| import { CvmIdObjectSchema, CvmIdSchema, refineCvmId } from "../../types/cvm_id"; | ||
| import { defineAction } from "../../utils/define-action"; | ||
|
|
||
| /** | ||
| * Commit CVM update (token-based, no auth required) | ||
| * | ||
| * Completes a two-phase CVM update using a one-time commit token generated | ||
| * during a prepare-only PATCH request. This enables multisig workflows where | ||
| * the on-chain signer is different from the original API caller. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { createClient, patchCvm, commitCvmUpdate } from '@phala/cloud' | ||
| * | ||
| * const client = createClient() | ||
| * | ||
| * // Phase 1: prepare-only | ||
| * const result = await patchCvm(client, { | ||
| * id: 'my-cvm', | ||
| * docker_compose_file: newComposeYaml, | ||
| * prepareOnly: true, | ||
| * }) | ||
| * | ||
| * if (result.requiresOnChainHash && result.commitToken) { | ||
| * // ... multisig approval happens externally ... | ||
| * | ||
| * // Phase 2: commit with token | ||
| * const committed = await commitCvmUpdate(client, { | ||
| * id: 'my-cvm', | ||
| * token: result.commitToken, | ||
| * composeHash: result.composeHash, | ||
| * transactionHash: '0x...', | ||
| * }) | ||
| * console.log(`Update started: ${committed.correlationId}`) | ||
| * } | ||
| * ``` | ||
| */ | ||
|
|
||
| export const CommitCvmUpdateRequestSchema = refineCvmId( | ||
| CvmIdObjectSchema.extend({ | ||
| token: z.string().describe("One-time commit token from prepare-only flow"), | ||
| composeHash: z.string().describe("Compose hash from Phase 1 response"), | ||
| transactionHash: z.string().describe("Transaction hash proving on-chain registration"), | ||
| }), | ||
| ); | ||
|
|
||
| export type CommitCvmUpdateRequest = z.input<typeof CommitCvmUpdateRequestSchema>; | ||
|
|
||
| const CommitCvmUpdateResultSchema = z.object({ | ||
| correlationId: z.string(), | ||
| status: z.string(), | ||
| }); | ||
|
|
||
| export type CommitCvmUpdateResult = z.infer<typeof CommitCvmUpdateResultSchema>; | ||
|
|
||
| const { action: commitCvmUpdate, safeAction: safeCommitCvmUpdate } = defineAction< | ||
| CommitCvmUpdateRequest, | ||
| typeof CommitCvmUpdateResultSchema | ||
| >(CommitCvmUpdateResultSchema, async (client, request) => { | ||
| const parsed = CommitCvmUpdateRequestSchema.parse(request); | ||
| const { cvmId } = CvmIdSchema.parse(parsed); | ||
|
|
||
| const response = await client.post<{ | ||
| correlation_id: string; | ||
| status: string; | ||
| }>(`/cvms/${cvmId}/commit-update`, { | ||
| token: parsed.token, | ||
| compose_hash: parsed.composeHash, | ||
| transaction_hash: parsed.transactionHash, | ||
| }); | ||
|
|
||
| return { | ||
| correlationId: response.correlation_id, | ||
| status: response.status, | ||
| }; | ||
| }); | ||
|
|
||
| export { commitCvmUpdate, safeCommitCvmUpdate }; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.