From c759db28b0815ecd47b422b7cc700fe80c0843af Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 30 Dec 2023 21:55:29 +0100 Subject: [PATCH] feat: with ssh agent Signed-off-by: kjuulh --- crates/cuddle-ci/src/rust_service.rs | 2 + .../cuddle-ci/src/rust_service/ssh_agent.rs | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 crates/cuddle-ci/src/rust_service/ssh_agent.rs diff --git a/crates/cuddle-ci/src/rust_service.rs b/crates/cuddle-ci/src/rust_service.rs index 5bcd341..1050aa9 100644 --- a/crates/cuddle-ci/src/rust_service.rs +++ b/crates/cuddle-ci/src/rust_service.rs @@ -410,6 +410,7 @@ mod clap_sanity_test; mod docker_cache; mod mold; mod sqlx; +mod ssh_agent; pub mod extensions { pub use super::apt::*; @@ -421,6 +422,7 @@ pub mod extensions { pub use super::docker_cache::*; pub use super::mold::*; pub use super::sqlx::*; + pub use super::ssh_agent::*; } #[cfg(test)] diff --git a/crates/cuddle-ci/src/rust_service/ssh_agent.rs b/crates/cuddle-ci/src/rust_service/ssh_agent.rs new file mode 100644 index 0000000..1727e46 --- /dev/null +++ b/crates/cuddle-ci/src/rust_service/ssh_agent.rs @@ -0,0 +1,55 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use dagger_sdk::{Container, Socket}; + +use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService}; + +use super::RustService; + +pub struct SshAgent { + socket: Socket, +} + +impl SshAgent { + pub fn new(socket: Socket) -> Self { + Self { socket } + } +} + +#[async_trait] +impl DaggerMiddleware for SshAgent { + async fn handle(&self, container: Container) -> eyre::Result { + let c = container.with_unix_socket("/tmp/ssh_socket", self.socket); + + Ok(c) + } +} + +pub trait SshAgentExt { + fn with_socket(&mut self, socket: dagger_sdk::Socket) -> &mut Self { + self + } +} + +impl SshAgentExt for RustService { + fn with_socket(&mut self, socket: dagger_sdk::Socket) -> &mut Self { + self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( + SshAgent::new(socket.clone()).extend(deps), + ))) + .with_stage(super::RustServiceStage::AfterBase(Arc::new( + SshAgent::new(socket.clone()).extend(deps), + ))) + } +} + +impl SshAgentExt for LeptosService { + fn with_socket(&mut self, socket: dagger_sdk::Socket) -> &mut Self { + self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( + SshAgent::new(socket.clone()).extend(deps), + ))) + .with_stage(super::RustServiceStage::AfterBase(Arc::new( + SshAgent::new(socket.clone()).extend(deps), + ))) + } +}