Skip to content

Commit

Permalink
wip: rename Event macro
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jan 2, 2025
1 parent ac970a4 commit 22ad5cf
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 250 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion sandpolis-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{self, parse_macro_input, DeriveInput};

#[proc_macro_derive(Event)]
#[proc_macro_derive(StreamEvent)]
pub fn derive_event(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;

// TODO assert type name ends with 'Event'?

let expanded = quote! {
impl Into<axum::extract::ws::Message> for #name {
fn into(self) -> axum::extract::ws::Message {
Expand All @@ -17,3 +19,5 @@ pub fn derive_event(input: TokenStream) -> TokenStream {

TokenStream::from(expanded)
}

// TODO data objects
1 change: 1 addition & 0 deletions sandpolis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ layer-package = []
layer-shell = []
layer-sysinfo = []
layer-probe = []
layer-tunnel = []

default = [ "layer-desktop", "layer-filesystem", "layer-shell", "layer-inventory", "layer-account", "layer-logging" ]
wayland = [ "bevy/wayland" ]
Expand Down
25 changes: 15 additions & 10 deletions sandpolis/src/agent/layer/package/mod.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
use std::path::PathBuf;

use anyhow::{bail, Result};
use axum::Router;

use crate::core::layer::package::PackageData;

pub trait PackageManager {
/// Get the location of the package manager's binary on the filesystem.
pub fn getManagerLocation(&self) -> Result<PathBuf> {
fn get_location(&self) -> Result<PathBuf> {
bail!("Not implemented");
}

/// Get the package manager's version string.
pub async fn getManagerVersion(&self) -> Result<String> {
async fn get_version(&self) -> Result<String> {
bail!("Not implemented");
}

/// Remove old packages from the local package cache.
pub async fn clean() -> Result<()> {
async fn clean() -> Result<()> {
bail!("Not implemented");
}

/// Get all currently installed packages.
pub async fn getInstalled() -> Result<Vec<Package>> {
async fn get_installed() -> Result<Vec<PackageData>> {
bail!("Not implemented");
}

/// Gather advanced metadata for the given package.
pub async fn getMetadata(name: String) -> Result<Package> {
async fn get_metadata(name: String) -> Result<PackageData> {
bail!("Not implemented");
}

/// Get all packages that are currently outdated.
pub async fn getOutdated() -> Result<Vec<Package>> {
async fn get_outdated() -> Result<Vec<PackageData>> {
bail!("Not implemented");
}

/// Install the given packages onto the local system.
pub async fn install(packages: Vec<String>) -> Result<()> {
async fn install(packages: Vec<String>) -> Result<()> {
bail!("Not implemented");
}

/// Synchronize the local package database with all remote repositories.
pub async fn refresh() -> Result<()> {
async fn refresh() -> Result<()> {
bail!("Not implemented");
}

/// Remove the given packages from the local system.
pub async fn remove(packages: Vec<String>) -> Result<()> {
async fn remove(packages: Vec<String>) -> Result<()> {
bail!("Not implemented");
}

/// Upgrade the given packages to the latest available version.
pub async fn upgrade(packages: Vec<String>) -> Result<()> {
async fn upgrade(packages: Vec<String>) -> Result<()> {
bail!("Not implemented");
}
}
Expand Down
24 changes: 23 additions & 1 deletion sandpolis/src/agent/layer/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ pub struct ShellSession {
}

impl ShellSession {
pub fn new(request: ShellSessionRequest) -> Result<Self> {
pub fn new(mut request: ShellSessionRequest) -> Result<Self> {
// Add a default for TERM
if request.environment.get("TERM").is_none() {
request
.environment
.insert("TERM".to_string(), "screen-256color".to_string());
}

// Add a default for rows/cols
if request.rows == 0 {
request.rows = 120;
}
if request.cols == 0 {
request.cols = 80;
}

request
.environment
.insert("ROWS".to_string(), request.rows.to_string());
request
.environment
.insert("COLS".to_string(), request.cols.to_string());

Ok(Self {
process: Command::new(&request.path)
.envs(request.environment)
Expand Down
2 changes: 2 additions & 0 deletions sandpolis/src/core/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ pub mod package;
pub mod probe;
#[cfg(feature = "layer-shell")]
pub mod shell;
#[cfg(feature = "layer-tunnel")]
pub mod tunnel;

pub mod network;
4 changes: 2 additions & 2 deletions sandpolis/src/core/layer/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum PackageManager {

#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "client", derive(bevy::prelude::Component))]
pub struct PackageManagerInfo {
pub struct PackageManagerData {
/// Type of package manager
pub manager: PackageManager,

Expand All @@ -43,7 +43,7 @@ pub struct PackageManagerInfo {

#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "client", derive(bevy::prelude::Component))]
pub struct Package {
pub struct PackageData {
/// Canonical name/identifier
pub name: String,

Expand Down
4 changes: 2 additions & 2 deletions sandpolis/src/core/layer/shell.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, path::PathBuf};

use sandpolis_macros::Event;
use sandpolis_macros::StreamEvent;
use serde::{Deserialize, Serialize};

pub struct ShellLayer {
Expand Down Expand Up @@ -169,7 +169,7 @@ pub struct ShellSessionInputEvent {
}

/// Event containing standard-output and standard-error
#[derive(Serialize, Deserialize, Default, Event)]
#[derive(Serialize, Deserialize, Default, StreamEvent)]
pub struct ShellSessionOutputEvent {
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
Expand Down
22 changes: 22 additions & 0 deletions sandpolis/src/core/layer/tunnel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::net::SocketAddr;

#[derive(Clone, Serialize, Deserialize)]
pub struct TunnelStreamData {
/// Instance hosting the listener
pub listener_id: InstanceId,

/// Socket to bind the listener to
pub listener_addr: SocketAddr,

pub repeater_iid: Vec<String>,

pub terminator_iid: String,

pub target_addr: SocketAddr,

pub target_protocol: String,
}

/// Raw data flowing through a tunnel
#[derive(Serialize, Deserialize, StreamEvent)]
pub struct TunnelStreamEvent(Vec<u8>);
Loading

0 comments on commit 22ad5cf

Please sign in to comment.