Skip to content

Commit

Permalink
Add ability to override no_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
davedoesdev committed Sep 29, 2020
1 parent 056ba24 commit 5c45a16
Show file tree
Hide file tree
Showing 21 changed files with 2,925 additions and 2,474 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -96,7 +96,7 @@ _Source: [docs.js](/docs.js)_

## PubKeyStore
### Adding and removing keys
- <a name="toc_pubkeystoreprototypeadd_pub_keyuri-pub_key-cb"></a><a name="toc_pubkeystoreprototype"></a><a name="toc_pubkeystore"></a>[PubKeyStore.prototype.add_pub_key](#pubkeystoreprototypeadd_pub_keyuri-pub_key-cb)
- <a name="toc_pubkeystoreprototypeadd_pub_keyuri-pub_key-options-cb"></a><a name="toc_pubkeystoreprototype"></a><a name="toc_pubkeystore"></a>[PubKeyStore.prototype.add_pub_key](#pubkeystoreprototypeadd_pub_keyuri-pub_key-options-cb)
- <a name="toc_pubkeystoreprototyperemove_pub_keyuri-cb"></a>[PubKeyStore.prototype.remove_pub_key](#pubkeystoreprototyperemove_pub_keyuri-cb)

### Retrieving keys
Expand Down Expand Up @@ -188,14 +188,17 @@ _Source: [docs.js](/docs.js)_

<a name="pubkeystore"></a>

## PubKeyStore.prototype.add_pub_key(uri, pub_key, [cb])
## PubKeyStore.prototype.add_pub_key(uri, pub_key, [options], [cb])

> Add a public key to the keystore.
**Parameters:**

- `{String} uri` A known, permanent identifier for the public key's owner. You can use anything but a [URI](http://en.wikipedia.org/wiki/Uniform_resource_identifier) seems ideal. For example if you know the owner's email address then you could you a `mailto` URI (e.g. `mailto:dave@davedoesdev.com`).
- `{String | Object} pub_key` The public key itself. This can be in any format (e.g. [PEM](http://www.faqs.org/qa/qa-14736.html)).
- `{Object} [options]` Additional options. Valid properties:
- `{Boolean} [allow_update]` If you passed `no_updates=true` when [opening the keystore](#moduleexportsconfig-cb), you can override it here by passing `true`, which allows this call to update an existing public key.

- `{Function} [cb]` Function to call once the key has been added. It will receive the following arguments:
- `{Object} err` If an error occurred then details of the error, otherwise `null`.

Expand Down
10 changes: 8 additions & 2 deletions couchdb/index.js
Expand Up @@ -225,8 +225,14 @@ PubKeyStoreCouchDB.prototype.get_pub_key_by_uri = function (uri, cb)
});
};

PubKeyStoreCouchDB.prototype.add_pub_key = function (uri, pub_key, cb)
PubKeyStoreCouchDB.prototype.add_pub_key = function (uri, pub_key, options, cb)
{
if (typeof options === 'function')
{
cb = options;
options = {};
}
options = options || {};
cb = cb || function () { return undefined; };

if (!this._db) { return cb(new Error('not_open')); }
Expand All @@ -240,7 +246,7 @@ PubKeyStoreCouchDB.prototype.add_pub_key = function (uri, pub_key, cb)
issuer_id = crypto.randomBytes(64).toString('hex'),
doc = { issuer_id: issuer_id, pub_key: pub_key };

if (this._config.no_updates)
if (this._config.no_updates && !options.allow_update)
{
return this._db.insert(doc, uri, function (err, res)
{
Expand Down
78 changes: 39 additions & 39 deletions coverage/lcov-report/index.html
Expand Up @@ -23,30 +23,30 @@ <h1>All files</h1>
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">89.02% </span>
<span class="strong">89.01% </span>
<span class="quiet">Statements</span>
<span class='fraction'>705/792</span>
<span class='fraction'>721/810</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">78.92% </span>
<span class="strong">78.78% </span>
<span class="quiet">Branches</span>
<span class='fraction'>393/498</span>
<span class='fraction'>412/523</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">88% </span>
<span class="strong">87.56% </span>
<span class="quiet">Functions</span>
<span class='fraction'>176/200</span>
<span class='fraction'>176/201</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">93.55% </span>
<span class="strong">93.56% </span>
<span class="quiet">Lines</span>
<span class='fraction'>667/713</span>
<span class='fraction'>683/730</span>
</div>


Expand Down Expand Up @@ -89,62 +89,62 @@ <h1>All files</h1>

<tr>
<td class="file high" data-value="pub-keystore/couchdb"><a href="pub-keystore/couchdb/index.html">pub-keystore/couchdb</a></td>
<td data-value="84.47" class="pic high">
<td data-value="84.75" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 84%"></div><div class="cover-empty" style="width: 16%"></div></div>
</td>
<td data-value="84.47" class="pct high">84.47%</td>
<td data-value="219" class="abs high">185/219</td>
<td data-value="73.08" class="pct medium">73.08%</td>
<td data-value="156" class="abs medium">114/156</td>
<td data-value="84.75" class="pct high">84.75%</td>
<td data-value="223" class="abs high">189/223</td>
<td data-value="73.46" class="pct medium">73.46%</td>
<td data-value="162" class="abs medium">119/162</td>
<td data-value="85.71" class="pct high">85.71%</td>
<td data-value="42" class="abs high">36/42</td>
<td data-value="92.51" class="pct high">92.51%</td>
<td data-value="187" class="abs high">173/187</td>
<td data-value="92.67" class="pct high">92.67%</td>
<td data-value="191" class="abs high">177/191</td>
</tr>

<tr>
<td class="file high" data-value="pub-keystore/in-mem"><a href="pub-keystore/in-mem/index.html">pub-keystore/in-mem</a></td>
<td data-value="95.54" class="pic high">
<td data-value="95.69" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 95%"></div><div class="cover-empty" style="width: 5%"></div></div>
</td>
<td data-value="95.54" class="pct high">95.54%</td>
<td data-value="112" class="abs high">107/112</td>
<td data-value="79.17" class="pct medium">79.17%</td>
<td data-value="72" class="abs medium">57/72</td>
<td data-value="95.69" class="pct high">95.69%</td>
<td data-value="116" class="abs high">111/116</td>
<td data-value="79.49" class="pct medium">79.49%</td>
<td data-value="78" class="abs medium">62/78</td>
<td data-value="66.67" class="pct medium">66.67%</td>
<td data-value="27" class="abs medium">18/27</td>
<td data-value="95.5" class="pct high">95.5%</td>
<td data-value="111" class="abs high">106/111</td>
<td data-value="95.65" class="pct high">95.65%</td>
<td data-value="115" class="abs high">110/115</td>
</tr>

<tr>
<td class="file high" data-value="pub-keystore/pouchdb"><a href="pub-keystore/pouchdb/index.html">pub-keystore/pouchdb</a></td>
<td data-value="82.26" class="pic high">
<td data-value="82.16" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 82%"></div><div class="cover-empty" style="width: 18%"></div></div>
</td>
<td data-value="82.26" class="pct high">82.26%</td>
<td data-value="265" class="abs high">218/265</td>
<td data-value="74.72" class="pct medium">74.72%</td>
<td data-value="178" class="abs medium">133/178</td>
<td data-value="82.16" class="pct high">82.16%</td>
<td data-value="269" class="abs high">221/269</td>
<td data-value="74.46" class="pct medium">74.46%</td>
<td data-value="184" class="abs medium">137/184</td>
<td data-value="85.71" class="pct high">85.71%</td>
<td data-value="56" class="abs high">48/56</td>
<td data-value="88.74" class="pct high">88.74%</td>
<td data-value="231" class="abs high">205/231</td>
<td data-value="88.51" class="pct high">88.51%</td>
<td data-value="235" class="abs high">208/235</td>
</tr>

<tr>
<td class="file high" data-value="pub-keystore/sql"><a href="pub-keystore/sql/index.html">pub-keystore/sql</a></td>
<td data-value="100" class="pic high">
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
<td data-value="99.45" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 99%"></div><div class="cover-empty" style="width: 1%"></div></div>
</td>
<td data-value="99.45" class="pct high">99.45%</td>
<td data-value="181" class="abs high">180/181</td>
<td data-value="95.29" class="pct high">95.29%</td>
<td data-value="85" class="abs high">81/85</td>
<td data-value="97.26" class="pct high">97.26%</td>
<td data-value="73" class="abs high">71/73</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="175" class="abs high">175/175</td>
<td data-value="97.44" class="pct high">97.44%</td>
<td data-value="78" class="abs high">76/78</td>
<td data-value="98.61" class="pct high">98.61%</td>
<td data-value="72" class="abs high">71/72</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="163" class="abs high">163/163</td>
<td data-value="168" class="abs high">168/168</td>
</tr>

</tbody>
Expand All @@ -155,7 +155,7 @@ <h1>All files</h1>
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
at Sat Mar 28 2020 09:59:15 GMT+0000 (Greenwich Mean Time)
at Tue Sep 29 2020 22:40:37 GMT+0100 (British Summer Time)
</div>
</div>
<script src="prettify.js"></script>
Expand Down
28 changes: 14 additions & 14 deletions coverage/lcov-report/pub-keystore/couchdb/index.html
Expand Up @@ -23,16 +23,16 @@ <h1><a href="../../index.html">All files</a> pub-keystore/couchdb</h1>
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">84.47% </span>
<span class="strong">84.75% </span>
<span class="quiet">Statements</span>
<span class='fraction'>185/219</span>
<span class='fraction'>189/223</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">73.08% </span>
<span class="strong">73.46% </span>
<span class="quiet">Branches</span>
<span class='fraction'>114/156</span>
<span class='fraction'>119/162</span>
</div>


Expand All @@ -44,9 +44,9 @@ <h1><a href="../../index.html">All files</a> pub-keystore/couchdb</h1>


<div class='fl pad1y space-right2'>
<span class="strong">92.51% </span>
<span class="strong">92.67% </span>
<span class="quiet">Lines</span>
<span class='fraction'>173/187</span>
<span class='fraction'>177/191</span>
</div>


Expand Down Expand Up @@ -74,17 +74,17 @@ <h1><a href="../../index.html">All files</a> pub-keystore/couchdb</h1>
</thead>
<tbody><tr>
<td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
<td data-value="84.47" class="pic high">
<td data-value="84.75" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 84%"></div><div class="cover-empty" style="width: 16%"></div></div>
</td>
<td data-value="84.47" class="pct high">84.47%</td>
<td data-value="219" class="abs high">185/219</td>
<td data-value="73.08" class="pct medium">73.08%</td>
<td data-value="156" class="abs medium">114/156</td>
<td data-value="84.75" class="pct high">84.75%</td>
<td data-value="223" class="abs high">189/223</td>
<td data-value="73.46" class="pct medium">73.46%</td>
<td data-value="162" class="abs medium">119/162</td>
<td data-value="85.71" class="pct high">85.71%</td>
<td data-value="42" class="abs high">36/42</td>
<td data-value="92.51" class="pct high">92.51%</td>
<td data-value="187" class="abs high">173/187</td>
<td data-value="92.67" class="pct high">92.67%</td>
<td data-value="191" class="abs high">177/191</td>
</tr>

</tbody>
Expand All @@ -95,7 +95,7 @@ <h1><a href="../../index.html">All files</a> pub-keystore/couchdb</h1>
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
at Sat Mar 28 2020 09:59:15 GMT+0000 (Greenwich Mean Time)
at Tue Sep 29 2020 22:40:37 GMT+0100 (British Summer Time)
</div>
</div>
<script src="../../prettify.js"></script>
Expand Down

0 comments on commit 5c45a16

Please sign in to comment.