Skip to content

Commit d38049e

Browse files
authored
feat(shell-api): add new key management helpers MONGOSH-1206 (#1300)
This also adds the aliases suggested in MONGOSH-1239, since doing so is straightforward and touches the same code.
1 parent 95c05ba commit d38049e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/i18n/src/locales/en_US.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,23 @@ const translations: Catalog = {
21472147
getKeyByAltName: {
21482148
description: 'Retrieves keys with the specified key alternative name.',
21492149
link: 'https://docs.mongodb.com/manual/reference/method/KeyVault.getKeyByAltName/#KeyVault.getKeyByAltName'
2150-
}
2150+
},
2151+
rewrapManyDataKey: {
2152+
description: 'Re-wrap one, more, or all data keys with another KMS provider, or re-wrap using the same one.',
2153+
link: 'https://docs.mongodb.com/manual/reference/method/KeyVault.rewrapManyDataKey/#KeyVault.rewrapManyDataKey'
2154+
},
2155+
createDataKey: {
2156+
description: 'Alias of KeyVault.createKey()',
2157+
link: 'https://docs.mongodb.com/manual/reference/method/KeyVault.createKey/#KeyVault.createKey'
2158+
},
2159+
removeKeyAltName: {
2160+
description: 'Alias of KeyVault.removeKeyAlternateName()',
2161+
link: 'https://docs.mongodb.com/manual/reference/method/KeyVault.removeKeyAlternateName/#KeyVault.removeKeyAlternateName'
2162+
},
2163+
addKeyAltName: {
2164+
description: 'Alias of KeyVault.addKeyAlternateName()',
2165+
link: 'https://docs.mongodb.com/manual/reference/method/KeyVault.addKeyAlternateName/#KeyVault.addKeyAlternateName'
2166+
},
21512167
}
21522168
}
21532169
},

packages/shell-api/src/field-level-encryption.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@ describe('Field Level Encryption', () => {
409409
expect(libmongoc.createDataKey).calledOnceWithExactly('local', options);
410410
});
411411
});
412+
describe('rewrapManyDataKey', () => {
413+
it('calls rewrapManyDataKey on clientEncryption', async() => {
414+
const rawResult = { result: 1 };
415+
libmongoc.rewrapManyDataKey.resolves(rawResult);
416+
const result = await keyVault.rewrapManyDataKey({ status: 0 }, { provider: 'local' });
417+
expect(libmongoc.rewrapManyDataKey).calledOnceWithExactly({ status: 0 }, { provider: 'local' });
418+
expect(result).to.deep.equal(rawResult);
419+
});
420+
});
412421
});
413422
describe('Mongo constructor FLE options', () => {
414423
before(() => {

packages/shell-api/src/field-level-encryption.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,31 @@ export class KeyVault extends ShellApiWithMongoClass {
330330
}
331331
return ret;
332332
}
333+
334+
@returnsPromise
335+
@apiVersions([1])
336+
async rewrapManyDataKey(filter: Document, options?: Document): Promise<Document> {
337+
return this._clientEncryption._libmongocrypt.rewrapManyDataKey(filter, options as any);
338+
}
339+
340+
// Alias for compatibility with the driver API.
341+
@returnsPromise
342+
@apiVersions([1])
343+
async createDataKey(...args: Parameters<KeyVault['createKey']>): ReturnType<KeyVault['createKey']> {
344+
return await this.createKey(...args);
345+
}
346+
347+
// Alias for compatibility with the driver API.
348+
@returnsPromise
349+
@apiVersions([1])
350+
async removeKeyAltName(...args: Parameters<KeyVault['removeKeyAlternateName']>): ReturnType<KeyVault['removeKeyAlternateName']> {
351+
return await this.removeKeyAlternateName(...args);
352+
}
353+
354+
// Alias for compatibility with the driver API.
355+
@returnsPromise
356+
@apiVersions([1])
357+
async addKeyAltName(...args: Parameters<KeyVault['addKeyAlternateName']>): ReturnType<KeyVault['addKeyAlternateName']> {
358+
return await this.addKeyAlternateName(...args);
359+
}
333360
}

0 commit comments

Comments
 (0)