Skip to content

Commit

Permalink
chore: update deps
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <m@rtin.fyi>
  • Loading branch information
Martichou committed Sep 22, 2024
1 parent fd12968 commit a2a1c18
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 51 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ edition = "2021"
sys_metrics = { git = "https://github.com/Martichou/sys_metrics" }
askama = "0.12"
actix-web = { version = "4.3", features = ["rustls"] }
actix-session = { version = "0.7", features = ["cookie-session"] }
axum = { version = "0.6" }
actix-session = { version = "0.10", features = ["cookie-session"] }
axum = { version = "0.7" }
chrono = { version = "0.4", features = ["serde"] }
diesel = { version = "2.0", features = ["postgres", "r2d2", "chrono", "uuid"] }
futures-util = "0.3"
log = "0.4"
once_cell = "1.14"
r2d2 = "0.8"
regex = "1.6"
rustls = "0.20"
rustls-pemfile = "1.0"
rustls = "0.23"
rustls-pemfile = "2.0"
serde_json = "1.0"
simd-json = "0.9"
simd-json = "0.14"
serde = { version = "1.0", features = ["derive"] }
snmalloc-rs = "0.3"
thiserror = "1.0"
ts-rs = { version = "7.1", features = ["serde-compat", "uuid-impl", "chrono-impl"] }
ts-rs = { version = "10.0", features = ["serde-compat", "uuid-impl", "chrono-impl"] }
uuid = { version = "1.1", features = ["serde", "v4"] }
walkdir = "2.3"

Expand Down
24 changes: 12 additions & 12 deletions bindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export * from "./AlertsDTOUpdate"
export * from "./IoBlock"
export * from "./IncidentsJoined"
export * from "./Incidents"
export * from "./ApiKey"
export * from "./HttpIncidentsCount"
export * from "./Customers"
export * from "./HttpAlertsCount"
export * from "./Alerts"
export * from "./Swap"
export * from "./AlertsDTO"
export * from "./CpuTimes"
export * from "./Incidents"
export * from "./Host"
export * from "./IncidentsJoined"
export * from "./IoNet"
export * from "./Memory"
export * from "./HttpIncidentsCount"
export * from "./LoadAvg"
export * from "./IoBlock"
export * from "./CpuStats"
export * from "./LoadAvg"
export * from "./AlertsDTOUpdate"
export * from "./Host"
export * from "./Swap"
export * from "./Memory"
export * from "./AlertsDTO"
export * from "./Disk"
export * from "./Customers"
export * from "./Alerts"
File renamed without changes.
43 changes: 27 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use actix_session::config::{CookieContentSecurity, PersistentSession};
use actix_session::storage::CookieSessionStore;
use actix_session::SessionMiddleware;
use diesel::{prelude::PgConnection, r2d2::ConnectionManager};
use rustls::{Certificate, PrivateKey, ServerConfig};
use rustls::{
pki_types::{CertificateDer, PrivateKeyDer},
ServerConfig,
};

use crate::apierrors::ApiError;

Expand Down Expand Up @@ -81,29 +84,37 @@ pub fn prog() -> Option<String> {
///
/// Use key and cert for the path to find the files.
pub fn get_ssl_builder(key: &str, cert: &str) -> Result<ServerConfig, ApiError> {
let key_file = &mut BufReader::new(File::open(key)?);
// Extract all PKCS8-encoded private key from key_file and generate a Vec from them
let mut keys = rustls_pemfile::pkcs8_private_keys(key_file)?;
// If no keys are found, we try using the rsa type
if keys.is_empty() {
// Reopen a new BufReader as pkcs8_private_keys took over the previous one
let key_file = &mut BufReader::new(File::open(key)?);
keys = rustls_pemfile::rsa_private_keys(key_file)?;
}
// Convert the first key to be a PrivateKey
let key: PrivateKey = PrivateKey(keys.remove(0));
let mut reader = BufReader::new(File::open(key)?);

// Try to read PKCS8 private keys first
let keys = rustls_pemfile::pkcs8_private_keys(&mut reader)
.map(|v| v.unwrap().clone_key())
.collect::<Vec<_>>();

let key = if !keys.is_empty() {
PrivateKeyDer::Pkcs8(keys[0].clone_key())
} else {
// If no PKCS8 keys are found, try to read RSA private keys
let mut reader = BufReader::new(File::open(key)?);
let keys = rustls_pemfile::rsa_private_keys(&mut reader)
.map(|v| v.unwrap().clone_key())
.collect::<Vec<_>>();

if !keys.is_empty() {
PrivateKeyDer::Pkcs1(keys[0].clone_key())
} else {
return Err(ApiError::ExplicitError("No private keys found".to_owned()));
}
};

let cert_file = &mut BufReader::new(File::open(cert)?);
// Create a Vec of certificate by extracting all cert from cert_file
let cert_chain = rustls_pemfile::certs(cert_file)
.unwrap()
.iter()
.map(|v| Certificate(v.clone()))
.map(|v| CertificateDer::from_slice(&v.unwrap().clone()).into_owned())
.collect();

// Return the ServerConfig to be used
Ok(ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(cert_chain, key)?)
}
Expand Down
6 changes: 3 additions & 3 deletions src/models/balerts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use once_cell::sync::Lazy;
use regex::Regex;

mod alerts;
mod alerts_impl;
mod alerts_querying;
Expand All @@ -8,9 +11,6 @@ pub use alerts_querying::*;
mod incidents;
mod incidents_impl;
pub use incidents::*;
pub use incidents_impl::*;
use once_cell::sync::Lazy;
use regex::Regex;

pub mod qtype;

Expand Down
2 changes: 0 additions & 2 deletions src/models/bauth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod apikeys;
mod apikeys_impl;
pub use apikeys::*;
pub use apikeys_impl::*;

mod customers;
mod customers_impl;
pub use customers::*;
pub use customers_impl::*;
8 changes: 0 additions & 8 deletions src/models/bserver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
mod cpustats;
mod cpustats_impl;
pub use cpustats::*;
pub use cpustats_impl::*;

mod cputimes;
mod cputimes_impl;
pub use cputimes::*;
pub use cputimes_impl::*;

mod disk;
mod disk_impl;
pub use disk::*;
pub use disk_impl::*;

mod hosts;
mod hosts_impl;
pub use hosts::*;
pub use hosts_impl::*;

mod ionet;
mod ionet_impl;
pub use ionet::*;
pub use ionet_impl::*;

mod ioblock;
mod ioblock_impl;
pub use ioblock::*;
pub use ioblock_impl::*;

mod loadavg;
mod loadavg_impl;
pub use loadavg::*;
pub use loadavg_impl::*;

mod memory;
mod memory_impl;
pub use memory::*;
pub use memory_impl::*;

mod swap;
mod swap_impl;
Expand Down
5 changes: 1 addition & 4 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ pub struct InnerUser {
/// which means for size = 21600 that we'll get the avg of each 60s intervals
#[inline]
pub fn get_granularity(size: i64) -> u32 {
std::cmp::min(
86400,
std::cmp::max(1, ((0.003 * size as f32) * (0.93) + 0.298206) as u32),
)
(((0.003 * size as f32) * (0.93) + 0.298206) as u32).clamp(1, 86400)
}

#[inline]
Expand Down

0 comments on commit a2a1c18

Please sign in to comment.