Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Sep 14, 2024
1 parent a72aa2a commit 1b8344c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 90 deletions.
97 changes: 9 additions & 88 deletions flake.lock

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

11 changes: 11 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum SubCmd {
Renc(RencSubCmd),
Edit(EditSubCmd),
Check(CheckSubCmd),
Deploy(DeploySubCmd),
}

#[derive(FromArgs, PartialEq, Debug)]
Expand All @@ -46,6 +47,15 @@ pub struct EditSubCmd {
file: String,
}

#[derive(FromArgs, PartialEq, Debug)]
/// Decrypt and deploy cipher credentials
#[argh(subcommand, name = "deploy")]
pub struct DeploySubCmd {
#[argh(positional, short = 's')]
/// per hostkey encrypted dir
storage: String,
}

#[derive(FromArgs, PartialEq, Debug)]
/// Check secret status
#[argh(subcommand, name = "check")]
Expand Down Expand Up @@ -75,6 +85,7 @@ impl Args {
info!("start re-encrypt secrets");
profile.renc(all, flake_root)
}
SubCmd::Deploy(_) => todo!(),
SubCmd::Edit(_) => todo!(),
SubCmd::Check(_) => todo!(),
}
Expand Down
11 changes: 9 additions & 2 deletions src/cmd/renc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use age::{encrypted, x25519};
use eyre::{eyre, ContextCompat, Result};
use spdlog::{debug, info, trace};
use spdlog::{debug, error, info, trace};
use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
Expand All @@ -12,8 +12,8 @@ use std::{
str::FromStr,
};

use crate::profile;
use crate::profile::{MasterIdentity, Profile, Settings};
use crate::{interop::add_to_store, profile};
use sha2::{digest::Key, Digest, Sha256};

const SECRET_DIR: &str = "secrets";
Expand All @@ -36,6 +36,7 @@ impl RencSecretPath {
debug!("public key hash: {}", pubkey_hash);

let profile::Secret { file, name, .. } = secret;
// TODO: here the storage_dir_path jiziwa no use
let secret_file_path = {
hasher.update(file);
let secret_file_string_hash = format!("{:x}", hasher.clone().finalize());
Expand All @@ -50,6 +51,7 @@ impl RencSecretPath {
debug!("identity hash: {}", ident_hash);

let mut storage_dir_path = PathBuf::from(storage_dir_suffix);
info!("storage dir path prefix: {:?}", storage_dir_path);
storage_dir_path.push(format!("{}-{}.age", ident_hash, name));
storage_dir_path
};
Expand Down Expand Up @@ -252,6 +254,11 @@ impl Profile {
let _ = fd.write_all(&i.1[..]);
}
}
let o = add_to_store(renc_path)?;
if !o.status.success() {
error!("Command executed with failing error code");
}
info!("path added to store: {}", String::from_utf8(o.stdout)?);
};

Ok(())
Expand Down
14 changes: 14 additions & 0 deletions src/interop/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
use std::{
path::Path,
process::{Command, Output},
};

use eyre::{eyre, Context, Result};

pub fn add_to_store<P: AsRef<Path>>(p: P) -> Result<Output> {
Command::new("nix")
.arg("store")
.arg("add-path")
.arg(p.as_ref())
.output()
.map_err(|i| eyre!("nix cmd run failed {}", i))
}

0 comments on commit 1b8344c

Please sign in to comment.