Unfinished work to skip auth printouts for JSON when none is an option

unused/TracingSupport
Chip Senkbeil 11 months ago
parent 3f2f0affb1
commit 2d9363fe6a
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -5,11 +5,13 @@ use async_trait::async_trait;
use crate::authenticator::Authenticator;
use crate::methods::AuthenticationMethod;
/// Authenticaton method for a static secret key
/// Authenticaton method that skips authentication and approves anything.
#[derive(Clone, Debug)]
pub struct NoneAuthenticationMethod;
impl NoneAuthenticationMethod {
pub const ID: &str = "none";
#[inline]
pub fn new() -> Self {
Self
@ -26,7 +28,7 @@ impl Default for NoneAuthenticationMethod {
#[async_trait]
impl AuthenticationMethod for NoneAuthenticationMethod {
fn id(&self) -> &'static str {
"none"
Self::ID
}
async fn authenticate(&self, _: &mut dyn Authenticator) -> io::Result<()> {

@ -14,6 +14,8 @@ pub struct StaticKeyAuthenticationMethod<T> {
}
impl<T> StaticKeyAuthenticationMethod<T> {
pub const ID: &str = "static_key";
#[inline]
pub fn new(key: T) -> Self {
Self { key }
@ -26,7 +28,7 @@ where
T: FromStr + PartialEq + Send + Sync,
{
fn id(&self) -> &'static str {
"static_key"
Self::ID
}
async fn authenticate(&self, authenticator: &mut dyn Authenticator) -> io::Result<()> {

@ -4,7 +4,8 @@ use std::time::Duration;
use async_trait::async_trait;
use distant_core::net::auth::msg::*;
use distant_core::net::auth::{
AuthHandler, AuthMethodHandler, PromptAuthMethodHandler, SingleAuthHandler,
AuthHandler, AuthMethodHandler, NoneAuthenticationMethod, PromptAuthMethodHandler,
SingleAuthHandler,
};
use distant_core::net::client::{Client as NetClient, ClientConfig, ReconnectStrategy};
use distant_core::net::manager::ManagerClient;
@ -145,11 +146,16 @@ impl<T: AuthHandler + Clone> Client<T> {
pub struct JsonAuthHandler {
tx: MsgSender,
rx: MsgReceiver,
skip: bool,
}
impl JsonAuthHandler {
pub fn new(tx: MsgSender, rx: MsgReceiver) -> Self {
Self { tx, rx }
Self {
tx,
rx,
skip: false,
}
}
}
@ -165,6 +171,23 @@ impl AuthHandler for JsonAuthHandler {
&mut self,
initialization: Initialization,
) -> io::Result<InitializationResponse> {
// NOTE: This is a hack to skip the need for authentication prompting when a "none"
// method is available as the server should then reply with the on_finished
// status automatically.
if initialization
.methods
.iter()
.any(|id| id == NoneAuthenticationMethod::ID)
{
self.skip = true;
// NOTE: We only send back the none auth method to ensure that it is performed
// first to avoid blocking waiting on failing a different method.
return Ok(InitializationResponse {
methods: vec![NoneAuthenticationMethod::ID.to_string()],
});
}
self.tx
.send_blocking(&Authentication::Initialization(initialization))?;
let response = self.rx.recv_blocking::<AuthenticationResponse>()?;
@ -179,12 +202,20 @@ impl AuthHandler for JsonAuthHandler {
}
async fn on_start_method(&mut self, start_method: StartMethod) -> io::Result<()> {
if self.skip {
return Ok(());
}
self.tx
.send_blocking(&Authentication::StartMethod(start_method))?;
Ok(())
}
async fn on_finished(&mut self) -> io::Result<()> {
if self.skip {
return Ok(());
}
self.tx.send_blocking(&Authentication::Finished)?;
Ok(())
}

@ -17,7 +17,6 @@ fn should_handle_large_volume_of_requests(ctx: DistantManagerCtx) {
// Perform many requests of writing a file and reading a file
for i in 1..100 {
println!("Writing {i} to file {path:?}");
ctx.new_assert_cmd(["fs", "write"])
.arg(path.to_str().unwrap())
.write_stdin(format!("idx: {i}"))

Loading…
Cancel
Save