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 2a0a9e4 commit 02c0aba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
14 changes: 14 additions & 0 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::{Path, PathBuf};

use crate::profile::Profile;

use eyre::Result;

impl Profile {
pub fn deploy<P>(self, flake_root: P, storage: P) -> Result<()>
where
P: AsRef<Path> + Into<PathBuf>,
{
Ok(())
}
}
6 changes: 5 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use spdlog::prelude::*;
use {argh::FromArgs, std::fmt::Debug};

mod check;
mod deploy;
mod edit;
mod renc;

Expand Down Expand Up @@ -85,7 +86,10 @@ impl Args {
info!("start re-encrypt secrets");
profile.renc(all, flake_root)
}
SubCmd::Deploy(_) => todo!(),
SubCmd::Deploy(DeploySubCmd { ref storage }) => {
info!("deploying secrets");
profile.deploy(flake_root, storage.into())
}
SubCmd::Edit(_) => todo!(),
SubCmd::Check(_) => todo!(),
}
Expand Down
36 changes: 17 additions & 19 deletions src/cmd/renc.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use age::{encrypted, x25519};
use eyre::{eyre, ContextCompat, Result};
use spdlog::{debug, error, info, trace};
use spdlog::{debug, error, info};
use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
fs::{self, File},
io::{Read, Write},
iter,
path::{Path, PathBuf},
rc::Rc,
path::PathBuf,
str::FromStr,
};

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

const SECRET_DIR: &str = "secrets";
use sha2::{Digest, Sha256};

struct RencSecretPath(PathBuf);

Expand Down Expand Up @@ -79,10 +74,6 @@ impl NamePathPair {
fn path(self) -> PathBuf {
self.1
}

fn get_base_path(&self) -> Option<&OsStr> {
self.1.file_name()
}
}

#[derive(Hash, Debug, Eq, PartialEq, Clone)]
Expand All @@ -100,6 +91,7 @@ impl NameBufPair {
}
}

use age::x25519;
impl Profile {
/// Get the `secrets.{}.file`, which in nix store
pub fn get_cipher_file_paths(&self) -> HashSet<NamePathPair> {
Expand All @@ -120,6 +112,14 @@ impl Profile {
.collect()
}

pub fn get_renced_paths(&self) -> Vec<NamePathPair> {
self.secrets
.clone()
.into_values()
.map(|i| NamePathPair(i.to_owned().id, i.to_renced_pathbuf(&self.settings).get()))
.collect()
}

pub fn get_key_pair_list<'a>(
&'a self,
) -> impl Iterator<Item = (Option<x25519::Identity>, Result<x25519::Recipient>)> + 'a {
Expand Down Expand Up @@ -168,12 +168,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: Vec<NamePathPair> = self
.secrets
.clone()
.into_values()
.map(|i| NamePathPair(i.to_owned().id, i.to_renced_pathbuf(&self.settings).get()))
.collect();
let renced_secret_paths: Vec<NamePathPair> = self.get_renced_paths();
debug!("secret paths: {:?}", renced_secret_paths);

let mut key_pair_list = self.get_key_pair_list();
Expand Down Expand Up @@ -233,7 +228,8 @@ impl Profile {
let renc_path = {
let mut p = flake_root;
p.push(self.settings.storage_dir_suffix.clone());
p.canonicalize()?
info!("reading dir {:?}", p);
p
};
if !renc_path.exists() {
let _ = fs::create_dir_all(&renc_path);
Expand All @@ -255,9 +251,11 @@ impl Profile {
if !o.status.success() {
error!("Command executed with failing error code");
}
// Another side, calculate with nix `builtins.path` and pass to when deploy as `storage`
info!("path added to store: {}", String::from_utf8(o.stdout)?);
};

Ok(())
}
}
// Seems too long huh

0 comments on commit 02c0aba

Please sign in to comment.