-
Notifications
You must be signed in to change notification settings - Fork 3
Added touch
method to set last_used property
#96
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,6 +420,50 @@ class DataStore { | |
|
||
return item; | ||
} | ||
/** | ||
* Touches an existing item in this DataStore. | ||
* | ||
* `{item}` is expected to be a complete object. API users should call | ||
* {@link #get}, then pass the returned value to `{touch}` | ||
* | ||
* @param {Object} item The item to touch | ||
* @returns {Object} The updated item | ||
* @throws {Error} if this item does not exist | ||
* @throws {TypeError} if `item` is not an object with a `id` member | ||
* @throws {DataStoreError} if the `item` violates the schema | ||
*/ | ||
async touch(item) { | ||
checkState(this); | ||
|
||
let self = instance.get(this); | ||
if (!item || !item.id) { | ||
throw new DataStoreError(DataStoreError.INVALID_ITEM); | ||
} | ||
|
||
let id = item.id; | ||
let record = await self.ldb.items.get(id); | ||
let orig, encrypted; | ||
if (!record) { | ||
throw new DataStoreError(DataStoreError.MISSING_ITEM); | ||
} else { | ||
encrypted = record.encrypted; | ||
} | ||
|
||
orig = await self.keystore.unprotect(id, encrypted); | ||
|
||
orig.last_used = new Date().toISOString(); | ||
encrypted = await self.keystore.protect(orig); | ||
|
||
record = { | ||
id, | ||
encrypted, | ||
last_modified: record.last_modified | ||
}; | ||
|
||
await self.ldb.items.put(record); | ||
self.recordMetric("touched", item.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might require an update to the extension's metrics reporting ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment is really a note to go check the extension and ensure it won't cause additional failures. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@linuxwolf Good call. @sashei is going to do a quick smoke test before merging and have a follow-up here to do corresponding follow-on work: mozilla-lockwise/lockbox-extension#661 |
||
return orig; | ||
} | ||
/** | ||
* Removes an item from this DataStore. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ const SCHEMA = joi.object().keys({ | |
origins: joi.array().items(STRING_500).max(5).default([]), | ||
tags: joi.array().items(STRING_500).max(10).default([]), | ||
entry: joi.alternatives(ENTRY_SCHEMAS).required(), | ||
last_used: joi.date().allow(null).default(null), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is what we really want. Adding it to the schema allows the API user to define when Other read-only properties (e.g., |
||
}); | ||
const VALIDATE_OPTIONS = { | ||
abortEarly: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this was put in place to troubleshoot tests, and just got missed with the last push. This option needs to be removed so we keep the default for "no-console" as "error".