Cleanup
Remove unused proto files and related references from the project
This commit is contained in:
parent
21d4747821
commit
df3a4631dd
10
build.rs
10
build.rs
@ -2,15 +2,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tonic_build::configure()
|
||||
.build_server(true)
|
||||
.protoc_arg("--experimental_allow_proto3_optional")
|
||||
.compile_protos(
|
||||
&[
|
||||
"proto/daemon.proto",
|
||||
"proto/shared.proto",
|
||||
"proto/brain.proto",
|
||||
"proto/dtpm.proto",
|
||||
],
|
||||
&["proto"],
|
||||
)?;
|
||||
.compile_protos(&["proto/brain.proto", "proto/dtpm.proto"], &["proto"])?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package deamon;
|
||||
|
||||
import "shared.proto";
|
||||
|
||||
|
||||
message NewContainerRes {
|
||||
string uuid = 1;
|
||||
string status = 2;
|
||||
string ip_address = 3;
|
||||
repeated shared.MappedPort mapped_ports = 4;
|
||||
string error = 5;
|
||||
}
|
||||
|
||||
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;
|
||||
optional string uuid= 2;
|
||||
}
|
||||
|
||||
message ContainerListResp {
|
||||
repeated shared.Container containers = 1;
|
||||
}
|
||||
|
||||
message DeleteContainerRes {
|
||||
string uuid = 1;
|
||||
string status = 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message BrainMessage {
|
||||
oneof Msg {
|
||||
shared.Container new_container_req = 1;
|
||||
ContainerFilters delete_container = 2;
|
||||
ContainerFilters list_container = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message DaemonMessage {
|
||||
oneof Msg {
|
||||
shared.Pubkey pubkey = 1;
|
||||
NewContainerRes new_container_resp = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// service DaemonService {
|
||||
// rpc CreateContainer (shared.Container) returns (NewContainerRes);
|
||||
// rpc DeleteContainer (ContainerFilters) returns (DeleteContainerRes);
|
||||
// rpc ListContainers (ContainerFilters) returns (ContainerListResp);
|
||||
// rpc InspectContainer (shared.UUID) returns (ContainerInspectResp);
|
||||
// rpc ContainerLog (shared.UUID) returns (stream LogResp);
|
||||
|
||||
// }
|
||||
|
||||
|
||||
service BrainSgxCli {
|
||||
rpc CreateContainer (shared.Container) returns (NewContainerRes);
|
||||
rpc DeleteContainer (ContainerFilters) returns (shared.Empty);
|
||||
rpc ListContainers (ContainerFilters) returns (ContainerListResp);
|
||||
// rpc InspectContainer (shared.UUID) returns (ContainerInspectResp);
|
||||
// rpc ContainerLog (shared.UUID) returns (stream LogResp);
|
||||
|
||||
}
|
||||
|
||||
service BrainSgxDaemon {
|
||||
rpc RegisterNode (shared.RegisterNodeReq) returns
|
||||
(stream shared.ContainerContracts);
|
||||
rpc BrainMessages (shared.Pubkey) returns (stream BrainMessage);
|
||||
rpc DaemonMessages (stream DaemonMessage) returns (shared.Empty);
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package shared;
|
||||
|
||||
message SetConfigResponse {
|
||||
string status = 1;
|
||||
}
|
||||
|
||||
message Empty {
|
||||
}
|
||||
|
||||
message ManagerConfigPB {
|
||||
repeated FileEntry filesystems = 1;
|
||||
repeated EnvironmentEntry environments = 2;
|
||||
repeated ChildProcess child_processes = 3;
|
||||
Container container = 4;
|
||||
}
|
||||
|
||||
message FileEntry {
|
||||
string path = 1;
|
||||
string content = 2;
|
||||
}
|
||||
|
||||
message EnvironmentEntry {
|
||||
string name = 1;
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message RestartPolicy {
|
||||
uint32 max_retries = 1;
|
||||
uint32 delay_seconds = 2;
|
||||
oneof policy_type {
|
||||
bool Always = 3;
|
||||
bool OnNonZeroExit = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message ChildProcess {
|
||||
string path = 1;
|
||||
repeated string arguments = 2;
|
||||
RestartPolicy restart= 3;
|
||||
}
|
||||
|
||||
service ConfigManager {
|
||||
rpc SetConfig(ManagerConfigPB) returns (SetConfigResponse) {}
|
||||
rpc GetConfig(Empty) returns (ManagerConfigPB) {}
|
||||
}
|
||||
|
||||
message MappedPort {
|
||||
uint32 host_port = 1;
|
||||
uint32 container_port = 2;
|
||||
}
|
||||
|
||||
message ContainerContracts {
|
||||
string uuid = 1;
|
||||
string package_url = 2;
|
||||
string admin_pubkey = 3;
|
||||
string node_pubkey = 4;
|
||||
repeated MappedPort exposed_ports = 5;
|
||||
string created_at = 13;
|
||||
}
|
||||
|
||||
|
||||
message Container {
|
||||
string package_url = 1;
|
||||
string node_pubkey = 2;
|
||||
Resource resource = 3;
|
||||
string uuid = 4;
|
||||
string admin_pubkey = 5;
|
||||
}
|
||||
|
||||
|
||||
message Resource {
|
||||
uint32 memory_mb = 1;
|
||||
uint32 disk_mb = 2;
|
||||
uint32 vcpu = 3;
|
||||
repeated uint32 ports = 4;
|
||||
}
|
||||
|
||||
message RegisterNodeReq {
|
||||
string node_pubkey = 1;
|
||||
string owner_pubkey = 2;
|
||||
string main_ip = 3;
|
||||
string country = 4;
|
||||
string region = 5;
|
||||
string city = 6;
|
||||
}
|
||||
|
||||
message Pubkey {
|
||||
string pubkey = 1;
|
||||
}
|
@ -1,10 +1,4 @@
|
||||
pub mod pb {
|
||||
pub mod shared {
|
||||
tonic::include_proto!("shared");
|
||||
}
|
||||
pub mod daemon {
|
||||
tonic::include_proto!("deamon");
|
||||
}
|
||||
|
||||
pub mod brain {
|
||||
tonic::include_proto!("brain");
|
||||
|
@ -1,3 +1,2 @@
|
||||
pub mod brain;
|
||||
pub mod dtpm;
|
||||
pub mod shared;
|
||||
|
@ -1,292 +0,0 @@
|
||||
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::pb::shared as pb_shared;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
pub filesystems: Vec<FileEntry>,
|
||||
pub environments: Vec<EnvironmentEntry>,
|
||||
pub child_processes: Vec<ChildProcess>,
|
||||
pub container: Option<Container>,
|
||||
}
|
||||
|
||||
impl From<pb_shared::ManagerConfigPb> for Config {
|
||||
fn from(pb_val: pb_shared::ManagerConfigPb) -> Self {
|
||||
Config {
|
||||
filesystems: pb_val
|
||||
.filesystems
|
||||
.into_iter()
|
||||
.map(FileEntry::from)
|
||||
.collect(),
|
||||
environments: pb_val
|
||||
.environments
|
||||
.into_iter()
|
||||
.map(EnvironmentEntry::from)
|
||||
.collect(),
|
||||
child_processes: pb_val
|
||||
.child_processes
|
||||
.into_iter()
|
||||
.map(ChildProcess::from)
|
||||
.collect(),
|
||||
container: pb_val.container.map(Container::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Config> for pb_shared::ManagerConfigPb {
|
||||
fn from(val: Config) -> pb_shared::ManagerConfigPb {
|
||||
pb_shared::ManagerConfigPb {
|
||||
filesystems: val.filesystems.into_iter().map(Into::into).collect(),
|
||||
environments: val.environments.into_iter().map(Into::into).collect(),
|
||||
child_processes: val.child_processes.into_iter().map(Into::into).collect(),
|
||||
container: val.container.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FileEntry {
|
||||
pub path: String,
|
||||
pub content: Option<FileContent>,
|
||||
}
|
||||
|
||||
impl From<pb_shared::FileEntry> for FileEntry {
|
||||
fn from(pb_val: pb_shared::FileEntry) -> Self {
|
||||
FileEntry {
|
||||
path: pb_val.path,
|
||||
content: Some(FileContent::Data(pb_val.content)),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<FileEntry> for pb_shared::FileEntry {
|
||||
fn from(val: FileEntry) -> pb_shared::FileEntry {
|
||||
pb_shared::FileEntry {
|
||||
path: val.path,
|
||||
content: match val.content {
|
||||
Some(FileContent::Data(data)) => data,
|
||||
Some(FileContent::Path(path)) => path,
|
||||
None => String::new(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum FileContent {
|
||||
#[serde(rename = "path")]
|
||||
Path(String),
|
||||
#[serde(rename = "data")]
|
||||
Data(String),
|
||||
}
|
||||
|
||||
impl Default for FileContent {
|
||||
fn default() -> Self {
|
||||
FileContent::Data("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct EnvironmentEntry {
|
||||
pub name: String,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl From<pb_shared::EnvironmentEntry> for EnvironmentEntry {
|
||||
fn from(pb_val: pb_shared::EnvironmentEntry) -> Self {
|
||||
EnvironmentEntry {
|
||||
name: pb_val.name,
|
||||
value: pb_val.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EnvironmentEntry> for pb_shared::EnvironmentEntry {
|
||||
fn from(val: EnvironmentEntry) -> pb_shared::EnvironmentEntry {
|
||||
pb_shared::EnvironmentEntry {
|
||||
name: val.name,
|
||||
value: val.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ChildProcess {
|
||||
pub path: String,
|
||||
pub arguments: Vec<String>,
|
||||
pub restart: Option<RestartPolicy>,
|
||||
}
|
||||
|
||||
impl From<pb_shared::ChildProcess> for ChildProcess {
|
||||
fn from(pb_val: pb_shared::ChildProcess) -> Self {
|
||||
ChildProcess {
|
||||
path: pb_val.path,
|
||||
arguments: pb_val.arguments,
|
||||
restart: pb_val.restart.map(RestartPolicy::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChildProcess> for pb_shared::ChildProcess {
|
||||
fn from(val: ChildProcess) -> pb_shared::ChildProcess {
|
||||
pb_shared::ChildProcess {
|
||||
path: val.path,
|
||||
arguments: val.arguments,
|
||||
restart: val.restart.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
|
||||
pub struct RestartPolicy {
|
||||
pub max_retries: u32,
|
||||
pub delay_seconds: u32,
|
||||
pub policy: Option<RestartPolicyType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum RestartPolicyType {
|
||||
Always(bool),
|
||||
OnNonZeroExit(bool),
|
||||
}
|
||||
|
||||
impl Default for RestartPolicyType {
|
||||
fn default() -> Self {
|
||||
RestartPolicyType::Always(true)
|
||||
}
|
||||
}
|
||||
impl From<pb_shared::RestartPolicy> for RestartPolicy {
|
||||
fn from(pb_val: pb_shared::RestartPolicy) -> Self {
|
||||
RestartPolicy {
|
||||
max_retries: pb_val.max_retries,
|
||||
delay_seconds: pb_val.delay_seconds,
|
||||
policy: match pb_val.policy_type {
|
||||
Some(pb_shared::restart_policy::PolicyType::Always(_)) => {
|
||||
Some(RestartPolicyType::Always(true))
|
||||
}
|
||||
Some(pb_shared::restart_policy::PolicyType::OnNonZeroExit(_)) => {
|
||||
Some(RestartPolicyType::OnNonZeroExit(true))
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RestartPolicy> for pb_shared::RestartPolicy {
|
||||
fn from(val: RestartPolicy) -> pb_shared::RestartPolicy {
|
||||
pb_shared::RestartPolicy {
|
||||
max_retries: val.max_retries,
|
||||
delay_seconds: val.delay_seconds,
|
||||
policy_type: match val.policy {
|
||||
Some(RestartPolicyType::Always(_)) => {
|
||||
Some(pb_shared::restart_policy::PolicyType::Always(true))
|
||||
}
|
||||
Some(RestartPolicyType::OnNonZeroExit(_)) => {
|
||||
Some(pb_shared::restart_policy::PolicyType::OnNonZeroExit(true))
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Container {
|
||||
pub package_url: String,
|
||||
pub resource: Option<Resource>,
|
||||
#[serde(default)]
|
||||
pub uuid: String,
|
||||
#[serde(default)]
|
||||
pub admin_pubkey: String,
|
||||
pub node_pubkey: String,
|
||||
}
|
||||
|
||||
impl From<pb_shared::Container> for Container {
|
||||
fn from(pb_val: pb_shared::Container) -> Self {
|
||||
Self {
|
||||
package_url: pb_val.package_url,
|
||||
resource: pb_val.resource.map(Resource::from),
|
||||
uuid: pb_val.uuid,
|
||||
admin_pubkey: pb_val.admin_pubkey,
|
||||
node_pubkey: pb_val.node_pubkey,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Container> for pb_shared::Container {
|
||||
fn from(val: Container) -> pb_shared::Container {
|
||||
pb_shared::Container {
|
||||
package_url: val.package_url,
|
||||
resource: val.resource.map(Into::into),
|
||||
// uuid: val.uuid.map(Into::into),
|
||||
uuid: val.uuid,
|
||||
admin_pubkey: val.admin_pubkey,
|
||||
node_pubkey: val.node_pubkey,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub struct Resource {
|
||||
pub memory_mb: u32,
|
||||
pub disk_mb: u32,
|
||||
pub vcpu: u32,
|
||||
pub port: Vec<u32>,
|
||||
}
|
||||
|
||||
impl From<pb_shared::Resource> for Resource {
|
||||
fn from(pb_val: pb_shared::Resource) -> Self {
|
||||
Self {
|
||||
memory_mb: pb_val.memory_mb,
|
||||
disk_mb: pb_val.disk_mb,
|
||||
vcpu: pb_val.vcpu,
|
||||
port: pb_val.ports,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Resource> for pb_shared::Resource {
|
||||
fn from(val: Resource) -> pb_shared::Resource {
|
||||
pb_shared::Resource {
|
||||
memory_mb: val.memory_mb,
|
||||
disk_mb: val.disk_mb,
|
||||
vcpu: val.vcpu,
|
||||
ports: val.port,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(u16, u16)> for pb_shared::MappedPort {
|
||||
fn from(val: (u16, u16)) -> Self {
|
||||
Self {
|
||||
host_port: val.0 as u32,
|
||||
container_port: val.1 as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pb_shared::MappedPort> for (u16, u16) {
|
||||
fn from(val: pb_shared::MappedPort) -> Self {
|
||||
(val.host_port as u16, val.container_port as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_path(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let config_str = std::fs::read_to_string(path)?;
|
||||
Ok(serde_yml::from_str(&config_str)?)
|
||||
}
|
||||
|
||||
pub fn load_data(mut self) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user