pub struct TeeClient { /* private fields */ }Expand description
Client for interacting with the Phala TEE Cloud API.
TeeClient provides low-level access to the Phala Cloud API for deploying
and managing containerized applications in a Trusted Execution Environment (TEE).
This client handles authentication, API requests, and encryption of sensitive data.
For most use cases, consider using the higher-level TeeDeployer API instead,
which provides a more ergonomic interface built on top of this client.
§Features
- Direct API access to the Phala TEE Cloud
- Secure environment variable encryption
- TEEPod discovery and selection
- Application deployment and management
Implementations§
Source§impl TeeClient
impl TeeClient
Sourcepub fn new(config: DeploymentConfig) -> Result<Self, Error>
pub fn new(config: DeploymentConfig) -> Result<Self, Error>
Sourcepub async fn deploy(&self) -> Result<DeploymentResponse, Error>
pub async fn deploy(&self) -> Result<DeploymentResponse, Error>
Deploys a container to the TEE environment using the client’s configuration.
This method uses the configuration set during client creation to deploy an application. It handles VM configuration, encryption, and API communication.
§Returns
A DeploymentResponse containing the deployment details if successful
§Errors
Returns an error if:
- The API request fails
- Environment variables cannot be encrypted
- The API returns an error response
Sourcepub async fn get_compose(&self, app_id: &str) -> Result<ComposeResponse, Error>
pub async fn get_compose(&self, app_id: &str) -> Result<ComposeResponse, Error>
Retrieves the current Docker Compose configuration for an application.
§Parameters
app_id- The ID of the application to get the configuration for
§Returns
A ComposeResponse containing the compose file and encryption public key
§Errors
Returns an error if the API request fails or the application is not found
Sourcepub async fn update_compose(
&self,
app_id: &str,
compose_file: Value,
env_vars: Option<HashMap<String, String>>,
env_pubkey: String,
) -> Result<Value, Error>
pub async fn update_compose( &self, app_id: &str, compose_file: Value, env_vars: Option<HashMap<String, String>>, env_pubkey: String, ) -> Result<Value, Error>
Updates the Docker Compose configuration for an existing application.
This method can update both the application configuration and its environment variables.
§Parameters
app_id- The ID of the application to updatecompose_file- The new Docker Compose configurationenv_vars- Optional new environment variablesenv_pubkey- The public key for encrypting environment variables
§Returns
A JSON value containing the update operation result
§Errors
Returns an error if:
- The API request fails
- The application is not found
- Environment variables cannot be encrypted
Sourcepub async fn get_available_teepods(
&self,
) -> Result<TeePodDiscoveryResponse, Error>
pub async fn get_available_teepods( &self, ) -> Result<TeePodDiscoveryResponse, Error>
Retrieves a list of available TEEPods from the Phala Cloud API.
This method queries the API for TEEPods that are available for deployment, providing detailed diagnostics for any connection issues.
§Returns
A JSON value containing the list of available TEEPods if successful
§Errors
Returns an error if:
- The network request fails (timeout, connection issues, etc.)
- The API returns an error response
- The response cannot be parsed as valid JSON
Sourcepub async fn get_pubkey_for_config(
&self,
vm_config: &Value,
) -> Result<PubkeyResponse, Error>
pub async fn get_pubkey_for_config( &self, vm_config: &Value, ) -> Result<PubkeyResponse, Error>
Sourcepub async fn deploy_with_config_do_encrypt(
&self,
vm_config: Value,
env_vars: &[(String, String)],
app_env_encrypt_pubkey: &str,
app_id_salt: &str,
) -> Result<DeploymentResponse, Error>
pub async fn deploy_with_config_do_encrypt( &self, vm_config: Value, env_vars: &[(String, String)], app_env_encrypt_pubkey: &str, app_id_salt: &str, ) -> Result<DeploymentResponse, Error>
Deploys a container with a custom VM configuration and encrypts environment variables.
This method handles the encryption of environment variables and then calls
deploy_with_config_encrypted_env to perform the actual deployment.
§Parameters
vm_config- The VM configuration as a JSON valueenv_vars- Environment variables to encrypt and include in the deploymentapp_env_encrypt_pubkey- The public key for encrypting environment variablesapp_id_salt- The salt value for encryption
§Returns
A DeploymentResponse containing the deployment details if successful
§Errors
Returns an error if:
- Environment variable encryption fails
- The API request fails
- The API returns an error response
Sourcepub async fn deploy_with_config_encrypted_env(
&self,
vm_config: Value,
encrypted_env: String,
app_env_encrypt_pubkey: &str,
app_id_salt: &str,
) -> Result<DeploymentResponse, Error>
pub async fn deploy_with_config_encrypted_env( &self, vm_config: Value, encrypted_env: String, app_env_encrypt_pubkey: &str, app_id_salt: &str, ) -> Result<DeploymentResponse, Error>
Deploys a container with a custom VM configuration and pre-encrypted environment variables.
This method is the final step in the deployment process, sending the VM configuration and encrypted environment variables to the API.
§Parameters
vm_config- The VM configuration as a JSON valueencrypted_env- Pre-encrypted environment variables as a stringapp_env_encrypt_pubkey- The public key used for encryptionapp_id_salt- The salt value used for encryption
§Returns
A DeploymentResponse containing the deployment details if successful
§Errors
Returns an error if the API request fails or returns an error
Sourcepub async fn provision_eliza(
&self,
name: String,
character_file: String,
env_keys: Vec<String>,
image: String,
) -> Result<(String, String), Error>
pub async fn provision_eliza( &self, name: String, character_file: String, env_keys: Vec<String>, image: String, ) -> Result<(String, String), Error>
Provisions a new ELIZA chatbot deployment.
This method initiates the ELIZA deployment process by requesting an app_id and encryption key from the API. This is the first step in the two-step deployment process.
§Parameters
name- Name for the ELIZA deploymentcharacter_file- Character configuration file contentenv_keys- List of environment variable keys to includeimage- Docker image to use for the deployment
§Returns
A tuple containing:
app_id- The ID of the provisioned applicationapp_env_encrypt_pubkey- The public key for encrypting environment variables
§Errors
Returns an error if:
- The API request fails
- Invalid configuration is provided
- The response cannot be parsed
Sourcepub async fn create_eliza_vm(
&self,
app_id: &str,
encrypted_env: &str,
) -> Result<DeploymentResponse, Error>
pub async fn create_eliza_vm( &self, app_id: &str, encrypted_env: &str, ) -> Result<DeploymentResponse, Error>
Creates a VM for an ELIZA deployment with encrypted environment variables.
This method is the second step in the ELIZA deployment process, creating the actual VM with the provided encrypted environment variables.
§Parameters
app_id- The ID of the provisioned applicationencrypted_env- Pre-encrypted environment variables
§Returns
A DeploymentResponse containing the deployment details and status
§Errors
Returns an error if:
- The API request fails
- The deployment cannot be created
- The response cannot be parsed
Sourcepub async fn get_network_info(
&self,
app_id: &str,
) -> Result<NetworkInfoResponse, Error>
pub async fn get_network_info( &self, app_id: &str, ) -> Result<NetworkInfoResponse, Error>
Retrieves network information for a deployed application.
This method fetches network connectivity details, status, and public URLs for accessing the deployed application.
§Parameters
app_id- The ID of the application to get network information for
§Returns
A NetworkInfoResponse containing network details including status and URLs
§Errors
Returns an error if:
- The API request fails
- The application is not found
- The network information cannot be retrieved
Sourcepub async fn get_system_stats(
&self,
app_id: &str,
) -> Result<SystemStatsResponse, Error>
pub async fn get_system_stats( &self, app_id: &str, ) -> Result<SystemStatsResponse, Error>
Retrieves system statistics for a deployed application.
This method fetches detailed system information including OS details, CPU, memory, disk usage, and load averages for a deployed containerized application.
§Parameters
app_id- The ID of the application to get system statistics for
§Returns
A SystemStatsResponse containing system information if successful
§Errors
Returns an error if:
- The API request fails
- The application is not found
- The system statistics cannot be retrieved
Sourcepub async fn get_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
pub async fn get_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
Get CVM details including status.
GET /api/v1/cvms/{cvm_id}
Sourcepub async fn get_state(&self, cvm_id: &str) -> Result<CvmStateResponse, Error>
pub async fn get_state(&self, cvm_id: &str) -> Result<CvmStateResponse, Error>
Get CVM state (running, stopped, etc.).
GET /api/v1/cvms/{cvm_id}/state
Sourcepub async fn start_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
pub async fn start_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
Start a stopped CVM.
POST /api/v1/cvms/{cvm_id}/start
Sourcepub async fn shutdown_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
pub async fn shutdown_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
Graceful shutdown (SIGTERM, then SIGKILL after timeout).
POST /api/v1/cvms/{cvm_id}/shutdown
Sourcepub async fn stop_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
pub async fn stop_cvm(&self, cvm_id: &str) -> Result<CvmInfo, Error>
Force stop (immediate, like power loss).
POST /api/v1/cvms/{cvm_id}/stop
Sourcepub async fn delete_cvm(&self, cvm_id: &str) -> Result<(), Error>
pub async fn delete_cvm(&self, cvm_id: &str) -> Result<(), Error>
Permanently delete a stopped CVM (irreversible).
DELETE /api/v1/cvms/{cvm_id}
Sourcepub async fn get_attestation(
&self,
cvm_id: &str,
) -> Result<AttestationResponse, Error>
pub async fn get_attestation( &self, cvm_id: &str, ) -> Result<AttestationResponse, Error>
Get TEE attestation data.
GET /api/v1/cvms/{cvm_id}/attestation