Skip to content

Commit

Permalink
CLI: Add TOML support.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Jan 25, 2024
1 parent acff7dc commit 0035b6a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/cli/src/args/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ pub enum Format {
#[value(alias = "yml")]
Yaml,
Json,
Toml,
}
1 change: 1 addition & 0 deletions crates/cli/src/cli/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Cli {
return match format {
Format::Yaml => decrypt_rops_file_impl::<YamlFileFormat>(encrypted_rops_file_str),
Format::Json => decrypt_rops_file_impl::<JsonFileFormat>(encrypted_rops_file_str),
Format::Toml => decrypt_rops_file_impl::<TomlFileFormat>(encrypted_rops_file_str),
};

fn decrypt_rops_file_impl<F: FileFormat>(encrypted_rops_file_str: &str) -> anyhow::Result<String> {
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/cli/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl Cli {
return match Self::get_format(explicit_file_path, input_args.format)? {
Format::Yaml => edit_encrypted_file::<YamlFileFormat>(explicit_file_path),
Format::Json => edit_encrypted_file::<JsonFileFormat>(explicit_file_path),
Format::Toml => edit_encrypted_file::<TomlFileFormat>(explicit_file_path),
};

// Nested to avoid it being misused for regular files which might use aliases.
Expand All @@ -22,6 +23,7 @@ impl Cli {
pub trait TempFileFormat: FileFormat { const TEMP_EXTENTION: &'static str; }
impl TempFileFormat for YamlFileFormat { const TEMP_EXTENTION: &'static str = "yaml"; }
impl TempFileFormat for JsonFileFormat { const TEMP_EXTENTION: &'static str = "json"; }
impl TempFileFormat for TomlFileFormat { const TEMP_EXTENTION: &'static str = "toml"; }
}

fn edit_encrypted_file<F: temp_file_format::TempFileFormat>(explicit_file_path: Option<&Path>) -> anyhow::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/cli/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl Cli {
return match file_format {
Format::Yaml => encrypt_rops_file_impl::<YamlFileFormat>(plaintext_string, encrypt_args),
Format::Json => encrypt_rops_file_impl::<JsonFileFormat>(plaintext_string, encrypt_args),
Format::Toml => encrypt_rops_file_impl::<TomlFileFormat>(plaintext_string, encrypt_args),
};

fn encrypt_rops_file_impl<F: FileFormat>(plaintext_str: &str, encrypt_args: EncryptArgs) -> anyhow::Result<String> {
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/cli/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Cli {
return match Self::get_format(Some(&key_args.file), key_args.format)? {
Format::Yaml => add_key_impl::<YamlFileFormat>(key_args),
Format::Json => add_key_impl::<JsonFileFormat>(key_args),
Format::Toml => add_key_impl::<TomlFileFormat>(key_args),
};

fn add_key_impl<F: FileFormat>(key_args: KeyInputArgs) -> anyhow::Result<()> {
Expand All @@ -34,6 +35,7 @@ impl Cli {
return match Self::get_format(Some(&key_args.file), key_args.format)? {
Format::Yaml => remove_key_impl::<YamlFileFormat>(key_args),
Format::Json => remove_key_impl::<JsonFileFormat>(key_args),
Format::Toml => remove_key_impl::<TomlFileFormat>(key_args),
};

fn remove_key_impl<F: FileFormat>(key_args: KeyInputArgs) -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["age", "aws-kms", "yaml", "json", "aes-gcm", "sha2"]
default = ["age", "aws-kms", "yaml", "json", "toml", "aes-gcm", "sha2"]
# Integrations:
age = ["dep:age"]
aws-kms = ["dep:aws-arn", "dep:aws-sdk-kms", "dep:tokio"]
Expand Down

0 comments on commit 0035b6a

Please sign in to comment.