use log::info;
use smb::{Client, ClientConfig, ConnectionConfig, UncPath};
use std::env::var;
#[maybe_async::maybe_async]
pub async fn make_server_connection(
share: &str,
config: Option<ConnectionConfig>,
) -> Result<(Client, UncPath), Box<dyn std::error::Error>> {
let server = var("SMB_RUST_TESTS_SERVER").unwrap_or("127.0.0.1".to_string());
let user = var("SMB_RUST_TESTS_USER_NAME").unwrap_or("LocalAdmin".to_string());
let password = var("SMB_RUST_TESTS_PASSWORD").unwrap_or("123456".to_string());
let mut conn_config = config.unwrap_or(ConnectionConfig::default());
conn_config.timeout = Some(std::time::Duration::from_secs(10));
let mut smb = Client::new(ClientConfig {
connection: conn_config,
..Default::default()
});
info!("Connecting to {}", server);
let unc_path = UncPath {
server: server.clone(),
share: Some(share.to_string()),
path: None,
};
smb.share_connect(&unc_path, user.as_str(), password.clone())
.await?;
info!("Connected to {}", unc_path);
Ok((smb, unc_path))
}