mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-10 23:12:54 +00:00
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
use anyhow::{bail, Result};
|
|
use std::{collections::HashMap, net::SocketAddr};
|
|
|
|
pub struct CPlaneApi {
|
|
address: SocketAddr,
|
|
}
|
|
|
|
// mock cplane api
|
|
impl CPlaneApi {
|
|
pub fn new(address: &SocketAddr) -> CPlaneApi {
|
|
CPlaneApi {
|
|
address: address.clone(),
|
|
}
|
|
}
|
|
|
|
pub fn check_auth(&self, user: &str, md5_response: &[u8], salt: &[u8; 4]) -> Result<()> {
|
|
// passwords for both is "mypass"
|
|
let auth_map: HashMap<_, &str> = vec![
|
|
("stas@zenith", "716ee6e1c4a9364d66285452c47402b1"),
|
|
("stas2@zenith", "3996f75df64c16a8bfaf01301b61d582"),
|
|
]
|
|
.into_iter()
|
|
.collect();
|
|
|
|
let stored_hash = auth_map
|
|
.get(&user)
|
|
.ok_or_else(|| anyhow::Error::msg("user not found"))?;
|
|
let salted_stored_hash = format!(
|
|
"md5{:x}",
|
|
md5::compute([stored_hash.as_bytes(), salt].concat())
|
|
);
|
|
|
|
let received_hash = std::str::from_utf8(&md5_response)?;
|
|
|
|
println!(
|
|
"auth: {} rh={} sh={} ssh={} {:?}",
|
|
user, received_hash, stored_hash, salted_stored_hash, salt
|
|
);
|
|
|
|
if received_hash == salted_stored_hash {
|
|
Ok(())
|
|
} else {
|
|
bail!("Auth failed")
|
|
}
|
|
}
|
|
|
|
fn get_database_uri(_user: String, _database: String) -> Option<String> {
|
|
Some("postgresql://localhost/stas".to_string())
|
|
}
|
|
|
|
fn create_database(_user: String, _database: String) -> Option<String> {
|
|
Some("postgresql://localhost/stas".to_string())
|
|
}
|
|
}
|