diff --git a/proto/daemon.proto b/proto/daemon.proto index d8f21e6..0bb73c8 100644 --- a/proto/daemon.proto +++ b/proto/daemon.proto @@ -4,20 +4,47 @@ package deamon; import "shared.proto"; -message Empty { -} - -message NewContainerReq { - repeated string port = 1; -} message NewContainerRes { - string status = 1; + optional shared.UUID container_id = 1; + string status = 2; + string ip_address = 3; +} + +message ContainerInspectResp { + shared.Container containers = 1; + repeated shared.MappedPort mapped_ports = 2; + string crated_time = 3; + optional string ratls_pubkey = 4; + optional string mr_signer = 5; + optional string mr_enclave = 6; + string state = 7; + string disk_usage = 8; +} + +message LogResp { + string std_out = 1; + string std_err = 2; +} + +message ContainerFilters { + string admin_pubkey = 1; +} + +message ContainerListResp { + repeated shared.Container containers = 1; +} + +message DeleteContainerRes { + optional shared.UUID container_id = 1; + string status = 2; } service DaemonService { - // rpc CreateContainer (NewContainerReq) returns (NewContainerRes); rpc CreateContainer (shared.Container) returns (NewContainerRes); - // rpc ListContainer (NodeFilters) returns (stream NodeListResp); + rpc InspectContainer (shared.UUID) returns (ContainerInspectResp); + rpc ContainerLog (shared.UUID) returns (stream LogResp); + rpc ListContainers (ContainerFilters) returns (ContainerListResp); + rpc DeleteContainer (shared.UUID) returns (DeleteContainerRes); } diff --git a/proto/shared.proto b/proto/shared.proto index fbbedc6..9abc99f 100644 --- a/proto/shared.proto +++ b/proto/shared.proto @@ -6,12 +6,16 @@ message SetConfigResponse { string status = 1; } -message Empty {} +message Empty { +} +message UUID { + string uuid = 1; +} // The main Config structure message ManagerConfigPB { - repeated FileEntry filesystem = 1; - repeated EnvironmentEntry environment = 2; + repeated FileEntry filesystems = 1; + repeated EnvironmentEntry environments = 2; repeated ChildProcess child_processes = 3; Container container = 4; } @@ -52,12 +56,18 @@ service ConfigManager { rpc GetConfig(Empty) returns (ManagerConfigPB) {} } +message MappedPort { + uint32 host_port = 1; + uint32 container_port = 2; +} + message Container { optional string package_url = 1; string node = 2; Resource resource = 3; - string uuid = 4; + UUID uuid = 4; + string admin_pubkey = 5; } message Resource { diff --git a/src/lib.rs b/src/lib.rs index 65ce9f4..567c78d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,128 +7,4 @@ pub mod pb { } } -pub mod config { - use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; - use serde::{Deserialize, Serialize}; - - #[derive(Clone, Serialize, Deserialize, prost::Oneof)] - pub enum FileContent { - #[serde(rename = "path")] - #[prost(string, tag = "2")] - Path(String), - #[serde(rename = "data")] - #[prost(string, tag = "3")] - Data(String), - } - - impl Default for FileContent { - fn default() -> Self { - FileContent::Data("".to_string()) - } - } - - #[derive(Clone, Serialize, Deserialize, prost::Message)] - pub struct FileEntry { - #[prost(string, tag = "1")] - pub path: String, - #[prost(oneof = "FileContent", tags = "2, 3")] - pub content: Option, - } - - #[derive(Clone, Serialize, Deserialize, prost::Message)] - pub struct EnvironmentEntry { - #[prost(string, tag = "1")] - pub name: String, - #[prost(string, tag = "2")] - pub value: String, - } - #[derive(Clone, Copy, Serialize, Deserialize, prost::Message)] - pub struct RestartPolicy { - #[prost(uint32, tag = "1")] - pub max_retries: u32, - #[prost(uint32, tag = "2")] - pub delay_seconds: u32, - #[prost(oneof = "RestartPolicyType", tags = "3, 4")] - pub policy: Option, - } - - #[derive(Clone, Copy, Serialize, Deserialize, prost::Oneof)] - pub enum RestartPolicyType { - #[prost(bool, tag = "3")] - Always(bool), - #[prost(bool, tag = "4")] - OnNonZeroExit(bool), - } - - impl Default for RestartPolicyType { - fn default() -> Self { - RestartPolicyType::Always(true) - } - } - - #[derive(Clone, Serialize, Deserialize, prost::Message)] - pub struct ChildProcess { - #[prost(string, tag = "1")] - pub path: String, - #[prost(string, repeated, tag = "2")] - pub arguments: Vec, - #[prost(message, optional, tag = "3")] - pub restart: Option, - } - - #[derive(Clone, Serialize, Deserialize, prost::Message)] - pub struct Container { - #[prost(string, optional, tag = "1")] - pub package_url: Option, - #[prost(string, tag = "2")] - pub node: String, - #[prost(message, optional, tag = "3")] - pub resource: Option, - #[serde(default)] - #[prost(string, tag = "4")] - pub uuid: String, - } - - #[derive(Clone, Serialize, Deserialize, PartialEq, prost::Message)] - pub struct Resource { - #[prost(uint32, tag = "1")] - pub memory_mb: u32, - #[prost(uint32, tag = "2")] - pub disk_mb: u32, - #[prost(uint32, tag = "3")] - pub vcpu: u32, - #[prost(uint32, repeated, tag = "4")] - pub port: Vec, - } - - #[derive(Clone, Serialize, Deserialize, prost::Message)] - pub struct Config { - #[prost(message, repeated, tag = "1")] - pub filesystem: Vec, - #[prost(message, repeated, tag = "2")] - pub environment: Vec, - #[prost(message, repeated, tag = "3")] - pub child_processes: Vec, - #[prost(message, optional, tag = "4")] - pub container: Option, - } - - impl Config { - pub fn from_path(path: &str) -> Result> { - let config_str = std::fs::read_to_string(path)?; - Ok(serde_yml::from_str(&config_str)?) - } - - pub fn load_data(mut self) -> Result> { - self.filesystem.iter_mut().for_each(|x| { - if let Some(FileContent::Path(path)) = &x.content { - let content = std::fs::read(path).expect("Unable to read file {path}"); - let encoded = BASE64.encode(content); - x.content = Some(FileContent::Data(encoded)); - } - }); - - Ok(self) - } - } -} +pub mod pb_types; diff --git a/src/pb_types.rs b/src/pb_types.rs new file mode 100644 index 0000000..eec3c89 --- /dev/null +++ b/src/pb_types.rs @@ -0,0 +1 @@ +pub mod shared; diff --git a/src/pb_types/shared.rs b/src/pb_types/shared.rs new file mode 100644 index 0000000..28c1593 --- /dev/null +++ b/src/pb_types/shared.rs @@ -0,0 +1,125 @@ +use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Serialize, Deserialize, prost::Message)] +pub struct Config { + #[prost(message, repeated, tag = "1")] + pub filesystems: Vec, + #[prost(message, repeated, tag = "2")] + pub environments: Vec, + #[prost(message, repeated, tag = "3")] + pub child_processes: Vec, + #[prost(message, optional, tag = "4")] + pub container: Option, +} + +#[derive(Clone, Serialize, Deserialize, prost::Message)] +pub struct FileEntry { + #[prost(string, tag = "1")] + pub path: String, + #[prost(oneof = "FileContent", tags = "2, 3")] + pub content: Option, +} + +#[derive(Clone, Serialize, Deserialize, prost::Oneof)] +pub enum FileContent { + #[serde(rename = "path")] + #[prost(string, tag = "2")] + Path(String), + #[serde(rename = "data")] + #[prost(string, tag = "3")] + Data(String), +} + +impl Default for FileContent { + fn default() -> Self { + FileContent::Data("".to_string()) + } +} + +#[derive(Clone, Serialize, Deserialize, prost::Message)] +pub struct EnvironmentEntry { + #[prost(string, tag = "1")] + pub name: String, + #[prost(string, tag = "2")] + pub value: String, +} + +#[derive(Clone, Serialize, Deserialize, prost::Message)] +pub struct ChildProcess { + #[prost(string, tag = "1")] + pub path: String, + #[prost(string, repeated, tag = "2")] + pub arguments: Vec, + #[prost(message, optional, tag = "3")] + pub restart: Option, +} + +#[derive(Clone, Copy, Serialize, Deserialize, prost::Message)] +pub struct RestartPolicy { + #[prost(uint32, tag = "1")] + pub max_retries: u32, + #[prost(uint32, tag = "2")] + pub delay_seconds: u32, + #[prost(oneof = "RestartPolicyType", tags = "3, 4")] + pub policy: Option, +} + +#[derive(Clone, Copy, Serialize, Deserialize, prost::Oneof)] +pub enum RestartPolicyType { + #[prost(bool, tag = "3")] + Always(bool), + #[prost(bool, tag = "4")] + OnNonZeroExit(bool), +} + +impl Default for RestartPolicyType { + fn default() -> Self { + RestartPolicyType::Always(true) + } +} + +#[derive(Clone, Serialize, Deserialize, prost::Message)] +pub struct Container { + #[prost(string, optional, tag = "1")] + pub package_url: Option, + #[prost(string, tag = "2")] + pub node: String, + #[prost(message, optional, tag = "3")] + pub resource: Option, + #[serde(default)] + #[prost(string, tag = "4")] + pub uuid: String, +} + +#[derive(Clone, Serialize, Deserialize, PartialEq, prost::Message)] +pub struct Resource { + #[prost(uint32, tag = "1")] + pub memory_mb: u32, + #[prost(uint32, tag = "2")] + pub disk_mb: u32, + #[prost(uint32, tag = "3")] + pub vcpu: u32, + #[prost(uint32, repeated, tag = "4")] + pub port: Vec, +} + +impl Config { + pub fn from_path(path: &str) -> Result> { + let config_str = std::fs::read_to_string(path)?; + Ok(serde_yml::from_str(&config_str)?) + } + + pub fn load_data(mut self) -> Result> { + self.filesystems.iter_mut().for_each(|x| { + if let Some(FileContent::Path(path)) = &x.content { + let content = + std::fs::read(path).unwrap_or_else(|_| panic!("Unable to read file {path}")); + let encoded = BASE64.encode(content); + x.content = Some(FileContent::Data(encoded)); + } + }); + + Ok(self) + } +}