(configuration, spec, context)
| 4 | const { extractAuthFromConnectionString } = require('../utils'); |
| 5 | |
| 6 | function resolveConnectionString(configuration, spec, context) { |
| 7 | const isShardedEnvironment = configuration.topologyType === 'Sharded'; |
| 8 | const useMultipleMongoses = spec && !!spec.useMultipleMongoses; |
| 9 | const username = context && context.user; |
| 10 | const password = context && context.password; |
| 11 | const authSource = (context && context.authSource) || 'admin'; |
| 12 | const authString = |
| 13 | process.env.AUTH === 'auth' |
| 14 | ? `${extractAuthFromConnectionString(process.env.MONGODB_URI)}@` |
| 15 | : ''; |
| 16 | const connectionString = |
| 17 | isShardedEnvironment && !useMultipleMongoses |
| 18 | ? `mongodb://${authString}${configuration.host}:${configuration.port}/${configuration.db}?directConnection=false&authSource=${authSource}` |
| 19 | : configuration.url({ username, password, authSource }); |
| 20 | return connectionString; |
| 21 | } |
| 22 | |
| 23 | module.exports = { resolveConnectionString }; |
no test coverage detected