Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

WIP [do not review]: Simplify connecting, fix double authSource #348

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,32 @@ console.log(c.driverUrl)
```javascript
const Connection = require('mongodb-connection-model');

Connection.from(
'mongodb://someUsername:testPassword@localhost',
(error, result) => {
console.log(result);
>>> `{
hosts: [{ host: 'localhost', port: 27017 }],
hostname: 'localhost',
port: 27017,
auth: {
username: 'someUsername',
password: 'testPassword',
db: 'admin'
},
isSrvRecord: false,
authStrategy: 'MONGODB',
mongodbUsername: 'someUsername',
mongodbPassword: 'testPassword',
mongodbDatabaseName: 'admin',
extraOptions: {},
connectionType: 'NODE_DRIVER',
readPreference: 'primary',
kerberosCanonicalizeHostname: false,
sslMethod: 'NONE',
sshTunnel: 'NONE',
sshTunnelPort: 22
}`
}
const result = await Connection.from(
'mongodb://someUsername:testPassword@localhost'
);
console.log(result);
>>> `{
hosts: [{ host: 'localhost', port: 27017 }],
hostname: 'localhost',
port: 27017,
auth: {
username: 'someUsername',
password: 'testPassword',
db: 'admin'
},
isSrvRecord: false,
authStrategy: 'MONGODB',
mongodbUsername: 'someUsername',
mongodbPassword: 'testPassword',
mongodbDatabaseName: 'admin',
extraOptions: {},
connectionType: 'NODE_DRIVER',
readPreference: 'primary',
kerberosCanonicalizeHostname: false,
sslMethod: 'NONE',
sshTunnel: 'NONE',
sshTunnelPort: 22
}`
```

## Properties
Expand Down Expand Up @@ -415,9 +413,6 @@ This will log the following events to the console:
```javascript
>>> status: { message: 'Validate', pending: true }
>>> status: { message: 'Validate', complete: true }
>>> status: { message: 'Load SSL files', pending: true }
>>> status: { message: 'Load SSL files', skipped: true,
reason: 'The selected SSL mode does not need to load any files.' }
>>> status: { message: 'Create SSH Tunnel', pending: true }
>>> status: { message: 'Create SSH Tunnel', complete: true}
>>> status: { message: 'Connect to MongoDB', pending: true }
Expand Down Expand Up @@ -445,8 +440,6 @@ This will log the following events to the console:
```javascript
>>> status: { message: 'Validate', pending: true }
>>> status: { message: 'Validate', complete: true }
>>> status: { message: 'Load SSL files', pending: true }
>>> status: { message: 'Load SSL files', complete: true}
>>> status: { message: 'Create SSH Tunnel', pending: true }
>>> status: { message: 'Create SSH Tunnel', skipped: true,
reason: 'The selected SSH Tunnel mode is NONE.'}
Expand Down
65 changes: 41 additions & 24 deletions constants/ssl-method-values.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
// Allowed values for the `sslMethod` field

/**
* Do not use SSL for anything.
*/
const NONE = 'NONE';
/**
* Use system CA.
*/
const SYSTEMCA = 'SYSTEMCA';
/**
* Use SSL if available.
*/
const IFAVAILABLE = 'IFAVAILABLE';
/**
* Use SSL but do not perform any validation of the certificate chain.
*/
const UNVALIDATED = 'UNVALIDATED';
/**
* The driver should validate the server certificate and fail to connect if validation fails.
*/
const SERVER = 'SERVER';
/**
* The driver must present a valid certificate and validate the server certificate.
*/
const ALL = 'ALL';

module.exports = [
/**
* Do not use SSL for anything.
*/
'NONE',
/**
* Use system CA.
*/
'SYSTEMCA',
/**
* Use SSL if available.
*/
'IFAVAILABLE',
/**
* Use SSL but do not perform any validation of the certificate chain.
*/
'UNVALIDATED',
/**
* The driver should validate the server certificate and fail to connect if validation fails.
*/
'SERVER',
/**
* The driver must present a valid certificate and validate the server certificate.
*/
'ALL'
NONE,
SYSTEMCA,
IFAVAILABLE,
UNVALIDATED,
SERVER,
ALL
];

module.exports.SSL_METHODS = {
NONE,
SYSTEMCA,
IFAVAILABLE,
UNVALIDATED,
SERVER,
ALL
};
Loading