-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the CLI param "-dbURI" #4385
Changes from all commits
e4ef003
c521ca6
477566c
d9fd270
b7cdb85
6a9bd19
4fbebd3
faddd42
8d0617c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- Add: servicePath field to builtin attributes (#2877) | ||
- Fix: logDeprecate not working correctly (`geo:json` wrongly considered as deprecated) | ||
- Fix: improve error traces (#4387) | ||
- Add: CLI parameter -dbUri / env var ORION_MONGO_URI (#3794) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,7 @@ static void mongoDriverLogger | |
*/ | ||
static std::string composeMongoUri | ||
( | ||
const char* dbURI, | ||
const char* host, | ||
const char* rplSet, | ||
const char* username, | ||
|
@@ -329,54 +330,82 @@ static std::string composeMongoUri | |
{ | ||
// Compose the mongoUri, taking into account all information | ||
|
||
std::string uri = "mongodb://"; | ||
std::string uri; | ||
|
||
// Add auth parameter if included | ||
if (strlen(username) != 0 && strlen(passwd) != 0) | ||
if (strlen(dbURI) != 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If That's fine, but such case of combining old and new CLI would be probably a misconfiguration that should be at least warned to the user (or maybe even better, raise a LM_X so the user have the chance to fix the configuration). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 477566c |
||
{ | ||
uri += username + std::string(":") + passwd + "@"; | ||
} | ||
if (strlen(username) != 0 || strlen(authDb) != 0 || strlen(rplSet) != 0 || strlen(mechanism) != 0 || dbSSL || dbDisableRetryWrites || timeout > 0) | ||
{ | ||
LM_X(1, ("Invalid Command Line Options: -dbURI cannot be combined with -dbhost, -rplSet, -dbTimeout, -dbuser, -dbAuthMech, -dbAuthDb, -dbSSL and -dbDisableRetryWrites")); | ||
} | ||
|
||
uri += host + std::string("/"); | ||
const char* pwd = strstr(dbURI, "${PWD}"); | ||
if (pwd != NULL) | ||
{ | ||
if (strlen(passwd) == 0) | ||
{ | ||
LM_X(1, ("Invalid Command Line Options: -dbURI is used with a password substitution, but no password (-dbpwd) is supplied")); | ||
} | ||
|
||
if (strlen(authDb) != 0) | ||
{ | ||
uri += authDb; | ||
// +6 is the length of the "${PWD}" | ||
uri = std::string(dbURI, pwd - dbURI) + passwd + (pwd + 6); | ||
ctc-nakatsuka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
uri = dbURI; | ||
} | ||
} | ||
else | ||
{ | ||
uri = "mongodb://"; | ||
|
||
// First option prefix is '?' symbol | ||
std::string optionPrefix = "?"; | ||
// Add auth parameter if included | ||
if (strlen(username) != 0 && strlen(passwd) != 0) | ||
{ | ||
uri += username + std::string(":") + passwd + "@"; | ||
} | ||
|
||
if (strlen(rplSet) != 0) | ||
{ | ||
uri += optionPrefix + "replicaSet=" + rplSet; | ||
optionPrefix = "&"; | ||
} | ||
uri += host + std::string("/"); | ||
|
||
if (strlen(mechanism) != 0) | ||
{ | ||
uri += optionPrefix + "authMechanism=" + mechanism; | ||
optionPrefix = "&"; | ||
} | ||
if (strlen(authDb) != 0) | ||
{ | ||
uri += authDb; | ||
} | ||
|
||
if (dbSSL) | ||
{ | ||
uri += optionPrefix + "tls=true&tlsAllowInvalidCertificates=true"; | ||
optionPrefix = "&"; | ||
} | ||
// First option prefix is '?' symbol | ||
std::string optionPrefix = "?"; | ||
|
||
if (dbDisableRetryWrites) | ||
{ | ||
uri += optionPrefix + "retryWrites=false"; | ||
optionPrefix = "&"; | ||
} | ||
if (strlen(rplSet) != 0) | ||
{ | ||
uri += optionPrefix + "replicaSet=" + rplSet; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (timeout > 0) | ||
{ | ||
char buf[STRING_SIZE_FOR_LONG]; | ||
i2s(timeout, buf, sizeof(buf)); | ||
uri += optionPrefix + "connectTimeoutMS=" + buf; | ||
optionPrefix = "&"; | ||
if (strlen(mechanism) != 0) | ||
{ | ||
uri += optionPrefix + "authMechanism=" + mechanism; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (dbSSL) | ||
{ | ||
uri += optionPrefix + "tls=true&tlsAllowInvalidCertificates=true"; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (dbDisableRetryWrites) | ||
{ | ||
uri += optionPrefix + "retryWrites=false"; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (timeout > 0) | ||
{ | ||
char buf[STRING_SIZE_FOR_LONG]; | ||
i2s(timeout, buf, sizeof(buf)); | ||
uri += optionPrefix + "connectTimeoutMS=" + buf; | ||
optionPrefix = "&"; | ||
} | ||
} | ||
|
||
LM_T(LmtMongo, ("MongoDB connection URI: '%s'", offuscatePassword(uri, passwd).c_str())); | ||
|
@@ -392,6 +421,7 @@ static std::string composeMongoUri | |
*/ | ||
int orion::mongoConnectionPoolInit | ||
( | ||
const char* dbURI, | ||
const char* host, | ||
const char* db, | ||
const char* rplSet, | ||
|
@@ -421,7 +451,7 @@ int orion::mongoConnectionPoolInit | |
atexit(shutdownClient); | ||
|
||
// Set mongo Uri to connect | ||
std::string uri = composeMongoUri(host, rplSet, username, passwd, mechanism, authDb, dbSSL, dbDisableRetryWrites, timeout); | ||
std::string uri = composeMongoUri(dbURI, host, rplSet, username, passwd, mechanism, authDb, dbSSL, dbDisableRetryWrites, timeout); | ||
|
||
#ifdef UNIT_TEST | ||
/* Basically, we are mocking all the DB pool with a single connection. The getMongoConnection() and mongoReleaseConnection() methods | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGES_NEXT_RELEASE should include the changes in this PR. Maybe something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, documetnation in cli.md should be modified to describe the new CLI and env var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d9fd270 and b7cdb85