index : bitwarden-ssh-agent.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-08-01 20:47:29.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-08-01 20:47:29.0 +00:00:00
commit
53812b8131b9a8dba7824d398a94eb5b6a9226fa [patch]
tree
005fdcc3101ce6f20bdfc4685b4d631e0efba55c
parent
c8d3b54a6f6dcf00910971c0bbadaa95076d1668
download
53812b8131b9a8dba7824d398a94eb5b6a9226fa.tar.gz

feat: add listing only items matching valid ssh key item criteria



Diff

 src/main.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index b815b4c..e73f55f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,10 @@ struct Cli {

/// Environment variable housing an existing Bitwarden session.
const SESSION_ENV_KEY: &str = "BW_SESSION";
/// Environment variable referencing the name of the field containing the SSH key filename. 
const BW_FIELD_KEY_FILENAME: &str = "private";
/// Environment variable referencing the name of the field containing the SSH key passphrase (if any).
const BW_FIELD_KEY_PASSPHRASE: &str = "passphrase";

fn main() -> Result<()> {
    let args: Cli = Cli::parse_args_default_or_exit();
@@ -42,7 +46,32 @@ fn main() -> Result<()> {
		for folder in folders {
			let folder_items = bwutil::exec_list_folder_items(&session_token, &folder.id)?;
			for item in folder_items {
				println!("{:#?}", item);
				// In order for this to be considered a valid SSH key item, this item needs to have the following fields:
				// - private - (required) this is the filename of the attachment containing the SSH key. 
				//		The field name is not case sensitive in order to be more user-friendly.
				// - passphrase - (optional) this is the passphrase (if any) for the SSH key. 
				//		The field name is not case sensitive in order to be more user-friendly.
				// - attachment (required) an attachment with the name specified in `private`.
				if let Some(fields) = &item.fields {
					let mut key_filename = String::new();
					let mut key_passphrase = String::new();
					for field in fields {
						if field.name.to_lowercase().eq(&String::from(BW_FIELD_KEY_FILENAME).to_lowercase()) {
							key_filename.push_str(&field.value);
						}
						if field.name.to_lowercase().eq(&String::from(BW_FIELD_KEY_PASSPHRASE).to_lowercase()) {
							key_passphrase.push_str(&field.value);
						}
					}

					if let Some(attachments) = &item.attachments {
						for attachment in attachments {
							if attachment.file_name.eq(&key_filename) {
								println!("{:#?}", item);
							}
						}
					}
				}
			}
		}
	}