-
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 2 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 |
---|---|---|
|
@@ -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,76 @@ 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 + "@"; | ||
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")); | ||
} | ||
|
||
uri = std::string(dbURI, pwd - dbURI) + passwd + (pwd + 6); | ||
ctc-nakatsuka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
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. Why implementing this password substitution mechanism? Why don't just use the password in the 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. This is because Orion-LD implements that functionality. See also following comment: 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. After reading the documetnation added to cli.md, now it's clear to me how it works :) It can be an interesting feature. Let's keep it. NTC |
||
else | ||
{ | ||
uri = dbURI; | ||
} | ||
} | ||
else | ||
{ | ||
uri = "mongodb://"; | ||
|
||
uri += host + std::string("/"); | ||
// Add auth parameter if included | ||
if (strlen(username) != 0 && strlen(passwd) != 0) | ||
{ | ||
uri += username + std::string(":") + passwd + "@"; | ||
} | ||
|
||
if (strlen(authDb) != 0) | ||
{ | ||
uri += authDb; | ||
} | ||
uri += host + std::string("/"); | ||
|
||
// First option prefix is '?' symbol | ||
std::string optionPrefix = "?"; | ||
if (strlen(authDb) != 0) | ||
{ | ||
uri += authDb; | ||
} | ||
|
||
if (strlen(rplSet) != 0) | ||
{ | ||
uri += optionPrefix + "replicaSet=" + rplSet; | ||
optionPrefix = "&"; | ||
} | ||
// First option prefix is '?' symbol | ||
std::string optionPrefix = "?"; | ||
|
||
if (strlen(mechanism) != 0) | ||
{ | ||
uri += optionPrefix + "authMechanism=" + mechanism; | ||
optionPrefix = "&"; | ||
} | ||
if (strlen(rplSet) != 0) | ||
{ | ||
uri += optionPrefix + "replicaSet=" + rplSet; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (dbSSL) | ||
{ | ||
uri += optionPrefix + "tls=true&tlsAllowInvalidCertificates=true"; | ||
optionPrefix = "&"; | ||
} | ||
if (strlen(mechanism) != 0) | ||
{ | ||
uri += optionPrefix + "authMechanism=" + mechanism; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (dbDisableRetryWrites) | ||
{ | ||
uri += optionPrefix + "retryWrites=false"; | ||
optionPrefix = "&"; | ||
} | ||
if (dbSSL) | ||
{ | ||
uri += optionPrefix + "tls=true&tlsAllowInvalidCertificates=true"; | ||
optionPrefix = "&"; | ||
} | ||
|
||
if (timeout > 0) | ||
{ | ||
char buf[STRING_SIZE_FOR_LONG]; | ||
i2s(timeout, buf, sizeof(buf)); | ||
uri += optionPrefix + "connectTimeoutMS=" + buf; | ||
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 +415,7 @@ static std::string composeMongoUri | |
*/ | ||
int orion::mongoConnectionPoolInit | ||
( | ||
const char* dbURI, | ||
const char* host, | ||
const char* db, | ||
const char* rplSet, | ||
|
@@ -421,7 +445,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