Skip to content

Commit

Permalink
Merge pull request #4527 from telefonicaid/remove/deprecated-db-relat…
Browse files Browse the repository at this point in the history
…ed-clis
  • Loading branch information
mapedraza authored Jun 5, 2024
2 parents a8dc0dd + 8a43ab0 commit 05a6158
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 257 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Fix: simplified GET /version operation, without including "libversions" field (add ?options=libVersions to get it)
- Fix: lighter operation to get databases list from MongoDB (#4517)
- Hardening: compile code using C++14 standard
- 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`)
4 changes: 2 additions & 2 deletions doc/manuals.jp/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

推奨されなくなった機能のリストと、廃止された機能のバージョンは次のとおりです :

* Orion 3.12.0 での CLI パラメータ (および関連する環境変数): `-dbhost``-rplSet``-dbTimeout``-dbuser``-dbAuthMech``-dbAuthDb``-dbSSL`、および `-dbDisableRetryWrites`。MongoDB URI を構築するために必要な情報が必要な場合は、[このセクション](#mapping-to-mongouri-from-old-cli-parameters) をチェックして、代わりに `dbURI` を使用してください
* Orion 3.12.0 での CLI パラメータ (および関連する環境変数): `-dbhost``-rplSet``-dbTimeout``-dbuser``-dbAuthMech``-dbAuthDb``-dbSSL`、および `-dbDisableRetryWrites`。MongoDB URI を構築するために必要な情報が必要な場合は、[このセクション](#mapping-to-mongouri-from-old-cli-parameters) をチェックして、代わりに `dbURI` を使用してください (Orion 4.0.0 で削除されました)
* Orion 3.10.0 での `geo:point`, `geo:line`, `geo:box` および `geo:polygon` 属性タイプ。代わりに `geo:json` を使用してください
* Orion 3.8.0 での `GET /v2` 操作。この操作はかなり役に立たず、実際には使用されません。
* Orion 3.1.0 のサブスクリプションでの初期通知 (`skipInitialNotification` オプションと共に)。(Orion 3.2.0 で削除)。初期通知の
Expand Down Expand Up @@ -103,13 +103,13 @@ Notes:

| **削除された機能** | **機能をサポートする Orion ラスト・バージョン** | **バージョンのリリース日** |
|--------------------------------------------------------------------------------------|-------------------------------------------------|----------------------------|
| CLI `-dbhost``-rplSet``-dbTimeout``-dbuser``-dbAuthMech``-dbAuthDb``-dbSSL`、および `-dbDisableRetryWrites` (および関連する環境変数) | まだ定義されていません | まだ定義されていません |
| `POST /v2/entities` オペレーションの `attributes` フィールド | まだ定義されていません | まだ定義されていません |
| `APPEND`, `UPDATE`, など。`POST /v2/op/update` でのアクション・タイプ | まだ定義されていません | まだ定義されていません |
| URI パラメータでの `dateCreated` および `dateModified` | まだ定義されていません | まだ定義されていません |
| エンティティのロケーションを指定する `location` メタデータ | まだ定義されていません | まだ定義されていません |
| `GET /v2` 操作 | まだ定義されていません | まだ定義されていません |
| `geo:point`, `geo:line`, `geo:box` および `geo:polygon` 属性タイプ | まだ定義されていません | まだ定義されていません |
| CLI `-dbhost``-rplSet``-dbTimeout``-dbuser``-dbAuthMech``-dbAuthDb``-dbSSL`、および `-dbDisableRetryWrites` (および関連する環境変数) | 3.12.0 | 2024年2月29日 |
| エンティティの場所を指定するための `location` メタデータ | 3.10.1 | 2023年6月12日 |
| NGSIv1 (関連する CLI パラメータ : `-strictNgsiv1Ids`, `-ngsiv1Autocast`) | 3.9.0 (*) | 2023年6月2日 |
| `/ngsi10` および `/ngsi9` URL プレフィックス | 3.7.0 (*) | 2022年5月26日 |
Expand Down
4 changes: 2 additions & 2 deletions doc/manuals/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 4.0.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.
Expand Down Expand Up @@ -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 |
Expand Down
27 changes: 2 additions & 25 deletions src/app/contextBroker/contextBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,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;
Expand All @@ -160,7 +153,6 @@ bool https;
bool mtenant;
char allowedOrigin[64];
int maxAge;
long dbTimeout;
long httpTimeout;
long mqttTimeout;
int dbPoolSize;
Expand Down Expand Up @@ -217,7 +209,6 @@ bool logDeprecate;
*/
#define PIDPATH _i "/tmp/contextBroker.pid"
#define IP_ALL _i "0.0.0.0"
#define LOCALHOST _i "localhost"
#define ONE_MONTH_PERIOD (3600 * 24 * 31)

#define FG_DESC "don't start as daemon"
Expand Down Expand Up @@ -298,19 +289,10 @@ PaArgument paArgs[] =
{ "-port", &port, "PORT", PaInt, PaOpt, 1026, 1, 65535, PORT_DESC },
{ "-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 },
{ "-dbURI", dbURI, "MONGO_URI", PaString, PaOpt, _i "mongodb://localhost:27017", PaNL, PaNL, DBURI_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 },
Expand Down Expand Up @@ -1142,11 +1124,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)"));
Expand Down Expand Up @@ -1230,7 +1207,7 @@ int main(int argC, char* argV[])
mqttMgr.init(mqttTimeout);
exprMgr.init();
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);

Expand Down
16 changes: 0 additions & 16 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions src/lib/mongoBackend/MongoGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
100 changes: 10 additions & 90 deletions src/lib/mongoDriver/mongoConnectionPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,100 +313,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()));
Expand All @@ -423,17 +351,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
Expand All @@ -452,7 +372,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
Expand Down
8 changes: 0 additions & 8 deletions src/lib/mongoDriver/mongoConnectionPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 05a6158

Please sign in to comment.