Skip to content

Commit

Permalink
+ switch logger for avoid ub
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Nov 19, 2024
1 parent 3236850 commit 6d393ef
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 284 deletions.
372 changes: 124 additions & 248 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ path = "src/lib.rs"
age = { git = "https://github.com/str4d/rage.git",rev = "baf277a749c839e49f93bffb58d36734ac94be83", features = ["ssh", "plugin"]}
argh = "0.1.12"
blake3 = "1.5.4"
colog = "1.3.0"
console = "0.15.8"
edit = "0.1.5"
eyre = "0.6.12"
hex = "0.4.3"
hex-literal = "0.4.1"
libc = "0.2.158"
log = "0.4.22"
nom = "7.1.3"
pinentry = "0.5.1"
rpassword = "7.3.1"
serde = "1.0.210"
serde_json = "1.0.132"
sha2 = "0.10.8"
spdlog-rs = "0.3.13"
subtle = "2.6.1"
sys-mount = "3.0.1"

Expand Down
6 changes: 3 additions & 3 deletions dev/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
};

# for vm testing log
systemd.services.vaultix-activate.serviceConfig.Environment = [ "SPDLOG_RS_LEVEL=trace" ];
systemd.services.vaultix-activate.serviceConfig.Environment = [ "RUST_LOG=trace" ];
}
)

Expand Down Expand Up @@ -128,7 +128,7 @@
};

# for vm testing log
systemd.services.vaultix-activate.serviceConfig.Environment = [ "SPDLOG_RS_LEVEL=trace" ];
systemd.services.vaultix-activate.serviceConfig.Environment = [ "RUST_LOG=trace" ];
})

./configuration.nix
Expand Down Expand Up @@ -172,7 +172,7 @@
};

# for vm testing log
systemd.services.vaultix-activate.serviceConfig.Environment = [ "SPDLOG_RS_LEVEL=trace" ];
systemd.services.vaultix-activate.serviceConfig.Environment = [ "RUST_LOG=trace" ];
})

./configuration.nix
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use eyre::Result;
use spdlog::{debug, error};
use log::{debug, error};

use crate::{
helper::stored::{InStore, SecMap, SecPath},
Expand Down
18 changes: 9 additions & 9 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use age::Recipient;
use eyre::{eyre, Context, ContextCompat, Result};
use hex::decode;
use lib::extract_all_hashes;
use spdlog::{debug, error, info, trace};
use log::{debug, error, info};
use sys_mount::{Mount, MountFlags, SupportedFilesystems};

impl HostKey {
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Profile {
ret
} else {
if PathBuf::from($obj.path()).starts_with(&default_path) {
spdlog::warn!(
log::warn!(
"extract to decryptedDir detected. recommend specify `name` instead of `path`."
);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Profile {
})
.for_each(|(k, v)| {
// render and insert
trace!("template before process: {}", template);
log::trace!("template before process: {}", template);

let raw_composed_insertial = String::from_utf8_lossy(v).to_string();

Expand Down Expand Up @@ -290,11 +290,6 @@ impl Profile {
} else {
self.decrypted_dir()
};
info!(
"link decrypted dir {} to {}",
target_extract_dir_with_gen.display(),
symlink_dst
);

match std::fs::remove_file(symlink_dst) {
Err(e) if e.kind() == io::ErrorKind::NotFound => {}
Expand All @@ -303,7 +298,12 @@ impl Profile {
debug!("old symlink removed");
}
}
// link back to /run/vaultix*

info!(
"linking decrypted dir {} to {}",
target_extract_dir_with_gen.display(),
symlink_dst
);
std::os::unix::fs::symlink(target_extract_dir_with_gen, symlink_dst)
.wrap_err_with(|| "create symlink error")
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::helper::{

use age::Recipient;
use eyre::{eyre, Context, ContextCompat};
use log::info;
use nom::AsBytes;
use spdlog::info;

use super::EditSubCmd;

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fs, path::PathBuf};

use eyre::{eyre, Context, ContextCompat};
use spdlog::prelude::*;
use log::{debug, info};
use {argh::FromArgs, std::fmt::Debug};

mod check;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/renc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use eyre::{eyre, Context, Result};
use spdlog::{debug, error, info};
use log::{debug, error, info};
use std::{fs, path::PathBuf};

use crate::{
Expand Down
3 changes: 1 addition & 2 deletions src/helper/secret_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::rc::Rc;
use std::{io::Read, iter, marker::PhantomData};

use age::{Identity, Recipient};
use spdlog::debug;

#[derive(Debug, Clone)]
pub struct AgeEnc;
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -71,6 +69,7 @@ impl SecBuf<AgeEnc> {
}
}
use eyre::eyre;
use log::debug;

use super::set_owner_group;

Expand Down
2 changes: 1 addition & 1 deletion src/helper/set_owner_group.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use eyre::{eyre, Result};
use libc::{fchown, getgrnam, getpwnam};
use spdlog::warn;
use log::warn;
use std::{ffi::CString, fs::File, os::fd::AsRawFd};

pub fn set_owner_and_group(file: &File, owner: &str, group: &str) -> Result<()> {
Expand Down
7 changes: 3 additions & 4 deletions src/helper/stored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ use std::{
rc::Rc,
};

use age::{Identity, Recipient};
use eyre::Context;
use spdlog::{debug, trace};

use crate::{
helper::secret_buf::{AgeEnc, SecBuf},
profile::{self, Secret, SecretSet},
};
use age::{Identity, Recipient};
use eyre::Context;
use eyre::{eyre, Result};
use log::{debug, trace};
use std::marker::PhantomData;

use super::secret_buf::HostEnc;
Expand Down
13 changes: 1 addition & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
#![feature(iterator_try_collect)]
use cmd::Args;
use eyre::Result;
use spdlog::formatter::{pattern, PatternFormatter};

mod cmd;
mod helper;
mod interop;
mod parser;
mod profile;
use std::os::unix::process::parent_id;

fn main() -> Result<()> {
let _ = spdlog::init_env_level();
let as_sd_unit = parent_id() == 1;
if as_sd_unit {
for sink in spdlog::default_logger().sinks() {
sink.set_formatter(Box::new(PatternFormatter::new(pattern!(
"{^{level}} - {payload}{eol}"
))))
}
spdlog::debug!("Detected running as systemd unit");
}
colog::init();
let args: Args = argh::from_env();
args.ayaya()
}

0 comments on commit 6d393ef

Please sign in to comment.