From d4b7ef7fa7db4c8b6cd0c61570020ec0013d5a6c Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Thu, 30 Jan 2025 19:24:46 +0100 Subject: [PATCH] feat(NODE-6695): enable KMS retry protocol (#60) --- addon/mongocrypt.cc | 12 ++++++++++++ addon/mongocrypt.h | 2 ++ package.json | 2 +- src/index.ts | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addon/mongocrypt.cc b/addon/mongocrypt.cc index b0ab3dd..053ad25 100644 --- a/addon/mongocrypt.cc +++ b/addon/mongocrypt.cc @@ -575,6 +575,8 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info) : ObjectWrap(info) { mongocrypt_setopt_use_need_kms_credentials_state(mongo_crypt()); + mongocrypt_setopt_retry_kms(mongo_crypt(), true); + // Initialize after all options are set. if (!mongocrypt_init(mongo_crypt())) { throw TypeError::New(Env(), errorStringFromStatus(mongo_crypt())); @@ -947,6 +949,8 @@ Function MongoCryptKMSRequest::Init(Napi::Env env) { {InstanceMethod("addResponse", &MongoCryptKMSRequest::AddResponse), InstanceAccessor("status", &MongoCryptKMSRequest::Status, nullptr), InstanceAccessor("bytesNeeded", &MongoCryptKMSRequest::BytesNeeded, nullptr), + InstanceAccessor("uSleep", &MongoCryptKMSRequest::USleep, nullptr), + InstanceAccessor("fail", &MongoCryptKMSRequest::Fail, nullptr), InstanceAccessor("kmsProvider", &MongoCryptKMSRequest::KMSProvider, nullptr), InstanceAccessor("endpoint", &MongoCryptKMSRequest::Endpoint, nullptr), InstanceAccessor("message", &MongoCryptKMSRequest::Message, nullptr)}); @@ -977,6 +981,14 @@ Value MongoCryptKMSRequest::BytesNeeded(const CallbackInfo& info) { return Number::New(Env(), mongocrypt_kms_ctx_bytes_needed(_kms_context)); } +Value MongoCryptKMSRequest::USleep(const CallbackInfo& info) { + return Number::New(Env(), mongocrypt_kms_ctx_usleep(_kms_context)); +} + +Value MongoCryptKMSRequest::Fail(const CallbackInfo& info) { + return Boolean::New(Env(), mongocrypt_kms_ctx_fail(_kms_context)); +} + Value MongoCryptKMSRequest::KMSProvider(const CallbackInfo& info) { return String::New(Env(), mongocrypt_kms_ctx_get_kms_provider(_kms_context, nullptr)); } diff --git a/addon/mongocrypt.h b/addon/mongocrypt.h index b7753d0..2fa074f 100644 --- a/addon/mongocrypt.h +++ b/addon/mongocrypt.h @@ -151,6 +151,8 @@ class MongoCryptKMSRequest : public Napi::ObjectWrap { Napi::Value Status(const Napi::CallbackInfo& info); Napi::Value Message(const Napi::CallbackInfo& info); Napi::Value BytesNeeded(const Napi::CallbackInfo& info); + Napi::Value Fail(const Napi::CallbackInfo& info); + Napi::Value USleep(const Napi::CallbackInfo& info); Napi::Value KMSProvider(const Napi::CallbackInfo& info); Napi::Value Endpoint(const Napi::CallbackInfo& info); diff --git a/package.json b/package.json index 064c944..19574fe 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "license": "Apache-2.0", "gypfile": true, - "mongodb:libmongocrypt": "1.11.0", + "mongodb:libmongocrypt": "1.12.0", "dependencies": { "node-addon-api": "^4.3.0", "prebuild-install": "^7.1.2" diff --git a/src/index.ts b/src/index.ts index ab43cb4..48cc628 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,8 +23,10 @@ type MongoCryptBindings = { export interface MongoCryptKMSRequest { addResponse(response: Uint8Array): void; + fail(): boolean; readonly status: MongoCryptStatus; readonly bytesNeeded: number; + readonly uSleep: number; readonly kmsProvider: string; readonly endpoint: string; readonly message: Buffer;