Skip to main content

phala_tee_deploy_rs/
config.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4/// Configuration for deploying applications to the Phala TEE Cloud.
5///
6/// This struct contains all the parameters needed to create a deployment,
7/// including API credentials, Docker Compose configuration, and environment variables.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct DeploymentConfig {
10    /// Base URL for the Phala TEE Cloud API
11    pub api_url: String,
12
13    /// API key for authentication with the Phala Cloud API
14    pub api_key: String,
15
16    /// Docker Compose configuration as a string
17    pub docker_compose: String,
18
19    /// Environment variables to be securely encrypted and included in the deployment
20    pub env_vars: HashMap<String, String>,
21
22    /// ID of the TEEPod to deploy to
23    pub teepod_id: u64,
24
25    /// Docker image to deploy
26    pub image: String,
27
28    /// Optional custom VM configuration
29    pub vm_config: Option<super::types::VmConfig>,
30}
31
32impl DeploymentConfig {
33    /// Creates a new deployment configuration with default API URL.
34    ///
35    /// # Parameters
36    ///
37    /// * `api_key` - API key for authenticating with the Phala Cloud API
38    /// * `docker_compose` - Docker Compose configuration as a string
39    /// * `env_vars` - Environment variables to include in the deployment
40    /// * `teepod_id` - ID of the TEEPod to deploy to
41    /// * `image` - Docker image to deploy
42    ///
43    /// # Returns
44    ///
45    /// A new `DeploymentConfig` instance with the default API URL
46    pub fn new(
47        api_key: String,
48        docker_compose: String,
49        env_vars: HashMap<String, String>,
50        teepod_id: u64,
51        image: String,
52    ) -> Self {
53        Self {
54            api_url: "https://cloud-api.phala.network/api/v1".to_string(),
55            api_key,
56            docker_compose,
57            env_vars,
58            teepod_id,
59            image,
60            vm_config: None,
61        }
62    }
63
64    /// Sets a custom API URL for the Phala Cloud API.
65    ///
66    /// # Parameters
67    ///
68    /// * `api_url` - The custom API URL to use
69    ///
70    /// # Returns
71    ///
72    /// The updated `DeploymentConfig` instance for method chaining
73    pub fn with_api_url(mut self, api_url: String) -> Self {
74        self.api_url = api_url;
75        self
76    }
77
78    /// Sets a custom VM configuration for the deployment.
79    ///
80    /// # Parameters
81    ///
82    /// * `vm_config` - The custom VM configuration to use
83    ///
84    /// # Returns
85    ///
86    /// The updated `DeploymentConfig` instance for method chaining
87    pub fn with_vm_config(mut self, vm_config: super::types::VmConfig) -> Self {
88        self.vm_config = Some(vm_config);
89        self
90    }
91}