diff --git a/api/agent/rust/.gitignore b/api/agent/rust/.gitignore deleted file mode 100644 index a8b5cd3d..00000000 --- a/api/agent/rust/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb - -# RustRover -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -.idea/ \ No newline at end of file diff --git a/api/agent/rust/Cargo.toml b/api/agent/rust/Cargo.toml deleted file mode 100644 index 70adb265..00000000 --- a/api/agent/rust/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "nex-agentapi" -version = "0.1.0" -edition = "2021" - -[dependencies] -serde = { version = "1.0.210", features = ["derive"]} -serde_json = "1.0.128" -uuid = {version = "1.10.0", features = ["serde"] } - -[build-dependencies] -typify = "0.1.0" -syn = "2.0.77" -serde_json = "1.0.128" -schemars = "0.8.21" -prettyplease = "0.2.22" \ No newline at end of file diff --git a/api/agent/rust/build.rs b/api/agent/rust/build.rs deleted file mode 100644 index 0226bf1c..00000000 --- a/api/agent/rust/build.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::{fs, path::Path}; - -use typify::{TypeSpace, TypeSpaceSettings}; - -fn main() { - let content = std::fs::read_to_string("../register-agent-request.json").unwrap(); - let content2 = std::fs::read_to_string("../start-workload-request.json").unwrap(); - let content3 = std::fs::read_to_string("../stop-workload-request.json").unwrap(); - - let schema = serde_json::from_str(&content).unwrap(); - let schema2 = serde_json::from_str(&content2).unwrap(); - let schema3 = serde_json::from_str(&content3).unwrap(); - - let mut type_space = TypeSpace::new(TypeSpaceSettings::default().with_struct_builder(true)); - type_space.add_root_schema(schema).unwrap(); - type_space.add_root_schema(schema2).unwrap(); - type_space.add_root_schema(schema3).unwrap(); - - let contents = - prettyplease::unparse(&syn::parse2::(type_space.to_stream()).unwrap()); - - let preamble = r#" -#![allow(dead_code)] - -use serde::{Serialize, Deserialize}; - "#; - - let final_contents = format!("{preamble}\n\n{contents}"); - - let mut out_file = Path::new("./src/codegen").to_path_buf(); - out_file.push("mod.rs"); - fs::write(out_file, final_contents).unwrap(); -} \ No newline at end of file diff --git a/api/agent/rust/src/codegen/mod.rs b/api/agent/rust/src/codegen/mod.rs deleted file mode 100644 index de82479f..00000000 --- a/api/agent/rust/src/codegen/mod.rs +++ /dev/null @@ -1,578 +0,0 @@ - -#![allow(dead_code)] - -use serde::{Serialize, Deserialize}; - - -/// Error types. -pub mod error { - /// Error from a TryFrom or FromStr implementation. - pub struct ConversionError(std::borrow::Cow<'static, str>); - impl std::error::Error for ConversionError {} - impl std::fmt::Display for ConversionError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - std::fmt::Display::fmt(&self.0, f) - } - } - impl std::fmt::Debug for ConversionError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - std::fmt::Debug::fmt(&self.0, f) - } - } - impl From<&'static str> for ConversionError { - fn from(value: &'static str) -> Self { - Self(value.into()) - } - } - impl From for ConversionError { - fn from(value: String) -> Self { - Self(value.into()) - } - } -} -///RegisterAgentRequest -/// -///
JSON schema -/// -/// ```json -///{ -/// "$id": "https://github.com/synadia-io/nex/agent-api/register-agent-request", -/// "title": "RegisterAgentRequest", -/// "type": "object", -/// "required": [ -/// "name", -/// "version" -/// ], -/// "properties": { -/// "description": { -/// "description": "A user friendly description of the agent", -/// "type": "string" -/// }, -/// "max_workloads": { -/// "description": "The maximum number of workloads this agent can hold. 0 indicates unlimited", -/// "type": "number" -/// }, -/// "name": { -/// "description": "Name of the agent", -/// "type": "string" -/// }, -/// "version": { -/// "description": "Version of the agent", -/// "type": "string" -/// } -/// }, -/// "additionalProperties": false -///} -/// ``` -///
-#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(deny_unknown_fields)] -pub struct RegisterAgentRequest { - ///A user friendly description of the agent - #[serde(default, skip_serializing_if = "Option::is_none")] - pub description: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub max_workloads: Option, - ///Name of the agent - pub name: String, - ///Version of the agent - pub version: String, -} -impl From<&RegisterAgentRequest> for RegisterAgentRequest { - fn from(value: &RegisterAgentRequest) -> Self { - value.clone() - } -} -impl RegisterAgentRequest { - pub fn builder() -> builder::RegisterAgentRequest { - Default::default() - } -} -///StartWorkloadRequest -/// -///
JSON schema -/// -/// ```json -///{ -/// "$id": "https://github.com/synadia-io/nex/agent-api/start-workload-request", -/// "title": "StartWorkloadRequest", -/// "type": "object", -/// "required": [ -/// "hash", -/// "name", -/// "namespace", -/// "totalBytes", -/// "workloadId", -/// "workloadType" -/// ], -/// "properties": { -/// "argv": { -/// "description": "Command line arguments to be passed when the workload is a native/service type", -/// "type": "array", -/// "items": { -/// "type": "string" -/// } -/// }, -/// "env": { -/// "description": "A map containing environment variables, applicable for native workload types", -/// "type": "object" -/// }, -/// "hash": { -/// "description": "A hex encoded SHA-256 hash of the artifact file bytes", -/// "type": "string" -/// }, -/// "name": { -/// "description": "Name of the workload", -/// "type": "string" -/// }, -/// "namespace": { -/// "description": "Namespace of the workload", -/// "type": "string" -/// }, -/// "totalBytes": { -/// "description": "Byte size of the workload artifact", -/// "type": "integer", -/// "minimum": 1.0 -/// }, -/// "triggerSubjects": { -/// "description": "A list of trigger subjects for the workload, if applicable. Note these are NOT subscribed to by the agent, only used for information and validation", -/// "type": "array", -/// "items": { -/// "type": "string" -/// } -/// }, -/// "workloadId": { -/// "description": "The unique identifier of the workload to start.", -/// "type": "string", -/// "format": "uuid" -/// }, -/// "workloadType": { -/// "description": "Type of the workload", -/// "type": "string" -/// } -/// }, -/// "additionalProperties": false -///} -/// ``` -///
-#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(deny_unknown_fields)] -pub struct StartWorkloadRequest { - ///Command line arguments to be passed when the workload is a native/service type - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub argv: Vec, - ///A map containing environment variables, applicable for native workload types - #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] - pub env: serde_json::Map, - ///A hex encoded SHA-256 hash of the artifact file bytes - pub hash: String, - ///Name of the workload - pub name: String, - ///Namespace of the workload - pub namespace: String, - ///Byte size of the workload artifact - #[serde(rename = "totalBytes")] - pub total_bytes: std::num::NonZeroU64, - ///A list of trigger subjects for the workload, if applicable. Note these are NOT subscribed to by the agent, only used for information and validation - #[serde(rename = "triggerSubjects", default, skip_serializing_if = "Vec::is_empty")] - pub trigger_subjects: Vec, - ///The unique identifier of the workload to start. - #[serde(rename = "workloadId")] - pub workload_id: uuid::Uuid, - ///Type of the workload - #[serde(rename = "workloadType")] - pub workload_type: String, -} -impl From<&StartWorkloadRequest> for StartWorkloadRequest { - fn from(value: &StartWorkloadRequest) -> Self { - value.clone() - } -} -impl StartWorkloadRequest { - pub fn builder() -> builder::StartWorkloadRequest { - Default::default() - } -} -///StopWorkloadRequest -/// -///
JSON schema -/// -/// ```json -///{ -/// "$id": "https://github.com/synadia-io/nex/agent-api/stop-workload-request", -/// "title": "StopWorkloadRequest", -/// "type": "object", -/// "required": [ -/// "workloadId" -/// ], -/// "properties": { -/// "immediate": { -/// "description": "Indicates whether the stoppage should be immediate or graceful", -/// "type": "boolean" -/// }, -/// "reason": { -/// "description": "Optional reason for stopping the workload", -/// "type": "string" -/// }, -/// "workloadId": { -/// "description": "The unique identifier of the workload to stop.", -/// "type": "string", -/// "format": "uuid" -/// } -/// }, -/// "additionalProperties": false -///} -/// ``` -///
-#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(deny_unknown_fields)] -pub struct StopWorkloadRequest { - ///Indicates whether the stoppage should be immediate or graceful - #[serde(default, skip_serializing_if = "Option::is_none")] - pub immediate: Option, - ///Optional reason for stopping the workload - #[serde(default, skip_serializing_if = "Option::is_none")] - pub reason: Option, - ///The unique identifier of the workload to stop. - #[serde(rename = "workloadId")] - pub workload_id: uuid::Uuid, -} -impl From<&StopWorkloadRequest> for StopWorkloadRequest { - fn from(value: &StopWorkloadRequest) -> Self { - value.clone() - } -} -impl StopWorkloadRequest { - pub fn builder() -> builder::StopWorkloadRequest { - Default::default() - } -} -/// Types for composing complex structures. -pub mod builder { - #[derive(Clone, Debug)] - pub struct RegisterAgentRequest { - description: Result, String>, - max_workloads: Result, String>, - name: Result, - version: Result, - } - impl Default for RegisterAgentRequest { - fn default() -> Self { - Self { - description: Ok(Default::default()), - max_workloads: Ok(Default::default()), - name: Err("no value supplied for name".to_string()), - version: Err("no value supplied for version".to_string()), - } - } - } - impl RegisterAgentRequest { - pub fn description(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.description = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for description: {}", e) - }); - self - } - pub fn max_workloads(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.max_workloads = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for max_workloads: {}", e) - }); - self - } - pub fn name(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.name = value - .try_into() - .map_err(|e| format!("error converting supplied value for name: {}", e)); - self - } - pub fn version(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.version = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for version: {}", e) - }); - self - } - } - impl std::convert::TryFrom for super::RegisterAgentRequest { - type Error = super::error::ConversionError; - fn try_from( - value: RegisterAgentRequest, - ) -> Result { - Ok(Self { - description: value.description?, - max_workloads: value.max_workloads?, - name: value.name?, - version: value.version?, - }) - } - } - impl From for RegisterAgentRequest { - fn from(value: super::RegisterAgentRequest) -> Self { - Self { - description: Ok(value.description), - max_workloads: Ok(value.max_workloads), - name: Ok(value.name), - version: Ok(value.version), - } - } - } - #[derive(Clone, Debug)] - pub struct StartWorkloadRequest { - argv: Result, String>, - env: Result, String>, - hash: Result, - name: Result, - namespace: Result, - total_bytes: Result, - trigger_subjects: Result, String>, - workload_id: Result, - workload_type: Result, - } - impl Default for StartWorkloadRequest { - fn default() -> Self { - Self { - argv: Ok(Default::default()), - env: Ok(Default::default()), - hash: Err("no value supplied for hash".to_string()), - name: Err("no value supplied for name".to_string()), - namespace: Err("no value supplied for namespace".to_string()), - total_bytes: Err("no value supplied for total_bytes".to_string()), - trigger_subjects: Ok(Default::default()), - workload_id: Err("no value supplied for workload_id".to_string()), - workload_type: Err("no value supplied for workload_type".to_string()), - } - } - } - impl StartWorkloadRequest { - pub fn argv(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.argv = value - .try_into() - .map_err(|e| format!("error converting supplied value for argv: {}", e)); - self - } - pub fn env(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.env = value - .try_into() - .map_err(|e| format!("error converting supplied value for env: {}", e)); - self - } - pub fn hash(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.hash = value - .try_into() - .map_err(|e| format!("error converting supplied value for hash: {}", e)); - self - } - pub fn name(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.name = value - .try_into() - .map_err(|e| format!("error converting supplied value for name: {}", e)); - self - } - pub fn namespace(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.namespace = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for namespace: {}", e) - }); - self - } - pub fn total_bytes(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.total_bytes = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for total_bytes: {}", e) - }); - self - } - pub fn trigger_subjects(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.trigger_subjects = value - .try_into() - .map_err(|e| { - format!( - "error converting supplied value for trigger_subjects: {}", e - ) - }); - self - } - pub fn workload_id(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.workload_id = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for workload_id: {}", e) - }); - self - } - pub fn workload_type(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.workload_type = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for workload_type: {}", e) - }); - self - } - } - impl std::convert::TryFrom for super::StartWorkloadRequest { - type Error = super::error::ConversionError; - fn try_from( - value: StartWorkloadRequest, - ) -> Result { - Ok(Self { - argv: value.argv?, - env: value.env?, - hash: value.hash?, - name: value.name?, - namespace: value.namespace?, - total_bytes: value.total_bytes?, - trigger_subjects: value.trigger_subjects?, - workload_id: value.workload_id?, - workload_type: value.workload_type?, - }) - } - } - impl From for StartWorkloadRequest { - fn from(value: super::StartWorkloadRequest) -> Self { - Self { - argv: Ok(value.argv), - env: Ok(value.env), - hash: Ok(value.hash), - name: Ok(value.name), - namespace: Ok(value.namespace), - total_bytes: Ok(value.total_bytes), - trigger_subjects: Ok(value.trigger_subjects), - workload_id: Ok(value.workload_id), - workload_type: Ok(value.workload_type), - } - } - } - #[derive(Clone, Debug)] - pub struct StopWorkloadRequest { - immediate: Result, String>, - reason: Result, String>, - workload_id: Result, - } - impl Default for StopWorkloadRequest { - fn default() -> Self { - Self { - immediate: Ok(Default::default()), - reason: Ok(Default::default()), - workload_id: Err("no value supplied for workload_id".to_string()), - } - } - } - impl StopWorkloadRequest { - pub fn immediate(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.immediate = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for immediate: {}", e) - }); - self - } - pub fn reason(mut self, value: T) -> Self - where - T: std::convert::TryInto>, - T::Error: std::fmt::Display, - { - self.reason = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for reason: {}", e) - }); - self - } - pub fn workload_id(mut self, value: T) -> Self - where - T: std::convert::TryInto, - T::Error: std::fmt::Display, - { - self.workload_id = value - .try_into() - .map_err(|e| { - format!("error converting supplied value for workload_id: {}", e) - }); - self - } - } - impl std::convert::TryFrom for super::StopWorkloadRequest { - type Error = super::error::ConversionError; - fn try_from( - value: StopWorkloadRequest, - ) -> Result { - Ok(Self { - immediate: value.immediate?, - reason: value.reason?, - workload_id: value.workload_id?, - }) - } - } - impl From for StopWorkloadRequest { - fn from(value: super::StopWorkloadRequest) -> Self { - Self { - immediate: Ok(value.immediate), - reason: Ok(value.reason), - workload_id: Ok(value.workload_id), - } - } - } -} diff --git a/api/agent/rust/src/lib.rs b/api/agent/rust/src/lib.rs deleted file mode 100644 index ba05113f..00000000 --- a/api/agent/rust/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod codegen; -