Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ignore = [
#"RUSTSEC-0000-0000",
"RUSTSEC-2021-0127", # serde_cbor as optional transitive dep: https://github.com/mozilla/authenticator-rs/issues/327
"RUSTSEC-2024-0436",
# ratatui is going to be updated soon
"RUSTSEC-2026-0002",
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
#"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish
#{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" },
Expand Down
2 changes: 1 addition & 1 deletion openstack_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ passkey = ["keystone_ng", "dep:webauthn-authenticator-rs", "dep:webauthn-rs-prot
[dependencies]
async-trait = {workspace = true}
base64 = { workspace = true }
bincode = { version = "^2.0", default-features = false, features = ["serde", "std"] }
bytes = {workspace = true}
chrono = { workspace= true }
config = { workspace = true, features = ["yaml"] }
Expand All @@ -63,6 +62,7 @@ hyper-util = { version = "^0.1", features = ["full"] }
itertools = { workspace = true }
json-patch = { workspace = true }
open.workspace = true
postcard = { version = "1.1", default-features = false, features = ["use-std"] }
regex = { workspace = true }
reqwest = { workspace = true, features = ["gzip", "deflate", "form", "http2",
"socks", "system-proxy"] }
Expand Down
63 changes: 25 additions & 38 deletions openstack_sdk/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,15 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs::{DirBuilder, File};
use std::io::prelude::*;
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
//use thiserror::Error;
use tracing::{debug, info, trace, warn};

use crate::auth::{
authtoken::{AuthToken, AuthTokenScope},
AuthState,
};

// /// Errors which may occur when creating connection state data.
// #[derive(Debug, Error)]
// #[non_exhaustive]
// pub enum StateError {
// #[error("failed to deserialize config: {}", source)]
// Parse {
// /// The source of the error.
// #[from]
// source: config::ConfigError,
// },
// #[error("IO error: {}", source)]
// IO {
// /// The source of the error.
// #[from]
// source: std::io::Error,
// },
// }

/// A HashMap of Scope to Token
#[derive(Clone, Default, Deserialize, Serialize, Debug)]
pub(crate) struct ScopeAuths(HashMap<AuthTokenScope, AuthToken>);
Expand Down Expand Up @@ -246,37 +228,34 @@ impl State {
Ok(mut file) => {
let mut contents = vec![];
match file.read_to_end(&mut contents) {
Ok(_) => match bincode::serde::decode_from_slice(
&contents,
bincode::config::legacy(),
) {
Ok::<(ScopeAuths, usize), _>((mut auth, _)) => {
Ok(_) => match postcard::from_bytes::<ScopeAuths>(&contents) {
Ok(mut auth) => {
auth.filter_invalid_auths();
trace!("Cached Auth info: {:?}", auth);
Some(auth)
}
Err(x) => {
info!(
"Corrupted cache file {}: {:?}. Removing ",
"Corrupted cache file `{}`: {:?}. Removing ",
fname.display(),
x
);
let _ = std::fs::remove_file(fname);
None
}
},
_ => {
Err(e) => {
// Not able to read file, maybe it is corrupted. There is nothing user can
// or is expected to do about it, but it make sense to make user aware of.
info!("Error reading file {}", fname.display());
info!("Error reading file `{}`: {:?}", fname.display(), e);
None
}
}
}
_ => {
Err(e) => {
// Not able to open file, maybe it is missing. There is nothing user can or is
// expected to do about it.
debug!("Error opening file {}", fname.display());
debug!("Error opening file `{}`: {:?}", fname.display(), e);
None
}
}
Expand All @@ -291,17 +270,25 @@ impl State {

let _ = state.0.insert(scope.clone(), data.clone());

match bincode::serde::encode_to_vec(&state, bincode::config::legacy()) {
Ok(ser_data) => match File::create(fname.as_path()) {
Ok(mut file) => {
let _ = file.write_all(&ser_data);
match File::create(fname.as_path()) {
Ok(mut file) => {
match file.metadata() {
Ok(metadata) => {
let mut permissions = metadata.permissions();
permissions.set_mode(0o600);
let _ = file.set_permissions(permissions);
}
Err(_) => {
warn!("Cannot set permissions for the cache file");
return;
}
}
_ => {
warn!("Error writing state file");
if let Err(e) = postcard::to_io(&state, &mut file) {
warn!("Error serializing state: {:?}", e);
}
},
Err(e) => {
warn!("Error serializing state, {:?}", e);
}
_ => {
warn!("Error writing state file");
}
}
}
Expand Down