Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Sep 15, 2024
1 parent b6b81e5 commit 5f40f7e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
68 changes: 56 additions & 12 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
use std::{
collections::HashMap,
fs,
fs::{self, DirEntry, ReadDir},
io::ErrorKind,
path::{Path, PathBuf},
};

use crate::profile::Profile;

use eyre::Result;
use spdlog::debug;
use eyre::{eyre, Context, Result};
use spdlog::{debug, error, info};

impl Profile {
pub fn get_decrypted_mount_point_path(&self) -> String {
self.settings.decrypted_mount_point.to_string()
}
pub fn get_decrypt_dir_path(&self) -> String {
self.settings.decrypted_dir.to_string()
}
pub fn read_decrypted_mount_point(&self) -> std::io::Result<ReadDir> {
fs::read_dir(self.get_decrypted_mount_point_path())
}
/// init decrypted mount point and return the generation count
pub fn init_decrypted_mount_point(&self) -> Result<usize> {
let mut max = 0;
let b = match self.read_decrypted_mount_point() {
Err(e) if e.kind() == ErrorKind::NotFound => {
fs::create_dir_all(self.get_decrypted_mount_point_path())
.wrap_err("create decrypted mountpoint error")
}
Err(e) => {
error!("{}", e);
Err(e).wrap_err(eyre!("read mountpoint error"))
}
Ok(o) => {
o.for_each(|en| {
match str::parse::<usize>(
en.unwrap()
.file_name()
.to_string_lossy()
.to_string()
.as_str(),
) {
Err(e) => {
error!("parse mount point generation err: {:?}", e)
}
Ok(res) => {
info!("found mountpoint generation {}", res);
if res > max {
max = res;
}
}
}
});
Ok(())
}
};

Ok(max)
}
/**
extract secrets to `/run/vaultix.d/$num` and link to `/run/vaultix`
*/
pub fn deploy(self) -> Result<()> {
let storage_name_ctt_map: HashMap<String, Vec<u8>> = {
let mut map = HashMap::new();
Expand All @@ -29,17 +80,10 @@ impl Profile {
map
};

// for entry in storage_ctt {
// let entry = entry?;
// let path = entry.path();

// debug!("found renced secret in store: {:?}", path);
// }

let secs_map = self.get_renced_paths().into_map();
let secs_map = self.get_renced_store_paths().into_map();

for s in secs_map.values().into_iter() {
debug!("found cipher file {:?}", s);
debug!("found cipher file {:?}", s.canonicalize()?);
}

Ok(())
Expand Down
13 changes: 9 additions & 4 deletions src/cmd/renc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::profile::{MasterIdentity, Profile, Settings};
use crate::{interop::add_to_store, profile};

impl profile::Secret {
fn to_renced_pathbuf(self, settings: &Settings) -> StoredSecretPath {
fn to_renced_store_pathbuf(self, settings: &Settings) -> StoredSecretPath {
StoredSecretPath::init_from(settings, &self)
}
}
Expand Down Expand Up @@ -85,12 +85,17 @@ impl Profile {
.collect()
}

pub fn get_renced_paths(&self) -> NamePathPairList {
pub fn get_renced_store_paths(&self) -> NamePathPairList {
NamePathPairList(
self.secrets
.clone()
.into_values()
.map(|i| NamePathPair(i.to_owned().id, i.to_renced_pathbuf(&self.settings).get()))
.map(|i| {
NamePathPair(
i.to_owned().id,
i.to_renced_store_pathbuf(&self.settings).get(),
)
})
.collect(),
)
}
Expand Down Expand Up @@ -143,7 +148,7 @@ impl Profile {
pub fn renc(self, _all: bool, flake_root: PathBuf) -> Result<()> {
use age::ssh;
let cipher_contents = self.get_cipher_contents();
let renced_secret_paths: NamePathPairList = self.get_renced_paths();
let renced_secret_paths: NamePathPairList = self.get_renced_store_paths();
debug!("secret paths: {:?}", renced_secret_paths);

let mut key_pair_list = self.get_key_pair_list();
Expand Down

0 comments on commit 5f40f7e

Please sign in to comment.