From 82941cc6b6868a452ff8cc674260936d5a0b2a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 29 Feb 2024 12:24:30 +0100 Subject: [PATCH] REMOVE deprecated db related CLIs --- CHANGES_NEXT_RELEASE | 1 + doc/manuals/deprecated.md | 4 +- src/app/contextBroker/contextBroker.cpp | 24 +---- src/lib/mongoBackend/MongoGlobal.cpp | 16 ---- src/lib/mongoBackend/MongoGlobal.h | 8 -- src/lib/mongoDriver/mongoConnectionPool.cpp | 100 ++------------------ src/lib/mongoDriver/mongoConnectionPool.h | 8 -- test/unittests/main_UnitTest.cpp | 18 +--- 8 files changed, 16 insertions(+), 163 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index e69de29bb2..59f9251202 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -0,0 +1 @@ +- Remove: `-dbhost`, `-rplSet`, `-dbTimeout`, `-dbuser`, `-dbAuthMech`, `-dbAuthDb`, `-dbSSL` and `-dbDisableRetryWrites` CLI parameters along with associated env vars, already deprecated in Orion 3.12.0 (use `-dbURI` instead`) \ No newline at end of file diff --git a/doc/manuals/deprecated.md b/doc/manuals/deprecated.md index 9b289331b4..5ed729988b 100644 --- a/doc/manuals/deprecated.md +++ b/doc/manuals/deprecated.md @@ -17,7 +17,7 @@ A list of deprecated features and the version in which they were deprecated foll * CLI parameters (and associated env vars): `-dbhost`, `-rplSet`, `-dbTimeout`, `-dbuser`, `-dbAuthMech`, `-dbAuthDb`, `-dbSSL` and `-dbDisableRetryWrites` in Orion 3.12.0. Use `dbURI` instead, - checking [this section](#mapping-to-mongouri-from-old-cli-parameters) if you need to know hot to build the MongoDB URI. + checking [this section](#mapping-to-mongouri-from-old-cli-parameters) if you need to know hot to build the MongoDB URI (removed in Orion 3.13.0). * `geo:point`, `geo:line`, `geo:box` and `geo:polygon` attribute types in Orion 3.10.0. Use `geo:json` instead. * `GET /v2` operation in Orion 3.8.0. This operation is pretty useless and not actually used. * Initial notification in subscriptions (along with `skipInitialNotification` option) in Orion 3.1.0. @@ -134,12 +134,12 @@ The following table provides information about the last Orion version supporting | **Removed feature** | **Last Orion version supporting feature** | **That version release date** | |----------------------------------------------------------------------------|-------------------------------------------|---------------------------------| -| CLI `-dbhost`, `-rplSet`, `-dbTimeout`, `-dbuser`, `-dbAuthMech`, `-dbAuthDb`, `-dbSSL` and `-dbDisableRetryWrites` (and associated env vars) | Not yet defined | Not yet defined | | `attributes` field in `POST /v2/entities` operation | Not yet defined | Not yet defined | | `APPEND`, `UPDATE`, etc. action types in `POST /v2/op/update` | Not yet defined | Not yet defined | | `dateCreated` and `dateModified` in `options` URI parameter | Not yet defined | Not yet defined | | `GET /v2` operation | Not yet defined | Not yet defined | | `geo:point`, `geo:line`, `geo:box` and `geo:polygon` attribute types | Not yet defined | Not yet defined | +| CLI `-dbhost`, `-rplSet`, `-dbTimeout`, `-dbuser`, `-dbAuthMech`, `-dbAuthDb`, `-dbSSL` and `-dbDisableRetryWrites` (and associated env vars) | 3.12.0 | February 29th, 2024 | | `location` metadata to specify entity location | 3.10.1 | June 12th, 2023 | | NGSIv1 API (along with CLI: `-strictNgsiv1Ids` and `-ngsiv1Autocast`) | 3.9.0 (*) | June 2nd, 2023 | | `/ngsi10` and `/ngsi9` URL prefixes | 3.7.0 (*) | May 26th, 2022 | diff --git a/src/app/contextBroker/contextBroker.cpp b/src/app/contextBroker/contextBroker.cpp index d1cc8a57b2..b8ede361f5 100644 --- a/src/app/contextBroker/contextBroker.cpp +++ b/src/app/contextBroker/contextBroker.cpp @@ -139,15 +139,8 @@ static bool isFatherProcess = false; bool fg; char bindAddress[MAX_LEN_IP]; int port; -char dbHost[256]; -char rplSet[64]; char dbName[64]; -char user[256]; char pwd[256]; -char authMech[64]; -char authDb[64]; -bool dbSSL; -bool dbDisableRetryWrites; char dbURI[1024]; char pidPath[256]; bool harakiri; @@ -159,7 +152,6 @@ bool https; bool mtenant; char allowedOrigin[64]; int maxAge; -long dbTimeout; long httpTimeout; long mqttTimeout; int dbPoolSize; @@ -298,18 +290,9 @@ PaArgument paArgs[] = { "-pidpath", pidPath, "PID_PATH", PaString, PaOpt, PIDPATH, PaNL, PaNL, PIDPATH_DESC }, { "-dbURI", dbURI, "MONGO_URI", PaString, PaOpt, _i "", PaNL, PaNL, DBURI_DESC }, - { "-dbhost", dbHost, "MONGO_HOST", PaString, PaOpt, LOCALHOST, PaNL, PaNL, DBHOST_DESC }, - { "-rplSet", rplSet, "MONGO_REPLICA_SET", PaString, PaOpt, _i "", PaNL, PaNL, RPLSET_DESC }, - { "-dbuser", user, "MONGO_USER", PaString, PaOpt, _i "", PaNL, PaNL, DBUSER_DESC }, { "-dbpwd", pwd, "MONGO_PASSWORD", PaString, PaOpt, _i "", PaNL, PaNL, DBPASSWORD_DESC }, - { "-dbAuthMech", authMech, "MONGO_AUTH_MECH", PaString, PaOpt, _i "", PaNL, PaNL, DBAUTHMECH_DESC }, - { "-dbAuthDb", authDb, "MONGO_AUTH_SOURCE", PaString, PaOpt, _i "", PaNL, PaNL, DBAUTHDB_DESC }, - { "-dbSSL", &dbSSL, "MONGO_SSL", PaBool, PaOpt, false, false, true, DBSSL_DESC }, - { "-dbDisableRetryWrites", &dbDisableRetryWrites, "MONGO_DISABLE_RETRY_WRITES", PaBool, PaOpt, false, false, true, DBDISABLERETRYWRITES_DESC }, - { "-db", dbName, "MONGO_DB", PaString, PaOpt, _i "orion", PaNL, PaNL, DB_DESC }, - { "-dbTimeout", &dbTimeout, "MONGO_TIMEOUT", PaULong, PaOpt, 0, 0, UINT_MAX, DB_TMO_DESC }, { "-dbPoolSize", &dbPoolSize, "MONGO_POOL_SIZE", PaInt, PaOpt, 10, 1, 10000, DBPS_DESC }, { "-ipv4", &useOnlyIPv4, "USEIPV4", PaBool, PaOpt, false, false, true, USEIPV4_DESC }, @@ -1133,11 +1116,6 @@ int main(int argC, char* argV[]) LM_X(1, ("dbName too long (max %d characters)", DB_NAME_MAX_LEN)); } - if ((strlen(authMech) > 0) && (strncmp(authMech, "SCRAM-SHA-1", strlen("SCRAM-SHA-1")) != 0) && (strncmp(authMech, "SCRAM-SHA-256", strlen("SCRAM-SHA-256")) != 0)) - { - LM_X(1, ("Fatal Error (-dbAuthMech must be either SCRAM-SHA-1 or SCRAM-SHA-256")); - } - if (useOnlyIPv6 && useOnlyIPv4) { LM_X(1, ("Fatal Error (-ipv4 and -ipv6 can not be activated at the same time. They are incompatible)")); @@ -1220,7 +1198,7 @@ int main(int argC, char* argV[]) alarmMgr.init(relogAlarms); mqttMgr.init(mqttTimeout); orionInit(orionExit, ORION_VERSION, policy, statCounters, statSemWait, statTiming, statNotifQueue, strictIdv1); - mongoInit(dbURI, dbHost, rplSet, dbName, user, pwd, authMech, authDb, dbSSL, dbDisableRetryWrites, mtenant, dbTimeout, writeConcern, dbPoolSize, statSemWait); + mongoInit(dbURI, dbName, pwd, mtenant, writeConcern, dbPoolSize, statSemWait); metricsMgr.init(!disableMetrics, statSemWait); logSummaryInit(&lsPeriod); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 85308f228b..ed1c979ca5 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -105,17 +105,9 @@ bool mongoMultitenant(void) void mongoInit ( const char* dbURI, - const char* dbHost, - const char* rplSet, std::string dbName, - const char* user, const char* pwd, - const char* mechanism, - const char* authDb, - bool dbSSL, - bool dbDisableRetryWrites, bool mtenant, - int64_t timeout, int writeConcern, int dbPoolSize, bool mutexTimeStat @@ -125,17 +117,9 @@ void mongoInit multitenant = mtenant; if (orion::mongoConnectionPoolInit(dbURI, - dbHost, dbName.c_str(), - rplSet, - user, pwd, - mechanism, - authDb, - dbSSL, - dbDisableRetryWrites, mtenant, - timeout, writeConcern, dbPoolSize, mutexTimeStat) != 0) diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index caa6058e8f..7b951c0784 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -72,17 +72,9 @@ extern bool mongoMultitenant(void); void mongoInit ( const char* dbURI, - const char* dbHost, - const char* rplSet, std::string dbName, - const char* user, const char* pwd, - const char* mechanism, - const char* authDb, - bool dbSSL, - bool dbDisableRetryWrites, bool mtenant, - int64_t timeout, int writeConcern, int dbPoolSize, bool mutexTimeStat diff --git a/src/lib/mongoDriver/mongoConnectionPool.cpp b/src/lib/mongoDriver/mongoConnectionPool.cpp index 855896753e..bcde607889 100644 --- a/src/lib/mongoDriver/mongoConnectionPool.cpp +++ b/src/lib/mongoDriver/mongoConnectionPool.cpp @@ -312,100 +312,28 @@ static void mongoDriverLogger /* **************************************************************************** * -* mongoConnectionPoolInit - +* composeMongoUri - */ -static std::string composeMongoUri -( - const char* dbURI, - const char* host, - const char* rplSet, - const char* username, - const char* passwd, - const char* mechanism, - const char* authDb, - bool dbSSL, - bool dbDisableRetryWrites, - int64_t timeout -) +static std::string composeMongoUri(const char* dbURI, const char* passwd) { // Compose the mongoUri, taking into account all information std::string uri; - if (strlen(dbURI) != 0) + const char* pwd = strstr(dbURI, "${PWD}"); + if (pwd != NULL) { - if (strlen(username) != 0 || strlen(authDb) != 0 || strlen(rplSet) != 0 || strlen(mechanism) != 0 || dbSSL || dbDisableRetryWrites || timeout > 0) + if (strlen(passwd) == 0) { - LM_X(1, ("Invalid Command Line Options: -dbURI cannot be combined with -dbhost, -rplSet, -dbTimeout, -dbuser, -dbAuthMech, -dbAuthDb, -dbSSL and -dbDisableRetryWrites")); + LM_X(1, ("Invalid Command Line Options: -dbURI is used with a password substitution, but no password (-dbpwd) is supplied")); } - 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")); - } - - // +6 is the length of the "${PWD}" - uri = std::string(dbURI, pwd - dbURI) + passwd + (pwd + 6); - } - else - { - uri = dbURI; - } + // +6 is the length of the "${PWD}" + uri = std::string(dbURI, pwd - dbURI) + passwd + (pwd + 6); } else { - uri = "mongodb://"; - - // Add auth parameter if included - if (strlen(username) != 0 && strlen(passwd) != 0) - { - uri += username + std::string(":") + passwd + "@"; - } - - uri += host + std::string("/"); - - if (strlen(authDb) != 0) - { - uri += authDb; - } - - // First option prefix is '?' symbol - std::string optionPrefix = "?"; - - if (strlen(rplSet) != 0) - { - uri += optionPrefix + "replicaSet=" + rplSet; - 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 = "&"; - } + uri = dbURI; } LM_T(LmtMongo, ("MongoDB connection URI: '%s'", offuscatePassword(uri, passwd).c_str())); @@ -422,17 +350,9 @@ static std::string composeMongoUri int orion::mongoConnectionPoolInit ( const char* dbURI, - const char* host, const char* db, - const char* rplSet, - const char* username, const char* passwd, - const char* mechanism, - const char* authDb, - bool dbSSL, - bool dbDisableRetryWrites, bool mtenant, - int64_t timeout, int writeConcern, int poolSize, bool semTimeStat @@ -451,7 +371,7 @@ int orion::mongoConnectionPoolInit atexit(shutdownClient); // Set mongo Uri to connect - std::string uri = composeMongoUri(dbURI, host, rplSet, username, passwd, mechanism, authDb, dbSSL, dbDisableRetryWrites, timeout); + std::string uri = composeMongoUri(dbURI, passwd); #ifdef UNIT_TEST /* Basically, we are mocking all the DB pool with a single connection. The getMongoConnection() and mongoReleaseConnection() methods diff --git a/src/lib/mongoDriver/mongoConnectionPool.h b/src/lib/mongoDriver/mongoConnectionPool.h index 0dddc183ae..e5991eb55b 100644 --- a/src/lib/mongoDriver/mongoConnectionPool.h +++ b/src/lib/mongoDriver/mongoConnectionPool.h @@ -47,17 +47,9 @@ extern void mongoVersionGet(int* mayor, int* minor); extern int mongoConnectionPoolInit ( const char* dbURI, - const char* host, const char* db, - const char* rplSet, - const char* username, const char* passwd, - const char* mechanism, - const char* authDb, - bool dbSSL, - bool dbDisableRetryWrites, bool mtenant, - int64_t timeout, int writeConcern = 1, int poolSize = 10, bool semTimeStat = false diff --git a/test/unittests/main_UnitTest.cpp b/test/unittests/main_UnitTest.cpp index 3b7718b0c1..8e1b5c1d8f 100644 --- a/test/unittests/main_UnitTest.cpp +++ b/test/unittests/main_UnitTest.cpp @@ -81,15 +81,8 @@ unsigned long logLineMaxSize = 32 * 1024; bool logDeprecate = false; char dbURI[1024]; -char dbHost[256]; -char rplSet[64]; char dbName[64]; -char user[64]; char pwd[64]; -char authMech[64]; -char authDb[64]; -bool dbSSL; -int64_t dbTimeout; int dbPoolSize; int writeConcern; char gtest_filter[1024]; @@ -109,15 +102,8 @@ unsigned long fcMaxInterval = 0; PaArgument paArgs[] = { { "-dbURI", dbURI, "DB_URI", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, - { "-dbhost", dbHost, "DB_HOST", PaString, PaOpt, (int64_t) "localhost", PaNL, PaNL, "" }, - { "-rplSet", rplSet, "RPL_SET", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, - { "-dbuser", user, "DB_USER", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, { "-dbpwd", pwd, "DB_PASSWORD", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, - { "-dbAuthMech", authMech, "DB_AUTH_MECH", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, - { "-dbAuthDb", authDb, "DB_AUTH_DB", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, - { "-dbSSL", &dbSSL, "DB_AUTH_SSL", PaBool, PaOpt, false, false, true, "" }, { "-db", dbName, "DB", PaString, PaOpt, (int64_t) "orion", PaNL, PaNL, "" }, - { "-dbTimeout", &dbTimeout, "DB_TIMEOUT", PaInt64, PaOpt, 0, PaNL, PaNL, "" }, { "-dbPoolSize", &dbPoolSize, "DB_POOL_SIZE", PaInt, PaOpt, 10, 1, 10000, "" }, { "-writeConcern", &writeConcern, "WRITE_CONCERN", PaInt, PaOpt, 1, 0, 1, "" }, { "--gtest_filter=", gtest_filter, "", PaString, PaOpt, (int64_t) "", PaNL, PaNL, "" }, @@ -159,8 +145,8 @@ int main(int argC, char** argV) LM_M(("Init tests")); orionInit(exitFunction, orionUnitTestVersion, SemReadWriteOp, false, false, false, false, false); - // Note that disableRetryTries, multitenancy and mutex time stats are disabled for unit test mongo init - mongoInit(dbURI, dbHost, rplSet, dbName, user, pwd, authMech, authDb, dbSSL, false, false, dbTimeout, writeConcern, dbPoolSize, false); + // Note that multitenancy and mutex time stats are disabled for unit test mongo init + mongoInit(dbURI, dbName, pwd, false, writeConcern, dbPoolSize, false); alarmMgr.init(false); logSummaryInit(&lsPeriod); // setupDatabase(); FIXME #3775: pending on mongo unit test re-enabling