Skip to content

Commit

Permalink
Addressed linting errors and updated passwd hist display.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Dec 20, 2023
1 parent 39dd16c commit b9e10aa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
17 changes: 13 additions & 4 deletions rucksack/src/command/handlers/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,28 @@ pub fn keys(matches: &ArgMatches, app: &App) -> Result<()> {
}

pub fn passwords(matches: &ArgMatches, app: &App) -> Result<()> {
let opts = Opts {
decrypted: true,
reveal: options::reveal(matches),
let mut opts = Opts {
password_history: true,
..Default::default()
};
opts.reveal = options::reveal(matches);
opts.decrypted = options::decrypt(matches);
let mut results: Vec<result::ResultRow> = Vec::new();
let record = query::record(app)?;
let analyzed = analyzer::analyze(record.password());
let score = scorer::score(&analyzed).trunc() as i64;
let md = record.metadata();
let mut pwd = record.password();
if !opts.reveal {
pwd = hidden();
}
results.push(result::password(pwd, md.created, md.updated, md.last_used));
results.push(result::password(
pwd,
score.to_string(),
md.created,
md.updated,
md.last_used,
));
log::debug!("history length: {}", record.history().len());
// Let's get these in order of most recent to oldest:
let mut history = record.history();
Expand All @@ -243,6 +251,7 @@ pub fn passwords(matches: &ArgMatches, app: &App) -> Result<()> {
}
results.push(result::password(
pwd,
score.to_string(),
old.metadata.created,
old.metadata.updated,
old.metadata.last_used,
Expand Down
2 changes: 1 addition & 1 deletion rucksack/src/output/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Column {
}

pub trait Columns {
fn new(&self, opts: &Opts) -> Vec<Column> {
fn gen(&self, opts: &Opts) -> Vec<Column> {
let mut cols = self.pre(opts);
cols = self.passwd(opts, cols);
cols = self.status(opts, cols);
Expand Down
9 changes: 8 additions & 1 deletion rucksack/src/output/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ pub fn new(id: String, name: String, url: String) -> ResultRow {
// This function is used for creating results rows that are needed by
// the `list passwords` command. The columns below are the only columns
// needed by that command.
pub fn password(pwd: String, created: String, updated: String, last_accessed: String) -> ResultRow {
pub fn password(
pwd: String,
score: String,
created: String,
updated: String,
last_accessed: String,
) -> ResultRow {
let hashmap: HashMap<Column, String> = HashMap::from([
(Column::Password, pwd),
(Column::Score, score),
(Column::Created, created),
(Column::LastUpdated, updated),
(Column::LastAccessed, last_accessed),
Expand Down
24 changes: 12 additions & 12 deletions rucksack/src/output/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ impl Table {

fn set_columns(&mut self) {
if self.opts.only_keys {
self.columns = column::ColsOnlyKey {}.new(&self.opts);
self.columns = column::ColsOnlyKey {}.gen(&self.opts);
} else if self.opts.kinds {
self.columns = column::ColsOnlyKind {}.new(&self.opts);
self.columns = column::ColsOnlyKind {}.gen(&self.opts);
} else if self.opts.tags {
self.columns = column::ColsOnlyTags {}.new(&self.opts);
self.columns = column::ColsOnlyTags {}.gen(&self.opts);
} else if self.opts.categories {
self.columns = column::ColsOnlyCat {}.new(&self.opts);
self.columns = column::ColsOnlyCat {}.gen(&self.opts);
} else if self.opts.backup_files {
self.columns = column::ColsBackupFiles {}.new(&self.opts);
self.columns = column::ColsBackupFiles {}.gen(&self.opts);
} else if self.opts.group_by_name {
self.opts.with_passwd = true;
self.columns = column::ColsGroupByName {}.new(&self.opts);
self.columns = column::ColsGroupByName {}.gen(&self.opts);
} else if self.opts.group_by_hash {
self.columns = column::ColsGroupByHash {}.new(&self.opts);
self.columns = column::ColsGroupByHash {}.gen(&self.opts);
} else if self.opts.group_by_password {
self.columns = column::ColsGroupByPasswd {}.new(&self.opts);
self.columns = column::ColsGroupByPasswd {}.gen(&self.opts);
} else if self.opts.group_by_kind {
self.columns = column::ColsGroupByKind {}.new(&self.opts);
self.columns = column::ColsGroupByKind {}.gen(&self.opts);
} else if self.opts.group_by_category {
self.columns = column::ColsGroupByCat {}.new(&self.opts);
self.columns = column::ColsGroupByCat {}.gen(&self.opts);
} else if self.opts.password_history {
self.opts.with_passwd = true;
self.columns = column::ColsPasswdHist {}.new(&self.opts);
self.columns = column::ColsPasswdHist {}.gen(&self.opts);
} else {
self.columns = column::ColsDefault {}.new(&self.opts);
self.columns = column::ColsDefault {}.gen(&self.opts);
}
self.set_headers();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rucksack_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ header "Show password history (revealed)"
--url "https://boo.fans.co.uk" \
--category default \
--type password \
--reveal
--reveal --decrypt


header "Export password data"
Expand Down

0 comments on commit b9e10aa

Please sign in to comment.