diff --git a/src/daemon_backend.rs b/src/daemon_backend.rs index bb55d70..52dcff5 100644 --- a/src/daemon_backend.rs +++ b/src/daemon_backend.rs @@ -1,13 +1,13 @@ -use std::fmt::Debug; +use std::{fmt::Debug, sync::Arc}; use futures_util::{SinkExt, StreamExt}; use giterated_models::{ - authenticated::Authenticated, + authenticated::{Authenticated, AuthenticationSourceProviders}, error::OperationError, message::GiteratedMessage, object::{GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse}, object_backend::ObjectBackend, - operation::{GiteratedOperation, GiteratedOperationState}, + operation::GiteratedOperation, }; use serde::de::DeserializeOwned; use tokio_tungstenite::tungstenite::Message; @@ -15,11 +15,22 @@ use tokio_tungstenite::tungstenite::Message; use crate::{DaemonConnectionPool, Socket}; #[derive(Clone)] -pub struct NetworkOperationState {} +pub struct NetworkOperationState { + authentication: Vec>, +} impl NetworkOperationState { pub fn new() -> Self { - Self {} + Self { + authentication: vec![], + } + } + + pub fn authenticate( + &mut self, + source: S, + ) { + self.authentication.push(Arc::new(source)) } } @@ -44,7 +55,10 @@ impl ObjectBackend for DaemonConnectionPool { .await .map_err(|e| OperationError::Internal(e.to_string()))?; - let authenticated = Authenticated::new(message); + let mut authenticated = Authenticated::new(message); + for authentication in &operation_state.authentication { + authenticated.append_authentication(authentication.clone()); + } send_expect(&mut connection, authenticated).await } @@ -68,7 +82,10 @@ impl ObjectBackend for DaemonConnectionPool { .await .map_err(|e| OperationError::Internal(e.to_string()))?; - let authenticated = Authenticated::new(message); + let mut authenticated = Authenticated::new(message); + for authentication in &operation_state.authentication { + authenticated.append_authentication(authentication.clone()); + } let object_raw: ObjectResponse = send_expect(&mut connection, authenticated).await?; Ok(unsafe { diff --git a/src/main.rs b/src/main.rs index d9733d7..9d50e86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,13 +2,16 @@ use std::str::FromStr; use giterated_api::{daemon_backend::NetworkOperationState, DaemonConnectionPool}; use giterated_models::{ + authenticated::{InstanceAuthenticator, UserAuthenticator}, instance::Instance, object_backend::ObjectBackend, - repository::Repository, + repository::{AccessList, Repository}, + settings::AnySetting, user::{DisplayName, User}, }; use color_eyre::eyre::Result; +use tokio::{fs::File, io::AsyncReadExt}; use tracing::info; #[tokio::main] @@ -22,7 +25,7 @@ async fn main() -> Result<()> { ) .unwrap(); - let operation_state = NetworkOperationState::new(); + let mut operation_state = NetworkOperationState::new(); let mut user = pool .get_object::("ambee:giterated.dev", &operation_state)