summaryrefslogtreecommitdiff
path: root/src/mongo/shell/keyvault.js
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/shell/keyvault.js
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/shell/keyvault.js')
-rw-r--r--src/mongo/shell/keyvault.js71
1 files changed, 21 insertions, 50 deletions
diff --git a/src/mongo/shell/keyvault.js b/src/mongo/shell/keyvault.js
index ee8f2ddf111..c913d81a5b1 100644
--- a/src/mongo/shell/keyvault.js
+++ b/src/mongo/shell/keyvault.js
@@ -6,37 +6,13 @@ Mongo.prototype.getKeyVault = function() {
};
class KeyVault {
- _runCommand(client, func, args) {
- let numRetries = 3;
- do {
- try {
- const result = func.apply(client, args);
- return result;
- } catch (e) {
- numRetries--;
- if (!isNetworkError(e) || numRetries == 0) {
- jsTest.log("KeyVault: We have exceeded the number of retries. Throwing.");
- throw e;
- }
-
- const res = this.mongo.getDB('admin')._helloOrLegacyHello();
- if (!res) {
- jsTest.log("KeyVault: We do not have a connection to the database. Throwing.");
- throw e;
- }
- this.keyColl = this.mongo.getDataKeyCollection();
- }
- } while (true);
- }
-
constructor(mongo) {
this.mongo = mongo;
- var collection = this._runCommand(this.mongo, this.mongo.getDataKeyCollection, {});
+ var collection = mongo.getDataKeyCollection();
this.keyColl = collection;
- this._runCommand(this.keyColl, this.keyColl.createIndex, [
+ this.keyColl.createIndex(
{keyAltNames: 1},
- {unique: true, partialFilterExpression: {keyAltNames: {$exists: true}}}
- ]);
+ {unique: true, partialFilterExpression: {keyAltNames: {$exists: true}}});
}
createKey(kmsProvider, param2 = undefined, param3 = undefined) {
@@ -59,8 +35,7 @@ class KeyVault {
return "TypeError: customer master key must be of String type.";
}
- var masterKeyAndMaterial = this._runCommand(
- this.mongo, this.mongo.generateDataKey, [kmsProvider, customerMasterKey]);
+ var masterKeyAndMaterial = this.mongo.generateDataKey(kmsProvider, customerMasterKey);
var masterKey = masterKeyAndMaterial.masterKey;
var current = ISODate();
@@ -91,24 +66,24 @@ class KeyVault {
doc.keyAltNames = keyAltNames;
}
- this._runCommand(this.keyColl, this.keyColl.insert, [doc]);
+ this.keyColl.insert(doc);
return uuid;
}
getKey(keyId) {
- return this._runCommand(this.keyColl, this.keyColl.find, [{"_id": keyId}]);
+ return this.keyColl.find({"_id": keyId});
}
getKeyByAltName(keyAltName) {
- return this._runCommand(this.keyColl, this.keyColl.find, [{"keyAltNames": keyAltName}]);
+ return this.keyColl.find({"keyAltNames": keyAltName});
}
deleteKey(keyId) {
- return this._runCommand(this.keyColl, this.keyColl.deleteOne, [{"_id": keyId}]);
+ return this.keyColl.deleteOne({"_id": keyId});
}
getKeys() {
- return this._runCommand(this.keyColl, this.keyColl.find, []);
+ return this.keyColl.find();
}
addKeyAlternateName(keyId, keyAltName) {
@@ -117,31 +92,27 @@ class KeyVault {
if (typeof keyAltName === "object") {
return "TypeError: key alternate name cannot be object or array type.";
}
- return this._runCommand(
- this.keyColl, this.keyColl.findAndModify, [{
- query: {"_id": keyId},
- update: {$push: {"keyAltNames": keyAltName}, $currentDate: {"updateDate": true}},
- }]);
+ return this.keyColl.findAndModify({
+ query: {"_id": keyId},
+ update: {$push: {"keyAltNames": keyAltName}, $currentDate: {"updateDate": true}},
+ });
}
removeKeyAlternateName(keyId, keyAltName) {
if (typeof keyAltName === "object") {
return "TypeError: key alternate name cannot be object or array type.";
}
-
- const ret = this._runCommand(
- this.keyColl, this.keyColl.findAndModify, [{
- query: {"_id": keyId},
- update: {$pull: {"keyAltNames": keyAltName}, $currentDate: {"updateDate": true}}
- }]);
+ const ret = this.keyColl.findAndModify({
+ query: {"_id": keyId},
+ update: {$pull: {"keyAltNames": keyAltName}, $currentDate: {"updateDate": true}}
+ });
if (ret != null && ret.keyAltNames.length === 1 && ret.keyAltNames[0] === keyAltName) {
// Remove the empty array to prevent duplicate key violations
- return this._runCommand(
- this.keyColl, this.keyColl.findAndModify, [{
- query: {"_id": keyId, "keyAltNames": undefined},
- update: {$unset: {"keyAltNames": ""}, $currentDate: {"updateDate": true}}
- }]);
+ return this.keyColl.findAndModify({
+ query: {"_id": keyId, "keyAltNames": undefined},
+ update: {$unset: {"keyAltNames": ""}, $currentDate: {"updateDate": true}}
+ });
}
return ret;
}