-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtypes_cvms.go
More file actions
377 lines (335 loc) · 14.8 KB
/
types_cvms.go
File metadata and controls
377 lines (335 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package phala
import "fmt"
// CVMInfo represents CVM information (API version 2026-01-21).
type CVMInfo struct {
ID string `json:"id"`
Name string `json:"name"`
AppID *string `json:"app_id,omitempty"`
VMUUID *string `json:"vm_uuid,omitempty"`
InstanceID *string `json:"instance_id,omitempty"`
Resource CvmResource `json:"resource"`
NodeInfo *NodeRef `json:"node_info,omitempty"`
OS *CvmOsInfo `json:"os,omitempty"`
KMSType *string `json:"kms_type,omitempty"`
KMSInfo *CvmKmsInfo `json:"kms_info,omitempty"`
Status string `json:"status"`
Progress *CvmProgressInfo `json:"progress,omitempty"`
ComposeHash *string `json:"compose_hash,omitempty"`
Gateway *CvmGatewayInfo `json:"gateway,omitempty"`
Services []any `json:"services,omitempty"`
PublicLogs *bool `json:"public_logs,omitempty"`
PublicSysinfo *bool `json:"public_sysinfo,omitempty"`
PublicTcbinfo *bool `json:"public_tcbinfo,omitempty"`
GatewayEnabled *bool `json:"gateway_enabled,omitempty"`
SecureTime *bool `json:"secure_time,omitempty"`
Listed bool `json:"listed"`
StorageFS *string `json:"storage_fs,omitempty"`
Workspace *WorkspaceRef `json:"workspace,omitempty"`
Creator *UserRef `json:"creator,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
AppURL *string `json:"app_url,omitempty"`
BaseImage *string `json:"base_image,omitempty"`
Features []string `json:"features,omitempty"`
Runner *string `json:"runner,omitempty"`
ManifestVer *string `json:"manifest_version,omitempty"`
ComposeFile any `json:"compose_file,omitempty"`
}
// CvmResource holds CVM resource allocation.
type CvmResource struct {
InstanceType *string `json:"instance_type,omitempty"`
VCPU *int `json:"vcpu,omitempty"`
MemoryInGB *float64 `json:"memory_in_gb,omitempty"`
DiskInGB *int `json:"disk_in_gb,omitempty"`
GPUs *int `json:"gpus,omitempty"`
ComputeBillingPrice *string `json:"compute_billing_price,omitempty"`
BillingPeriod *string `json:"billing_period,omitempty"`
}
// CvmOsInfo holds CVM OS information.
type CvmOsInfo struct {
Name *string `json:"name,omitempty"`
Version *string `json:"version,omitempty"`
IsDev *bool `json:"is_dev,omitempty"`
OSImageHash *string `json:"os_image_hash,omitempty"`
}
// CvmKmsInfo holds CVM KMS information.
type CvmKmsInfo struct {
ChainID *int `json:"chain_id,omitempty"`
DstackKmsAddress *string `json:"dstack_kms_address,omitempty"`
DstackAppAddress *string `json:"dstack_app_address,omitempty"`
DeployerAddress *string `json:"deployer_address,omitempty"`
RPCEndpoint *string `json:"rpc_endpoint,omitempty"`
EncryptedEnvPubkey *string `json:"encrypted_env_pubkey,omitempty"`
}
// CvmProgressInfo holds CVM progress information.
type CvmProgressInfo struct {
Target *string `json:"target,omitempty"`
StartedAt *string `json:"started_at,omitempty"`
CorrelationID *string `json:"correlation_id,omitempty"`
}
// CvmGatewayInfo holds CVM gateway information.
type CvmGatewayInfo struct {
BaseDomain *string `json:"base_domain,omitempty"`
CNAME *string `json:"cname,omitempty"`
}
// NodeRef is a reference to a node.
type NodeRef struct {
ObjectType string `json:"object_type"`
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Region *string `json:"region,omitempty"`
DeviceID *string `json:"device_id,omitempty"`
PPID *string `json:"ppid,omitempty"`
Status *string `json:"status,omitempty"`
Version *string `json:"version,omitempty"`
}
// UserRef is a reference to a user.
type UserRef struct {
ObjectType string `json:"object_type"`
ID *string `json:"id,omitempty"`
Username *string `json:"username,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
}
// WorkspaceRef is a reference to a workspace.
type WorkspaceRef struct {
ObjectType string `json:"object_type"`
ID string `json:"id"`
Name string `json:"name"`
Slug *string `json:"slug,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
}
// CvmRef is a reference to a CVM.
type CvmRef struct {
ObjectType string `json:"object_type"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
AppID *string `json:"app_id,omitempty"`
VMUUID *string `json:"vm_uuid,omitempty"`
}
// PaginatedCVMInfos is a paginated list of CVM infos.
type PaginatedCVMInfos = Paginated[CVMInfo]
// GetCVMListOptions holds query parameters for listing CVMs.
type GetCVMListOptions struct {
Page *int `json:"page,omitempty"`
PageSize *int `json:"page_size,omitempty"`
}
// ProvisionCVMRequest is the request body for provisioning a CVM.
type ProvisionCVMRequest struct {
Name string `json:"name"`
InstanceType string `json:"instance_type"`
ComposeFile *ComposeFile `json:"compose_file,omitempty"`
// Optional fields.
VCPU *int `json:"vcpu,omitempty"`
Memory *int `json:"memory,omitempty"`
DiskSize *int `json:"disk_size,omitempty"`
TeepodID *int `json:"teepod_id,omitempty"`
Image *string `json:"image,omitempty"`
KMSType *string `json:"kms_type,omitempty"`
Listed *bool `json:"listed,omitempty"`
Encrypted *bool `json:"encrypted,omitempty"`
SecureTime *bool `json:"secure_time,omitempty"`
}
// ComposeFile represents a compose file configuration.
type ComposeFile struct {
Name string `json:"name"`
DockerComposeFile string `json:"docker_compose_file"`
GatewayEnabled *bool `json:"gateway_enabled,omitempty"`
PreLaunchScript *string `json:"pre_launch_script,omitempty"`
EncryptedEnv *string `json:"encrypted_env,omitempty"`
EnvKeys *string `json:"env_keys,omitempty"`
}
// ProvisionCVMResponse is the response from provisioning a CVM.
type ProvisionCVMResponse struct {
AppID string `json:"app_id"`
ComposeHash string `json:"compose_hash"`
AppEnvEncryptPubkey string `json:"app_env_encrypt_pubkey,omitempty"`
KMSInfo *CvmKmsInfo `json:"kms_info,omitempty"`
FMSPC string `json:"fmspc,omitempty"`
DeviceID string `json:"device_id,omitempty"`
OSImageHash string `json:"os_image_hash,omitempty"`
InstanceType string `json:"instance_type,omitempty"`
NodeID *int `json:"node_id,omitempty"`
KMSID string `json:"kms_id,omitempty"`
}
// CommitCVMProvisionRequest is the request for committing a CVM provision.
type CommitCVMProvisionRequest struct {
AppID string `json:"app_id"`
ComposeHash string `json:"compose_hash"`
TransactionHash *string `json:"transaction_hash,omitempty"`
}
// CommitCVMProvisionResponse is the response from committing a CVM provision.
type CommitCVMProvisionResponse struct {
ID any `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
// CvmID returns the CVM ID as a string.
func (r *CommitCVMProvisionResponse) CvmID() string {
if r.ID == nil {
return ""
}
return fmt.Sprintf("%v", r.ID)
}
// CVMState represents the state of a CVM.
type CVMState = GenericObject
// CVMStats represents CVM statistics.
type CVMStats = GenericObject
// CVMNetwork represents CVM network information.
type CVMNetwork = GenericObject
// CVMContainersStats represents CVM container statistics.
type CVMContainersStats = GenericObject
// CVMUserConfig represents CVM user configuration.
type CVMUserConfig = GenericObject
// CVMActionResponse is the generic response for CVM lifecycle actions.
type CVMActionResponse struct {
ID any `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
}
// ReplicateCVMOptions holds options for replicating a CVM.
type ReplicateCVMOptions struct {
NodeID *int `json:"node_id,omitempty"`
}
// PatchCVMRequest is the request for patching a CVM (multi-field update).
type PatchCVMRequest struct {
DockerComposeFile *string `json:"docker_compose_file,omitempty"`
PreLaunchScript *string `json:"pre_launch_script,omitempty"`
EncryptedEnv *string `json:"encrypted_env,omitempty"`
EnvKeys *string `json:"env_keys,omitempty"`
PublicSysinfo *bool `json:"public_sysinfo,omitempty"`
PublicLogs *bool `json:"public_logs,omitempty"`
PublicTcbinfo *bool `json:"public_tcbinfo,omitempty"`
GatewayEnabled *bool `json:"gateway_enabled,omitempty"`
SecureTime *bool `json:"secure_time,omitempty"`
Listed *bool `json:"listed,omitempty"`
VCPU *int `json:"vcpu,omitempty"`
Memory *int `json:"memory,omitempty"`
DiskSize *int `json:"disk_size,omitempty"`
InstanceType *string `json:"instance_type,omitempty"`
OSImageName *string `json:"os_image_name,omitempty"`
AllowRestart *bool `json:"allow_restart,omitempty"`
}
// PatchCVMResponse is the response from patching a CVM.
type PatchCVMResponse struct {
RequiresOnChainHash bool `json:"requires_on_chain_hash"`
CorrelationID string `json:"correlation_id,omitempty"`
ComposeHash string `json:"compose_hash,omitempty"`
AppID string `json:"app_id,omitempty"`
DeviceID string `json:"device_id,omitempty"`
KMSInfo *CvmKmsInfo `json:"kms_info,omitempty"`
}
// ConfirmCVMPatchRequest is the request for confirming a CVM patch with on-chain hash.
type ConfirmCVMPatchRequest struct {
ComposeHash string `json:"compose_hash"`
TransactionHash string `json:"transaction_hash"`
}
// CVMAttestation represents CVM attestation data.
type CVMAttestation struct {
Name *string `json:"name,omitempty"`
IsOnline bool `json:"is_online"`
IsPublic bool `json:"is_public"`
Error *string `json:"error,omitempty"`
AppCertificates []Certificate `json:"app_certificates,omitempty"`
TCBInfo *TcbInfo `json:"tcb_info,omitempty"`
ComposeFile *string `json:"compose_file,omitempty"`
}
// Certificate represents a TLS certificate.
type Certificate struct {
Subject CertificateSubject `json:"subject"`
Issuer CertificateIssuer `json:"issuer"`
SerialNumber string `json:"serial_number"`
NotBefore string `json:"not_before"`
NotAfter string `json:"not_after"`
Version string `json:"version"`
Fingerprint string `json:"fingerprint"`
SignatureAlgorithm string `json:"signature_algorithm"`
SANs []string `json:"sans,omitempty"`
IsCA bool `json:"is_ca"`
PositionInChain *int `json:"position_in_chain,omitempty"`
Quote *string `json:"quote,omitempty"`
AppID *string `json:"app_id,omitempty"`
CertUsage *string `json:"cert_usage,omitempty"`
}
// CertificateSubject holds certificate subject fields.
type CertificateSubject struct {
CommonName *string `json:"common_name,omitempty"`
Organization *string `json:"organization,omitempty"`
Country *string `json:"country,omitempty"`
State *string `json:"state,omitempty"`
Locality *string `json:"locality,omitempty"`
}
// CertificateIssuer holds certificate issuer fields.
type CertificateIssuer struct {
CommonName *string `json:"common_name,omitempty"`
Organization *string `json:"organization,omitempty"`
Country *string `json:"country,omitempty"`
}
// TcbInfo holds TCB info fields.
type TcbInfo struct {
MRTD string `json:"mrtd"`
RootfsHash *string `json:"rootfs_hash,omitempty"`
RTMR0 string `json:"rtmr0"`
RTMR1 string `json:"rtmr1"`
RTMR2 string `json:"rtmr2"`
RTMR3 string `json:"rtmr3"`
EventLog []EventLog `json:"event_log,omitempty"`
AppCompose string `json:"app_compose"`
}
// EventLog holds an event log entry.
type EventLog struct {
IMR int `json:"imr"`
EventType int `json:"event_type"`
Digest string `json:"digest"`
Event string `json:"event"`
EventPayload string `json:"event_payload"`
}
// CVMVisibility holds CVM visibility settings.
type CVMVisibility struct {
PublicSysinfo *bool `json:"public_sysinfo,omitempty"`
PublicLogs *bool `json:"public_logs,omitempty"`
PublicTcbinfo *bool `json:"public_tcbinfo,omitempty"`
}
// IsAllowedResult represents the result of an on-chain allowance check.
type IsAllowedResult struct {
CvmID int `json:"cvm_id,omitempty"`
AppContractAddress string `json:"app_contract_address"`
ComposeHash string `json:"compose_hash"`
DeviceID string `json:"device_id"`
ComposeHashAllowed bool `json:"compose_hash_allowed"`
AllowAnyDevice bool `json:"allow_any_device"`
DeviceIDAllowed *bool `json:"device_id_allowed,omitempty"`
IsAllowed bool `json:"is_allowed"`
Error *string `json:"error,omitempty"`
}
// CheckCvmIsAllowedRequest is the request for checking CVM on-chain allowance.
type CheckCvmIsAllowedRequest struct {
ComposeHash *string `json:"compose_hash,omitempty"`
NodeID *int `json:"node_id,omitempty"`
DeviceID *string `json:"device_id,omitempty"`
}
// CheckAppIsAllowedRequest is the request for checking app contract allowance.
type CheckAppIsAllowedRequest struct {
ComposeHash string `json:"compose_hash"`
NodeID *int `json:"node_id,omitempty"`
DeviceID *string `json:"device_id,omitempty"`
ChainID *int `json:"chain_id,omitempty"`
}
// AppCvmsBatchIsAllowedResponse is the batch response for app CVMs allowance check.
type AppCvmsBatchIsAllowedResponse struct {
IsOnchain bool `json:"is_onchain"`
Results []IsAllowedResult `json:"results"`
Total int `json:"total"`
AllowedCount int `json:"allowed_count"`
DeniedCount int `json:"denied_count"`
ErrorCount int `json:"error_count"`
SkippedCvmIDs []int `json:"skipped_cvm_ids"`
}
// OSImage represents an available OS image.
type OSImage struct {
Name string `json:"name"`
Slug string `json:"slug,omitempty"`
Version string `json:"version,omitempty"`
OSImageHash *string `json:"os_image_hash,omitempty"`
IsDev bool `json:"is_dev,omitempty"`
RequiresGPU bool `json:"requires_gpu,omitempty"`
}