-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specific files to be re-encrypted with --rekey
#149
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,7 +12,7 @@ pub(crate) struct Opts { | |||||
pub edit: Option<String>, | ||||||
pub editor: Option<String>, | ||||||
pub identities: Option<Vec<String>>, | ||||||
pub rekey: bool, | ||||||
pub rekey: Option<Vec<String>>, | ||||||
pub rules: String, | ||||||
pub schema: bool, | ||||||
pub verbose: bool, | ||||||
|
@@ -35,10 +35,12 @@ fn build() -> Command { | |||||
) | ||||||
.arg( | ||||||
Arg::new("rekey") | ||||||
.help("re-encrypts all secrets with specified recipients") | ||||||
.help("re-encrypts secrets with specified recipients") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.long("rekey") | ||||||
.short('r') | ||||||
.action(ArgAction::SetTrue), | ||||||
.num_args(0..) | ||||||
.value_name("FILE") | ||||||
.value_hint(ValueHint::FilePath), | ||||||
) | ||||||
.arg( | ||||||
Arg::new("identity") | ||||||
|
@@ -107,7 +109,9 @@ where | |||||
identities: matches | ||||||
.get_many::<String>("identity") | ||||||
.map(|vals| vals.cloned().collect::<Vec<_>>()), | ||||||
rekey: matches.get_flag("rekey"), | ||||||
rekey: matches | ||||||
.get_many::<String>("rekey") | ||||||
.map(|vals| vals.cloned().collect::<Vec<_>>()), | ||||||
rules: matches | ||||||
.get_one::<String>("rules") | ||||||
.cloned() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use color_eyre::eyre::{eyre, Result}; | ||
use std::{env, fs, path::Path, process}; | ||
use std::{env, path::PathBuf, process}; | ||
|
||
mod age; | ||
mod cli; | ||
|
@@ -29,10 +29,7 @@ fn main() -> Result<()> { | |
let identities = opts.identities.unwrap_or_default(); | ||
|
||
if let Some(path) = &opts.edit { | ||
let path_normalized = util::normalize_path(Path::new(path)); | ||
let edit_path = std::env::current_dir() | ||
.and_then(fs::canonicalize) | ||
.map(|p| p.join(path_normalized))?; | ||
let edit_path = util::canonicalize_rule_path(path)?; | ||
let rule = rules | ||
.into_iter() | ||
.find(|x| x.path == edit_path) | ||
|
@@ -41,8 +38,22 @@ fn main() -> Result<()> { | |
// `EDITOR`/`--editor` is mandatory if action is `--edit` | ||
let editor = &opts.editor.unwrap(); | ||
ragenix::edit(&rule, &identities, editor, &mut std::io::stdout())?; | ||
} else if opts.rekey { | ||
ragenix::rekey(&rules, &identities, &mut std::io::stdout())?; | ||
} else if let Some(paths) = opts.rekey { | ||
if paths.is_empty() { | ||
// Option passed but no files specified - rekey all | ||
ragenix::rekey(&rules, &identities, true, &mut std::io::stdout())?; | ||
} else { | ||
let paths_normalized = paths | ||
.into_iter() | ||
.map(util::canonicalize_rule_path) | ||
.collect::<Result<Vec<PathBuf>>>()?; | ||
let chosen_rules = rules | ||
.into_iter() | ||
.filter(|x| paths_normalized.contains(&x.path)) | ||
.collect::<Vec<ragenix::RagenixRule>>(); | ||
|
||
ragenix::rekey(&chosen_rules, &identities, false, &mut std::io::stdout())?; | ||
} | ||
Comment on lines
+41
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better if you did this in the |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add the
[PATH]
to the synopsis section.