MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / main

Function main

sdk/rust/examples/dstack_client_usage.rs:10–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9#[tokio::main]
10async fn main() -> anyhow::Result<()> {
11 // Create a DstackClient with default endpoint (/var/run/dstack.sock)
12 let client = DstackClient::new(None);
13
14 // Or create with a custom endpoint
15 // let client = DstackClient::new(Some("/custom/path/dstack.sock"));
16
17 // Or create with HTTP endpoint for simulator
18 // let client = DstackClient::new(Some("http://localhost:8000"));
19
20 println!("DstackClient created successfully!");
21
22 // Example usage (these will fail without a running dstack service):
23
24 // 1. Get system info
25 let info = client.info().await?;
26 println!("System info retrieved successfully!");
27 println!(" App ID: {}", info.app_id);
28 println!(" Instance ID: {}", info.instance_id);
29 println!(" App Name: {}", info.app_name);
30 println!(" Device ID: {}", info.device_id);
31 println!(" Compose Hash: {}", info.compose_hash);
32 println!(" TCB Info - MRTD: {}", info.tcb_info.mrtd);
33 println!(" TCB Info - RTMR0: {}", info.tcb_info.rtmr0);
34
35 // 2. Derive a key
36 let response = client
37 .get_key(Some("my-app".to_string()), Some("encryption".to_string()))
38 .await?;
39 println!("Key derived successfully!");
40 println!(" Key length: {}", response.key.len());
41 println!(
42 " Signature chain length: {}",
43 response.signature_chain.len()
44 );
45
46 // Decode the key
47 let key_bytes = response.decode_key()?;
48 println!(" Decoded key bytes length: {}", key_bytes.len());
49
50 // 3. Generate TDX quote
51 let report_data = b"Hello, dstack world!".to_vec();
52 let response = client.get_quote(report_data).await?;
53 println!("TDX quote generated successfully!");
54 println!(" Quote length: {}", response.quote.len());
55 println!(" Event log length: {}", response.event_log.len());
56
57 // Decode the quote
58 let quote_bytes = response.decode_quote()?;
59 println!(" Decoded quote bytes length: {}", quote_bytes.len());
60
61 // Replay RTMRs from event log
62 let rtmrs = response.replay_rtmrs()?;
63 println!(" Replayed RTMRs: {} entries", rtmrs.len());
64 for (idx, rtmr) in rtmrs.iter() {
65 println!(" RTMR{}: {}", idx, rtmr);
66 }
67

Callers

nothing calls this directly

Calls 15

to_vecMethod · 0.80
cloneMethod · 0.80
infoMethod · 0.45
get_keyMethod · 0.45
decode_keyMethod · 0.45
get_quoteMethod · 0.45
decode_quoteMethod · 0.45
replay_rtmrsMethod · 0.45
emit_eventMethod · 0.45
buildMethod · 0.45
get_tls_keyMethod · 0.45
decode_event_logMethod · 0.45

Tested by

no test coverage detected