feat: with opinionated ssh auth sock fetch
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-12-30 22:07:44 +01:00
parent 830e39e8bf
commit 97b70164d1
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -2,56 +2,66 @@ use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use dagger_sdk::{Container, Socket}; use dagger_sdk::{Container, Socket};
use eyre::Context;
use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService}; use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService};
use super::RustService; use super::RustService;
pub struct SshAgent { pub struct SshAgent {
socket: Socket, client: dagger_sdk::Query,
} }
impl SshAgent { impl SshAgent {
pub fn new(socket: Socket) -> Self { pub fn new(client: dagger_sdk::Query) -> Self {
Self { socket } Self { client }
} }
} }
#[async_trait] #[async_trait]
impl DaggerMiddleware for SshAgent { impl DaggerMiddleware for SshAgent {
async fn handle(&self, container: Container) -> eyre::Result<Container> { async fn handle(&self, container: Container) -> eyre::Result<Container> {
let sock_var =
std::env::var("SSH_AUTH_SOCK").context("failed to find variable SSH_AUTH_SOCK")?;
let socket = self.client.host().unix_socket(&sock_var);
let c = container let c = container
.with_unix_socket("/tmp/ssh_socket", self.socket.clone()) .with_unix_socket(&sock_var, socket)
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_socket"); .with_env_variable("SSH_AUTH_SOCK", &sock_var);
Ok(c) Ok(c)
} }
} }
pub trait SshAgentExt { pub trait SshAgentExt {
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self { fn with_ssh_agent(&mut self) -> &mut Self {
self self
} }
} }
impl SshAgentExt for RustService { impl SshAgentExt for RustService {
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self { fn with_ssh_agent(&mut self) -> &mut Self {
let client = self.client.clone();
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
SshAgent::new(socket.clone()), SshAgent::new(client.clone()),
))) )))
.with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new( .with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new(
socket.clone(), client,
)))) ))))
} }
} }
impl SshAgentExt for LeptosService { impl SshAgentExt for LeptosService {
fn with_ssh_agent(&mut self, socket: dagger_sdk::Socket) -> &mut Self { fn with_ssh_agent(&mut self) -> &mut Self {
let client = self.client.clone();
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
SshAgent::new(socket.clone()), SshAgent::new(client.clone()),
))) )))
.with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new( .with_stage(super::RustServiceStage::AfterBase(Arc::new(SshAgent::new(
socket.clone(), client,
)))) ))))
} }
} }