mongodb 2.2.36 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +24 -10
- package/CHANGES_3.0.0.md +288 -0
- package/HISTORY.md +120 -25
- package/README.md +247 -176
- package/conf.json +15 -14
- package/index.js +12 -6
- package/lib/admin.js +156 -364
- package/lib/aggregation_cursor.js +86 -88
- package/lib/apm.js +192 -149
- package/lib/authenticate.js +73 -53
- package/lib/bulk/common.js +140 -115
- package/lib/bulk/ordered.js +273 -195
- package/lib/bulk/unordered.js +291 -201
- package/lib/change_stream.js +359 -0
- package/lib/collection.js +1128 -1368
- package/lib/command_cursor.js +100 -73
- package/lib/cursor.js +454 -358
- package/lib/db.js +775 -771
- package/lib/gridfs/chunk.js +38 -34
- package/lib/gridfs/grid_store.js +590 -593
- package/lib/gridfs-stream/download.js +46 -40
- package/lib/gridfs-stream/index.js +24 -45
- package/lib/gridfs-stream/upload.js +28 -26
- package/lib/metadata.js +22 -16
- package/lib/mongo_client.js +708 -285
- package/lib/topologies/mongos.js +444 -0
- package/lib/topologies/replset.js +501 -0
- package/lib/topologies/server.js +448 -0
- package/lib/topologies/topology_base.js +441 -0
- package/lib/url_parser.js +334 -257
- package/lib/utils.js +210 -132
- package/package.json +20 -32
- package/yarn.lock +3728 -0
- package/lib/mongos.js +0 -533
- package/lib/read_preference.js +0 -131
- package/lib/replset.js +0 -582
- package/lib/server.js +0 -518
- package/lib/topology_base.js +0 -191
package/lib/authenticate.js
CHANGED
|
@@ -1,109 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
, handleCallback = require('./utils').handleCallback
|
|
3
|
-
, MongoError = require('mongodb-core').MongoError
|
|
4
|
-
, f = require('util').format;
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
|
-
var
|
|
3
|
+
var shallowClone = require('./utils').shallowClone,
|
|
4
|
+
handleCallback = require('./utils').handleCallback,
|
|
5
|
+
MongoError = require('mongodb-core').MongoError,
|
|
6
|
+
f = require('util').format;
|
|
7
|
+
|
|
8
|
+
var authenticate = function(client, username, password, options, callback) {
|
|
7
9
|
// Did the user destroy the topology
|
|
8
|
-
if(
|
|
10
|
+
if (client.topology && client.topology.isDestroyed())
|
|
11
|
+
return callback(new MongoError('topology was destroyed'));
|
|
9
12
|
|
|
10
13
|
// the default db to authenticate against is 'self'
|
|
11
|
-
// if
|
|
12
|
-
var authdb = options.dbName
|
|
13
|
-
authdb = self.authSource ? self.authSource : authdb;
|
|
14
|
+
// if authententicate is called from a retry context, it may be another one, like admin
|
|
15
|
+
var authdb = options.dbName;
|
|
14
16
|
authdb = options.authdb ? options.authdb : authdb;
|
|
15
17
|
authdb = options.authSource ? options.authSource : authdb;
|
|
16
18
|
|
|
17
19
|
// Callback
|
|
18
20
|
var _callback = function(err, result) {
|
|
19
|
-
if(
|
|
20
|
-
|
|
21
|
+
if (client.listeners('authenticated').length > 0) {
|
|
22
|
+
client.emit('authenticated', err, result);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// Return to caller
|
|
24
26
|
handleCallback(callback, err, result);
|
|
25
|
-
}
|
|
27
|
+
};
|
|
26
28
|
|
|
27
29
|
// authMechanism
|
|
28
30
|
var authMechanism = options.authMechanism || '';
|
|
29
31
|
authMechanism = authMechanism.toUpperCase();
|
|
30
32
|
|
|
31
33
|
// If classic auth delegate to auth command
|
|
32
|
-
if(authMechanism
|
|
33
|
-
|
|
34
|
-
if(err) return handleCallback(callback, err, false);
|
|
34
|
+
if (authMechanism === 'MONGODB-CR') {
|
|
35
|
+
client.topology.auth('mongocr', authdb, username, password, function(err) {
|
|
36
|
+
if (err) return handleCallback(callback, err, false);
|
|
35
37
|
_callback(null, true);
|
|
36
38
|
});
|
|
37
|
-
} else if(authMechanism
|
|
38
|
-
|
|
39
|
-
if(err) return handleCallback(callback, err, false);
|
|
39
|
+
} else if (authMechanism === 'PLAIN') {
|
|
40
|
+
client.topology.auth('plain', authdb, username, password, function(err) {
|
|
41
|
+
if (err) return handleCallback(callback, err, false);
|
|
40
42
|
_callback(null, true);
|
|
41
43
|
});
|
|
42
|
-
} else if(authMechanism
|
|
43
|
-
|
|
44
|
-
if(err) return handleCallback(callback, err, false);
|
|
44
|
+
} else if (authMechanism === 'MONGODB-X509') {
|
|
45
|
+
client.topology.auth('x509', authdb, username, password, function(err) {
|
|
46
|
+
if (err) return handleCallback(callback, err, false);
|
|
45
47
|
_callback(null, true);
|
|
46
48
|
});
|
|
47
|
-
} else if(authMechanism
|
|
48
|
-
|
|
49
|
-
if(err) return handleCallback(callback, err, false);
|
|
49
|
+
} else if (authMechanism === 'SCRAM-SHA-1') {
|
|
50
|
+
client.topology.auth('scram-sha-1', authdb, username, password, function(err) {
|
|
51
|
+
if (err) return handleCallback(callback, err, false);
|
|
50
52
|
_callback(null, true);
|
|
51
53
|
});
|
|
52
|
-
} else if(authMechanism
|
|
53
|
-
if(process.platform
|
|
54
|
-
|
|
55
|
-
if(err) return handleCallback(callback, err, false);
|
|
54
|
+
} else if (authMechanism === 'GSSAPI') {
|
|
55
|
+
if (process.platform === 'win32') {
|
|
56
|
+
client.topology.auth('sspi', authdb, username, password, options, function(err) {
|
|
57
|
+
if (err) return handleCallback(callback, err, false);
|
|
56
58
|
_callback(null, true);
|
|
57
59
|
});
|
|
58
60
|
} else {
|
|
59
|
-
|
|
60
|
-
if(err) return handleCallback(callback, err, false);
|
|
61
|
+
client.topology.auth('gssapi', authdb, username, password, options, function(err) {
|
|
62
|
+
if (err) return handleCallback(callback, err, false);
|
|
61
63
|
_callback(null, true);
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
|
-
} else if(authMechanism
|
|
65
|
-
|
|
66
|
-
if(err) return handleCallback(callback, err, false);
|
|
66
|
+
} else if (authMechanism === 'DEFAULT') {
|
|
67
|
+
client.topology.auth('default', authdb, username, password, function(err) {
|
|
68
|
+
if (err) return handleCallback(callback, err, false);
|
|
67
69
|
_callback(null, true);
|
|
68
70
|
});
|
|
69
71
|
} else {
|
|
70
|
-
handleCallback(
|
|
72
|
+
handleCallback(
|
|
73
|
+
callback,
|
|
74
|
+
MongoError.create({
|
|
75
|
+
message: f('authentication mechanism %s not supported', options.authMechanism),
|
|
76
|
+
driver: true
|
|
77
|
+
})
|
|
78
|
+
);
|
|
71
79
|
}
|
|
72
|
-
}
|
|
80
|
+
};
|
|
73
81
|
|
|
74
82
|
module.exports = function(self, username, password, options, callback) {
|
|
75
|
-
if(typeof options
|
|
83
|
+
if (typeof options === 'function') (callback = options), (options = {});
|
|
84
|
+
options = options || {};
|
|
85
|
+
|
|
76
86
|
// Shallow copy the options
|
|
77
87
|
options = shallowClone(options);
|
|
78
88
|
|
|
79
89
|
// Set default mechanism
|
|
80
|
-
if(!options.authMechanism) {
|
|
90
|
+
if (!options.authMechanism) {
|
|
81
91
|
options.authMechanism = 'DEFAULT';
|
|
82
|
-
} else if(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
} else if (
|
|
93
|
+
options.authMechanism !== 'GSSAPI' &&
|
|
94
|
+
options.authMechanism !== 'DEFAULT' &&
|
|
95
|
+
options.authMechanism !== 'MONGODB-CR' &&
|
|
96
|
+
options.authMechanism !== 'MONGODB-X509' &&
|
|
97
|
+
options.authMechanism !== 'SCRAM-SHA-1' &&
|
|
98
|
+
options.authMechanism !== 'PLAIN'
|
|
99
|
+
) {
|
|
100
|
+
return handleCallback(
|
|
101
|
+
callback,
|
|
102
|
+
MongoError.create({
|
|
103
|
+
message:
|
|
104
|
+
'only DEFAULT, GSSAPI, PLAIN, MONGODB-X509, SCRAM-SHA-1 or MONGODB-CR is supported by authMechanism',
|
|
105
|
+
driver: true
|
|
106
|
+
})
|
|
107
|
+
);
|
|
89
108
|
}
|
|
90
109
|
|
|
91
110
|
// If we have a callback fallback
|
|
92
|
-
if(typeof callback
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
if (typeof callback === 'function')
|
|
112
|
+
return authenticate(self, username, password, options, function(err, r) {
|
|
113
|
+
// Support failed auth method
|
|
114
|
+
if (err && err.message && err.message.indexOf('saslStart') !== -1) err.code = 59;
|
|
115
|
+
// Reject error
|
|
116
|
+
if (err) return callback(err, r);
|
|
117
|
+
callback(null, r);
|
|
118
|
+
});
|
|
99
119
|
|
|
100
120
|
// Return a promise
|
|
101
121
|
return new self.s.promiseLibrary(function(resolve, reject) {
|
|
102
122
|
authenticate(self, username, password, options, function(err, r) {
|
|
103
123
|
// Support failed auth method
|
|
104
|
-
if(err && err.message && err.message.indexOf('saslStart')
|
|
124
|
+
if (err && err.message && err.message.indexOf('saslStart') !== -1) err.code = 59;
|
|
105
125
|
// Reject error
|
|
106
|
-
if(err) return reject(err);
|
|
126
|
+
if (err) return reject(err);
|
|
107
127
|
resolve(r);
|
|
108
128
|
});
|
|
109
129
|
});
|