Skip to content

Commit

Permalink
feat: add last used to ssh keys
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Mar 27, 2024
1 parent 3e7284c commit 1edc28d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions services/api/database/migrations/20240312000000_sshkeyused.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
return knex.schema
.alterTable('ssh_key', (table) => {
table.datetime('last_used');
})
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(knex) {
return knex.schema
.alterTable('ssh_key', (table) => {
table.dropColumn('last_used');
})
};
19 changes: 19 additions & 0 deletions services/api/src/routes/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ const keysRoute = async (
logger.debug(`Unknown fingerprint: ${fingerprint}`);
}

// update key used timestamp
const foundkey = await query(
sqlClientPool,
knex('ssh_key')
.select('id')
.where('key_fingerprint', fingerprint)
.toString(),
);
var date = new Date();
const convertDateFormat = R.init;
var lastUsed = convertDateFormat(date.toISOString());
await query(
sqlClientPool,
knex('ssh_key')
.where('id', foundkey[0].id)
.update({lastUsed: lastUsed})
.toString(),
);

res.send(result);
};

Expand Down
1 change: 1 addition & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ const typeDefs = gql`
keyType: String
keyFingerprint: String
created: String
lastUsed: String
}
type User {
Expand Down

0 comments on commit 1edc28d

Please sign in to comment.