Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-22 05:10:29 +01:00
Remove read_file and read_file_string and replace them with the std alternatives
Dieser Commit ist enthalten in:
Ursprung
7cbcad0e38
Commit
c9376e3126
5 geänderte Dateien mit 6 neuen und 19 gelöschten Zeilen
|
@ -536,15 +536,14 @@ async fn get_release_info(has_http_access: bool, running_within_docker: bool) ->
|
||||||
|
|
||||||
#[get("/diagnostics")]
|
#[get("/diagnostics")]
|
||||||
async fn diagnostics(_token: AdminToken, ip_header: IpHeader, conn: DbConn) -> ApiResult<Html<String>> {
|
async fn diagnostics(_token: AdminToken, ip_header: IpHeader, conn: DbConn) -> ApiResult<Html<String>> {
|
||||||
use crate::util::read_file_string;
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
// Get current running versions
|
// Get current running versions
|
||||||
let web_vault_version: WebVaultVersion =
|
let web_vault_version: WebVaultVersion =
|
||||||
match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "vw-version.json")) {
|
match std::fs::read_to_string(&format!("{}/{}", CONFIG.web_vault_folder(), "vw-version.json")) {
|
||||||
Ok(s) => serde_json::from_str(&s)?,
|
Ok(s) => serde_json::from_str(&s)?,
|
||||||
_ => match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "version.json")) {
|
_ => match std::fs::read_to_string(&format!("{}/{}", CONFIG.web_vault_folder(), "version.json")) {
|
||||||
Ok(s) => serde_json::from_str(&s)?,
|
Ok(s) => serde_json::from_str(&s)?,
|
||||||
_ => WebVaultVersion {
|
_ => WebVaultVersion {
|
||||||
version: String::from("Version file missing"),
|
version: String::from("Version file missing"),
|
||||||
|
|
|
@ -11,7 +11,6 @@ use serde::ser::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{Error, MapResult},
|
error::{Error, MapResult},
|
||||||
util::read_file,
|
|
||||||
CONFIG,
|
CONFIG,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,13 +29,13 @@ static JWT_ADMIN_ISSUER: Lazy<String> = Lazy::new(|| format!("{}|admin", CONFIG.
|
||||||
static JWT_SEND_ISSUER: Lazy<String> = Lazy::new(|| format!("{}|send", CONFIG.domain_origin()));
|
static JWT_SEND_ISSUER: Lazy<String> = Lazy::new(|| format!("{}|send", CONFIG.domain_origin()));
|
||||||
|
|
||||||
static PRIVATE_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
|
static PRIVATE_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
|
||||||
read_file(&CONFIG.private_rsa_key()).unwrap_or_else(|e| panic!("Error loading private RSA Key.\n{}", e))
|
std::fs::read(&CONFIG.private_rsa_key()).unwrap_or_else(|e| panic!("Error loading private RSA Key.\n{}", e))
|
||||||
});
|
});
|
||||||
static PRIVATE_RSA_KEY: Lazy<EncodingKey> = Lazy::new(|| {
|
static PRIVATE_RSA_KEY: Lazy<EncodingKey> = Lazy::new(|| {
|
||||||
EncodingKey::from_rsa_pem(&PRIVATE_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding private RSA Key.\n{}", e))
|
EncodingKey::from_rsa_pem(&PRIVATE_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding private RSA Key.\n{}", e))
|
||||||
});
|
});
|
||||||
static PUBLIC_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
|
static PUBLIC_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
|
||||||
read_file(&CONFIG.public_rsa_key()).unwrap_or_else(|e| panic!("Error loading public RSA Key.\n{}", e))
|
std::fs::read(&CONFIG.public_rsa_key()).unwrap_or_else(|e| panic!("Error loading public RSA Key.\n{}", e))
|
||||||
});
|
});
|
||||||
static PUBLIC_RSA_KEY: Lazy<DecodingKey> = Lazy::new(|| {
|
static PUBLIC_RSA_KEY: Lazy<DecodingKey> = Lazy::new(|| {
|
||||||
DecodingKey::from_rsa_pem(&PUBLIC_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding public RSA Key.\n{}", e))
|
DecodingKey::from_rsa_pem(&PUBLIC_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding public RSA Key.\n{}", e))
|
||||||
|
|
|
@ -91,8 +91,7 @@ macro_rules! make_config {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_file(path: &str) -> Result<Self, Error> {
|
fn from_file(path: &str) -> Result<Self, Error> {
|
||||||
use crate::util::read_file_string;
|
let config_str = std::fs::read_to_string(path)?;
|
||||||
let config_str = read_file_string(path)?;
|
|
||||||
serde_json::from_str(&config_str).map_err(Into::into)
|
serde_json::from_str(&config_str).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,7 +328,7 @@ fn check_rsa_keys() -> Result<(), crate::error::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !util::file_exists(&pub_path) {
|
if !util::file_exists(&pub_path) {
|
||||||
let rsa_key = openssl::rsa::Rsa::private_key_from_pem(&util::read_file(&priv_path)?)?;
|
let rsa_key = openssl::rsa::Rsa::private_key_from_pem(&std::fs::read(&priv_path)?)?;
|
||||||
|
|
||||||
let pub_key = rsa_key.public_key_to_pem()?;
|
let pub_key = rsa_key.public_key_to_pem()?;
|
||||||
crate::util::write_file(&pub_path, &pub_key)?;
|
crate::util::write_file(&pub_path, &pub_key)?;
|
||||||
|
|
10
src/util.rs
10
src/util.rs
|
@ -308,11 +308,6 @@ pub fn file_exists(path: &str) -> bool {
|
||||||
Path::new(path).exists()
|
Path::new(path).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_file(path: &str) -> IOResult<Vec<u8>> {
|
|
||||||
let contents = fs::read(Path::new(path))?;
|
|
||||||
Ok(contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> {
|
pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
let mut f = File::create(path)?;
|
let mut f = File::create(path)?;
|
||||||
|
@ -321,11 +316,6 @@ pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error>
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_file_string(path: &str) -> IOResult<String> {
|
|
||||||
let contents = fs::read_to_string(Path::new(path))?;
|
|
||||||
Ok(contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_file(path: &str) -> IOResult<()> {
|
pub fn delete_file(path: &str) -> IOResult<()> {
|
||||||
let res = fs::remove_file(path);
|
let res = fs::remove_file(path);
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren