Skip to content

Commit d0fcc4b

Browse files
authored
feat(NODE-6947): add keyExpirationMS to bindings (#78)
1 parent 750a0f6 commit d0fcc4b

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

addon/mongocrypt.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info) : ObjectWrap(info) {
571571
mongocrypt_setopt_bypass_query_analysis(mongo_crypt());
572572
}
573573

574+
if (options.Has("keyExpirationMS")) {
575+
int64_t keyExpirationMS = options.Get("keyExpirationMS").ToNumber().Int64Value();
576+
if (keyExpirationMS < 0) {
577+
throw TypeError::New(Env(), "Option `keyExpirationMS` must be a non-negative number");
578+
}
579+
mongocrypt_setopt_key_expiration(mongo_crypt(), keyExpirationMS);
580+
}
581+
574582
mongocrypt_setopt_use_range_v2(mongo_crypt());
575583

576584
mongocrypt_setopt_use_need_kms_credentials_state(mongo_crypt());

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"license": "Apache-2.0",
3737
"gypfile": true,
38-
"mongodb:libmongocrypt": "1.13.0",
38+
"mongodb:libmongocrypt": "1.14.0",
3939
"dependencies": {
4040
"node-addon-api": "^4.3.0",
4141
"prebuild-install": "^7.1.3"

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ type MongoCryptConstructorOptions = {
6767
cryptSharedLibSearchPaths?: string[];
6868
cryptSharedLibPath?: string;
6969
bypassQueryAnalysis?: boolean;
70+
/** Configure the time to expire the DEK from the cache. */
71+
keyExpirationMS?: number;
7072
/** TODO(NODE-6793): remove this option and have it always set in the next major */
7173
enableMultipleCollinfo?: boolean;
7274
};

test/unit/bindings.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ describe('MongoCryptConstructor', () => {
9797
});
9898
});
9999

100+
describe('options.keyExpirationMS', () => {
101+
context('when the number is positive', () => {
102+
it('does not error', () => {
103+
expect(
104+
new MongoCrypt({ kmsProviders: serialize({ aws: {} }), keyExpirationMS: 1000000 })
105+
).to.be.instanceOf(MongoCrypt);
106+
});
107+
});
108+
109+
context('when the number is negative', () => {
110+
it('throws an error', () => {
111+
expect(() => {
112+
new MongoCrypt({ kmsProviders: serialize({ aws: {} }), keyExpirationMS: -1000000 });
113+
}).to.throw(/must be a non-negative number/);
114+
});
115+
});
116+
});
117+
100118
describe('options.encryptedFieldsMap', () => {
101119
it('throws when provided and not a Uint8Array', () => {
102120
expect(

0 commit comments

Comments
 (0)