2023-12-30 21:55:29 +01:00
|
|
|
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<Container> {
|
2023-12-30 21:58:17 +01:00
|
|
|
let c = container.with_unix_socket("/tmp/ssh_socket", self.socket.clone());
|
2023-12-30 21:55:29 +01:00
|
|
|
|
|
|
|
Ok(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait SshAgentExt {
|
2023-12-30 21:59:21 +01:00
|
|
|
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self {
|
2023-12-30 21:55:29 +01:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SshAgentExt for RustService {
|
2023-12-30 21:59:21 +01:00
|
|
|
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self {
|
2023-12-30 21:55:29 +01:00
|
|
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
2023-12-30 21:58:17 +01:00
|
|
|
SshAgent::new(socket.clone()),
|
2023-12-30 21:55:29 +01:00
|
|
|
)))
|
2023-12-30 21:58:17 +01:00
|
|
|
.with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new(
|
|
|
|
socket.clone(),
|
|
|
|
))))
|
2023-12-30 21:55:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SshAgentExt for LeptosService {
|
2023-12-30 21:59:21 +01:00
|
|
|
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self {
|
2023-12-30 21:55:29 +01:00
|
|
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
2023-12-30 21:58:17 +01:00
|
|
|
SshAgent::new(socket.clone()),
|
2023-12-30 21:55:29 +01:00
|
|
|
)))
|
2023-12-30 21:58:17 +01:00
|
|
|
.with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new(
|
|
|
|
socket.clone(),
|
|
|
|
))))
|
2023-12-30 21:55:29 +01:00
|
|
|
}
|
|
|
|
}
|