Skip to content

Commit 16a52e7

Browse files
docs(NODE-5094): fix docs for azure kms credential refresh (#596)
1 parent edc8bf8 commit 16a52e7

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ npm test
6060
<dt><a href="#MongoCryptCreateEncryptedCollectionError">MongoCryptCreateEncryptedCollectionError</a></dt>
6161
<dd><p>An error indicating that <code>ClientEncryption.createEncryptedCollection()</code> failed to create a collection</p>
6262
</dd>
63+
<dt><a href="#MongoCryptAzureKMSRequestError">MongoCryptAzureKMSRequestError</a></dt>
64+
<dd><p>An error indicating that mongodb-client-encryption failed to auto-refresh Azure KMS credentials.</p>
65+
</dd>
6366
</dl>
6467

6568
## Typedefs
@@ -692,6 +695,20 @@ An error indicating that `ClientEncryption.createEncryptedCollection()` failed t
692695
**Experimental**: Public Technical Preview
693696
An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create a collection
694697

698+
<a name="MongoCryptAzureKMSRequestError"></a>
699+
700+
## MongoCryptAzureKMSRequestError
701+
An error indicating that mongodb-client-encryption failed to auto-refresh Azure KMS credentials.
702+
703+
<a name="new_MongoCryptAzureKMSRequestError_new"></a>
704+
705+
### new MongoCryptAzureKMSRequestError(message, body)
706+
707+
| Param | Type |
708+
| --- | --- |
709+
| message | <code>string</code> |
710+
| body | <code>object</code> \| <code>undefined</code> |
711+
695712
<a name="BSONValue"></a>
696713

697714
## BSONValue

lib/providers/azure.js

+34-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const utils = require('./utils');
99
const MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS = 6000;
1010

1111
/**
12+
* @class
1213
* @ignore
1314
*/
1415
class AzureCredentialCache {
@@ -36,35 +37,45 @@ class AzureCredentialCache {
3637
}
3738

3839
/**
39-
* @ignore
4040
* exposed for testing
41+
* @ignore
4142
*/
4243
resetCache() {
4344
this.cachedToken = null;
4445
}
4546

4647
/**
47-
* @ignore
4848
* exposed for testing
49+
* @ignore
4950
*/
5051
_getToken() {
5152
return fetchAzureKMSToken();
5253
}
5354
}
5455
/**
55-
* @type{AzureCredentialCache}
56+
* @type{ AzureCredentialCache }
57+
* @ignore
5658
*/
5759
let tokenCache = new AzureCredentialCache();
5860

61+
/**
62+
* @typedef {object} KmsRequestResponsePayload
63+
* @property {string | undefined} access_token
64+
* @property {string | undefined} expires_in
65+
*
66+
* @ignore
67+
*/
68+
5969
/**
6070
* @param { {body: string, status: number }} response
6171
* @returns { Promise<{ accessToken: string, expiresOnTimestamp: number } >}
72+
* @ignore
6273
*/
6374
async function parseResponse(response) {
6475
const { status, body: rawBody } = response;
6576

6677
/**
67-
* @type { { access_token?: string, expires_in?: string} }
78+
* @type { KmsRequestResponsePayload }
6879
*/
6980
const body = (() => {
7081
try {
@@ -107,6 +118,8 @@ async function parseResponse(response) {
107118
* @param {object} options
108119
* @param {object | undefined} [options.headers]
109120
* @param {URL | undefined} [options.url]
121+
*
122+
* @ignore
110123
*/
111124
function prepareRequest(options) {
112125
const url =
@@ -122,13 +135,26 @@ function prepareRequest(options) {
122135
}
123136

124137
/**
138+
* @typedef {object} AzureKMSRequestOptions
139+
* @property {object | undefined} headers
140+
* @property {URL | undefined} url
125141
* @ignore
142+
*/
143+
144+
/**
145+
* @typedef {object} AzureKMSRequestResponse
146+
* @property {string} accessToken
147+
* @property {number} expiresOnTimestamp
148+
* @ignore
149+
*/
150+
151+
/**
126152
* exported only for testing purposes in the driver
127153
*
128-
* @param {object} options
129-
* @param {object | undefined} [options.headers]
130-
* @param {URL | undefined} [options.url]
131-
* @returns {Promise<{ accessToken: string, expiresOnTimestamp: number }>}
154+
* @param {AzureKMSRequestOptions} options
155+
* @returns {Promise<AzureKMSRequestResponse>}
156+
*
157+
* @ignore
132158
*/
133159
async function fetchAzureKMSToken(options = {}) {
134160
const { headers, url } = prepareRequest(options);
@@ -142,7 +168,6 @@ async function fetchAzureKMSToken(options = {}) {
142168
}
143169

144170
/**
145-
* @param {import('../../index').KMSProviders} kmsProviders
146171
* @ignore
147172
*/
148173
async function loadAzureCredentials(kmsProviders) {

lib/providers/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const { loadAzureCredentials, fetchAzureKMSToken } = require('./azure');
55
const { loadGCPCredentials } = require('./gcp');
66

77
/**
8-
* @ignore
98
* Auto credential fetching should only occur when the provider is defined on the kmsProviders map
109
* and the settings are an empty object.
1110
*
1211
* This is distinct from a nullish provider key.
1312
*
1413
* @param {'aws' | 'gcp' | 'azure'} provider
15-
* @param {import('../../index').KMSProviders} kmsProviders
14+
* @param {object} kmsProviders
15+
*
16+
* @ignore
1617
*/
1718
function isEmptyCredentials(provider, kmsProviders) {
1819
return (
@@ -28,8 +29,8 @@ function isEmptyCredentials(provider, kmsProviders) {
2829
* Credentials will only attempt to get loaded if they do not exist
2930
* and no existing credentials will get overwritten.
3031
*
31-
* @param {import('../../index').KMSProviders} kmsProviders - The user provided KMS providers.
32-
* @returns {Promise<import('../../index').KMSProviders>} The new kms providers.
32+
* @param {object} kmsProviders - The user provided KMS providers.
33+
* @returns {object} The new kms providers.
3334
*
3435
* @ignore
3536
*/

lib/providers/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const http = require('http');
88
* @param {http.RequestOptions} options
99
*
1010
* @returns { Promise<{ body: string, status: number }> }
11+
* @ignore
1112
*/
1213
function get(url, options = {}) {
1314
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)