Wire keychain status to local keychain ops
This commit is contained in:
parent
f54920bb65
commit
99f6dee26f
12 changed files with 191 additions and 20 deletions
|
|
@ -318,6 +318,31 @@ impl Store {
|
|||
.map_err(StoreError::from)
|
||||
}
|
||||
|
||||
pub fn insert_keychain_op(&self, op: &StoredKeychainOp) -> Result<(), StoreError> {
|
||||
self.conn.execute(
|
||||
r#"INSERT OR REPLACE INTO keychain_ops(op_id, op_json, created_at_ms)
|
||||
VALUES (?1, ?2, ?3)"#,
|
||||
params![op.op_id, op.op_json, op.created_at_ms],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn list_keychain_ops(&self) -> Result<Vec<StoredKeychainOp>, StoreError> {
|
||||
let mut stmt = self.conn.prepare(
|
||||
r#"SELECT op_id, op_json, created_at_ms
|
||||
FROM keychain_ops ORDER BY created_at_ms, op_id"#,
|
||||
)?;
|
||||
let rows = stmt.query_map([], |row| {
|
||||
Ok(StoredKeychainOp {
|
||||
op_id: row.get(0)?,
|
||||
op_json: row.get(1)?,
|
||||
created_at_ms: row.get(2)?,
|
||||
})
|
||||
})?;
|
||||
rows.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(StoreError::from)
|
||||
}
|
||||
|
||||
pub fn insert_ssh_cert_request(
|
||||
&self,
|
||||
request: &StoredSshCertRequest,
|
||||
|
|
@ -513,6 +538,13 @@ pub struct StoredAuthOp {
|
|||
pub created_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct StoredKeychainOp {
|
||||
pub op_id: String,
|
||||
pub op_json: String,
|
||||
pub created_at_ms: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct StoredSshCertRequest {
|
||||
pub request_id: String,
|
||||
|
|
@ -653,4 +685,27 @@ mod tests {
|
|||
vec![first]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keychain_ops_roundtrip() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
let first = StoredKeychainOp {
|
||||
op_id: "op:keychain:1".to_owned(),
|
||||
op_json: r#"{"id":"op:keychain:1"}"#.to_owned(),
|
||||
created_at_ms: 1,
|
||||
};
|
||||
let second = StoredKeychainOp {
|
||||
op_id: "op:keychain:2".to_owned(),
|
||||
op_json: r#"{"id":"op:keychain:2"}"#.to_owned(),
|
||||
created_at_ms: 2,
|
||||
};
|
||||
|
||||
store.insert_keychain_op(&second).expect("insert second");
|
||||
store.insert_keychain_op(&first).expect("insert first");
|
||||
|
||||
assert_eq!(
|
||||
store.list_keychain_ops().expect("list keychain ops"),
|
||||
vec![first, second]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue