Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"crates/op",
"crates/ot",
"crates/orchestrator",
"crates/paths",
"crates/minimal",
"crates/minimal2",
"crates/minimald",
Expand Down Expand Up @@ -124,6 +125,7 @@ multi = { version = "0.0.1", path = "crates/multi" }
op = { version = "0.0.1", path = "crates/op" }
ot = { version = "0.0.1", path = "crates/ot" }
orchestrator = { version = "0.0.1", path = "crates/orchestrator" }
paths = { version = "0.0.1", path = "crates/paths" }
remote-proto = { version = "0.0.1", path = "crates/remote-proto" }
remote-client = { version = "0.0.1", path = "crates/remote-client" }
sandbox2 = { version = "0.0.1", path = "crates/sandbox2" }
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tracing.workspace = true
tracing-subscriber.workspace = true

ot.workspace = true
paths.workspace = true
sessions.workspace = true
stdlib.workspace = true

Expand Down
5 changes: 1 addition & 4 deletions crates/minimald/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
use camino::Utf8PathBuf;
use clap::{Args, CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use sessions::{
paths::{CwdRelative, Daemon, DaemonAbsPath, DaemonRelPath},
sub_path,
};
use paths::{CwdRelative, Daemon, DaemonAbsPath, DaemonRelPath, sub_path};
use tokio::net::UnixListener;
use tracing_subscriber::{EnvFilter, fmt, prelude::*};

Expand Down
2 changes: 1 addition & 1 deletion crates/minimald/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub async fn handle_ssh_rpc(

#[cfg(test)]
mod tests {
use sessions::paths::HostAbsPath;
use paths::HostAbsPath;

use super::*;
use crate::test_harness::TestServer;
Expand Down
2 changes: 1 addition & 1 deletion crates/minimald/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::sessions::paths::DaemonAbsPath;
use ::paths::DaemonAbsPath;
use russh::keys::key::safe_rng;
use russh::keys::{PrivateKey, ssh_key::Error as KeyError};
use serde::{Deserialize, Serialize};
Expand Down
3 changes: 2 additions & 1 deletion crates/minimald/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use sessions::{paths::DaemonAbsPath, store::SessionObject};
use paths::DaemonAbsPath;
use sessions::store::SessionObject;
use tokio::sync::{mpsc, oneshot};

enum SessionMessage {
Expand Down
2 changes: 1 addition & 1 deletion crates/minimald/src/sessions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::BTreeMap;

use crate::session::{Session, SessionHandle};
use paths::DaemonAbsPath;
use sessions::{
SessionId,
paths::DaemonAbsPath,
store::{DiskLoader, Loader, SessionKey, SessionObject},
};
use tokio::sync::{mpsc, oneshot};
Expand Down
4 changes: 2 additions & 2 deletions crates/minimald/src/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use std::io::SeekFrom;
use std::path::{Path, PathBuf};

use path_absolutize::Absolutize;
use paths::DaemonAbsPath;
use russh::ChannelId;
use russh::server::Session;
use russh_sftp::protocol::{
Attrs, Data, File, FileAttributes, Handle, Name, OpenFlags, Status, StatusCode,
};
use sessions::SessionId;
use sessions::paths::DaemonAbsPath;
use tokio::fs::{self, OpenOptions};
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use tokio::task::spawn;
Expand Down Expand Up @@ -464,10 +464,10 @@ pub(crate) async fn handle_sftp_subsystem(

#[cfg(test)]
mod tests {
use paths::HostAbsPath;
use russh_sftp::client::error::Error as SftpClientError;
use russh_sftp::protocol::{OpenFlags, StatusCode};
use sessions::SessionId;
use sessions::paths::HostAbsPath;
use tokio::io::AsyncWriteExt;

use crate::rpc::{CreateSession, CreateSessionRequest};
Expand Down
2 changes: 1 addition & 1 deletion crates/minimald/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use std::sync::Arc;

use camino::Utf8PathBuf;
use paths::DaemonAbsPath;
use russh::keys::ssh_key;
use sessions::SessionId;
use sessions::paths::DaemonAbsPath;
use tempfile::TempDir;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::UnixStream;
Expand Down
15 changes: 15 additions & 0 deletions crates/paths/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "paths"
version = "0.0.1"
edition.workspace = true
publish.workspace = true

[dependencies]
camino.workspace = true
serde.workspace = true

[dev-dependencies]
toml.workspace = true

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
12 changes: 6 additions & 6 deletions crates/sessions/src/paths.rs → crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! to pass a host path to code that expects a sandbox-internal path, and the
//! type checker will not stop you.
//!
//! This module encodes the filesystem a path belongs to as a *phantom type
//! This crate encodes the filesystem a path belongs to as a *phantom type
//! parameter*, splits absolute and relative paths into distinct types, and
//! requires crossing realms to go through an explicit [`Translator`].
//!
Expand All @@ -26,7 +26,7 @@
//! # Example
//!
//! ```
//! use sessions::paths::{AbsPath, Host, RelPath};
//! use paths::{AbsPath, Host, RelPath};
//!
//! let base: AbsPath<Host> = AbsPath::try_new("/etc/minimal").unwrap();
//! let rel: RelPath<Host> = RelPath::try_new("hooks/cleanup.sh").unwrap();
Expand Down Expand Up @@ -162,7 +162,7 @@ pub const fn _validate_subdir(s: &str) {
macro_rules! sub_path {
($base:expr, $dir:literal) => {{
#[allow(clippy::used_underscore_items)]
const _: () = $crate::paths::_validate_subdir($dir);
const _: () = $crate::_validate_subdir($dir);
($base).sub_path_unchecked($dir)
}};
}
Expand Down Expand Up @@ -608,7 +608,7 @@ impl<'de, R: Realm> serde::Deserialize<'de> for RelPath<R> {
/// tag is needed — every UTF-8 path is unambiguously one or the other.
///
/// ```
/// use sessions::paths::HostPath;
/// use paths::HostPath;
///
/// let abs: HostPath = toml::from_str::<Wrap>(r#"x = "/etc/minimal""#).unwrap().x;
/// let rel: HostPath = toml::from_str::<Wrap>(r#"x = "etc/minimal""#).unwrap().x;
Expand Down Expand Up @@ -886,7 +886,7 @@ impl std::error::Error for CwdResolveError {
/// #[derive(clap::Parser)]
/// struct Args {
/// #[arg(long)]
/// minimal_dir: Option<sessions::paths::CwdRelative<sessions::paths::Daemon>>,
/// minimal_dir: Option<paths::CwdRelative<paths::Daemon>>,
/// }
/// ```
///
Expand All @@ -899,7 +899,7 @@ impl std::error::Error for CwdResolveError {
/// `CwdRelative<Sandbox>` is not spellable:
///
/// ```compile_fail
/// use sessions::paths::{CwdRelative, Sandbox};
/// use paths::{CwdRelative, Sandbox};
/// let _: CwdRelative<Sandbox>;
/// ```
pub struct CwdRelative<R: CwdResolvable>(EitherPath<R>);
Expand Down
1 change: 1 addition & 0 deletions crates/sessions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ publish.workspace = true
common.workspace = true
globset.workspace = true
camino.workspace = true
paths.workspace = true
serde.workspace = true
serde_json.workspace = true
uuid.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/sessions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use std::fmt;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::paths::HostAbsPath;
use paths::HostAbsPath;

pub mod lifecyclehook;
pub mod loadout;
pub mod patches;
pub mod paths;
pub mod policy;
pub mod store;
pub mod vars;
Expand Down
2 changes: 1 addition & 1 deletion crates/sessions/src/lifecyclehook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//! [`LifecycleHook::builder`] or deserialize them from configuration; both paths
//! enforce the same invariant.

use crate::paths::{self, ConfigRelPath};
use camino::Utf8PathBuf;
use core::fmt;
use paths::ConfigRelPath;

/// Errors produced when constructing a [`LifecycleHook`].
#[non_exhaustive]
Expand Down
4 changes: 2 additions & 2 deletions crates/sessions/src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
//! ignore = ["**/.DS_Store", "**/*.bak", "**/*.swp"]
//! ```

use crate::paths::{HostPath, SandboxPath};
use camino::{Utf8Component, Utf8PathBuf};
use core::fmt;
use paths::{HostPath, SandboxPath};

/// Errors produced when constructing patch types.
#[non_exhaustive]
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'de> serde::Deserialize<'de> for FileSet {
/// Wraps a [`SandboxPath`], so the realm tag is preserved through to the
/// apply layer. No `AsRef<std::path::Path>` is provided on purpose: a
/// destination path cannot be passed to host I/O without going through a
/// [`crate::paths::Translator`] first.
/// [`paths::Translator`] first.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PatchDest(SandboxPath);

Expand Down
7 changes: 4 additions & 3 deletions crates/sessions/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::paths::{DaemonAbsPath, DaemonRelPath};
use crate::{Record, SessionId, sub_path};
use paths::{DaemonAbsPath, DaemonRelPath, sub_path};

use crate::{Record, SessionId};

/// Describes the session object yielded by [`Loader`].
pub trait SessionObject: Sized + Send + 'static + std::fmt::Debug {
Expand Down Expand Up @@ -294,7 +295,7 @@ impl Loader for DiskLoader {
#[cfg(test)]
mod tests {
use super::*;
use crate::paths::HostAbsPath;
use paths::HostAbsPath;
use std::{collections::BTreeSet, io::ErrorKind};
use tempfile::TempDir;

Expand Down
Loading