mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
74
node_modules/mongodb/lib/operations/add_user.js
generated
vendored
Normal file
74
node_modules/mongodb/lib/operations/add_user.js
generated
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AddUserOperation = void 0;
|
||||
const crypto = require("crypto");
|
||||
const error_1 = require("../error");
|
||||
const utils_1 = require("../utils");
|
||||
const command_1 = require("./command");
|
||||
const operation_1 = require("./operation");
|
||||
/** @internal */
|
||||
class AddUserOperation extends command_1.CommandOperation {
|
||||
constructor(db, username, password, options) {
|
||||
super(db, options);
|
||||
this.db = db;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.options = options ?? {};
|
||||
}
|
||||
execute(server, session, callback) {
|
||||
const db = this.db;
|
||||
const username = this.username;
|
||||
const password = this.password;
|
||||
const options = this.options;
|
||||
// Error out if digestPassword set
|
||||
// v5 removed the digestPassword option from AddUserOptions but we still want to throw
|
||||
// an error when digestPassword is provided.
|
||||
if ('digestPassword' in options && options.digestPassword != null) {
|
||||
return callback(new error_1.MongoInvalidArgumentError('Option "digestPassword" not supported via addUser, use db.command(...) instead'));
|
||||
}
|
||||
let roles;
|
||||
if (!options.roles || (Array.isArray(options.roles) && options.roles.length === 0)) {
|
||||
(0, utils_1.emitWarningOnce)('Creating a user without roles is deprecated. Defaults to "root" if db is "admin" or "dbOwner" otherwise');
|
||||
if (db.databaseName.toLowerCase() === 'admin') {
|
||||
roles = ['root'];
|
||||
}
|
||||
else {
|
||||
roles = ['dbOwner'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
roles = Array.isArray(options.roles) ? options.roles : [options.roles];
|
||||
}
|
||||
let topology;
|
||||
try {
|
||||
topology = (0, utils_1.getTopology)(db);
|
||||
}
|
||||
catch (error) {
|
||||
return callback(error);
|
||||
}
|
||||
const digestPassword = topology.lastHello().maxWireVersion >= 7;
|
||||
let userPassword = password;
|
||||
if (!digestPassword) {
|
||||
// Use node md5 generator
|
||||
const md5 = crypto.createHash('md5');
|
||||
// Generate keys used for authentication
|
||||
md5.update(`${username}:mongo:${password}`);
|
||||
userPassword = md5.digest('hex');
|
||||
}
|
||||
// Build the command to execute
|
||||
const command = {
|
||||
createUser: username,
|
||||
customData: options.customData || {},
|
||||
roles: roles,
|
||||
digestPassword
|
||||
};
|
||||
// No password
|
||||
if (typeof password === 'string') {
|
||||
command.pwd = userPassword;
|
||||
}
|
||||
super.executeCommand(server, session, command, callback);
|
||||
}
|
||||
}
|
||||
exports.AddUserOperation = AddUserOperation;
|
||||
(0, operation_1.defineAspects)(AddUserOperation, [operation_1.Aspect.WRITE_OPERATION]);
|
||||
//# sourceMappingURL=add_user.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue