diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2019-02-12 22:14:59 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2019-02-14 23:19:17 +0000 |
commit | 9d402c82594ad179d2b177027aec462422a4b4fa (patch) | |
tree | 87712d5ea54c57701141ed0fe842bffc0081323a /src | |
parent | 814b1f8237db9ecb27dd0ffa96f11edd58bac73e (diff) | |
download | mongo-9d402c82594ad179d2b177027aec462422a4b4fa.tar.gz |
SERVER-39501 Migrate windows options to IDL
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/SConscript | 11 | ||||
-rw-r--r-- | src/mongo/db/mongod_options.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.cpp | 49 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.h | 17 | ||||
-rw-r--r-- | src/mongo/db/windows_options.idl | 76 | ||||
-rw-r--r-- | src/mongo/s/mongos_options.cpp | 17 | ||||
-rw-r--r-- | src/mongo/util/cmdline_utils/SConscript | 3 | ||||
-rw-r--r-- | src/mongo/util/cmdline_utils/censor_cmdline.cpp | 9 | ||||
-rw-r--r-- | src/mongo/util/cmdline_utils/censor_cmdline_test.cpp | 188 |
10 files changed, 98 insertions, 286 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 3b36d14efdc..bdbf0e98d6f 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -404,6 +404,7 @@ mongod = env.Program( 'db/update/update_driver', 'db/update_index_data', 'db/views/views_mongod', + 'db/windows_options' if env.TargetOSIs('windows') else [], 'executor/network_interface_factory', 'mongod_options_init', 'rpc/rpc', @@ -497,6 +498,7 @@ mongos = env.Program( 'db/server_options', 'db/startup_warnings_common', 'db/stats/counters', + 'db/windows_options' if env.TargetOSIs('windows') else [], 's/commands/cluster_commands', 's/commands/shared_cluster_commands', 's/committed_optime_metadata_hook', diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 86c80a6ab81..a15037350be 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -408,6 +408,17 @@ env.Library( ], ) +if env.TargetOSIs('windows'): + env.Library( + target='windows_options', + source=[ + env.Idlc('windows_options.idl')[0], + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/util/options_parser/options_parser', + ], + ) + env.Clone().InjectModule("enterprise").Library( target="server_options_servers", source=[ diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 6ef9cd82991..dc2df163205 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -63,15 +63,6 @@ Status addMongodOptions(moe::OptionSection* options) { return ret; } -#if defined(_WIN32) - moe::OptionSection windows_scm_options("Windows Service Control Manager options"); - - ret = addWindowsServerOptions(&windows_scm_options); - if (!ret.isOK()) { - return ret; - } -#endif - moe::OptionSection rs_options("Replica set options"); moe::OptionSection replication_options("Replication options"); moe::OptionSection sharding_options("Sharding options"); @@ -355,9 +346,6 @@ Status addMongodOptions(moe::OptionSection* options) { options->addSection(general_options).transitional_ignore(); -#if defined(_WIN32) - options->addSection(windows_scm_options).transitional_ignore(); -#endif options->addSection(replication_options).transitional_ignore(); options->addSection(rs_options).transitional_ignore(); options->addSection(sharding_options).transitional_ignore(); diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index 1e98b3c5299..4b836399e3a 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -63,6 +63,8 @@ using std::endl; using std::string; +namespace moe = ::mongo::optionenvironment; + namespace mongo { Status addGeneralServerOptions(moe::OptionSection* options) { @@ -298,53 +300,6 @@ Status addGeneralServerOptions(moe::OptionSection* options) { return Status::OK(); } -Status addWindowsServerOptions(moe::OptionSection* options) { - options->addOptionChaining("install", "install", moe::Switch, "install Windows service") - .setSources(moe::SourceAllLegacy); - - options->addOptionChaining("remove", "remove", moe::Switch, "remove Windows service") - .setSources(moe::SourceAllLegacy); - - options - ->addOptionChaining( - "reinstall", - "reinstall", - moe::Switch, - "reinstall Windows service (equivalent to --remove followed by --install)") - .setSources(moe::SourceAllLegacy); - - options->addOptionChaining("processManagement.windowsService.serviceName", - "serviceName", - moe::String, - "Windows service name"); - - options->addOptionChaining("processManagement.windowsService.displayName", - "serviceDisplayName", - moe::String, - "Windows service display name"); - - options->addOptionChaining("processManagement.windowsService.description", - "serviceDescription", - moe::String, - "Windows service description"); - - options->addOptionChaining("processManagement.windowsService.serviceUser", - "serviceUser", - moe::String, - "account for service execution"); - - options->addOptionChaining("processManagement.windowsService.servicePassword", - "servicePassword", - moe::String, - "password used to authenticate serviceUser"); - - options->addOptionChaining("service", "service", moe::Switch, "start mongodb service") - .hidden() - .setSources(moe::SourceAllLegacy); - - return Status::OK(); -} - namespace { // Helpers for option storage Status setupBinaryName(const std::vector<std::string>& argv) { diff --git a/src/mongo/db/server_options_server_helpers.h b/src/mongo/db/server_options_server_helpers.h index 03724ca7230..b6587c5379a 100644 --- a/src/mongo/db/server_options_server_helpers.h +++ b/src/mongo/db/server_options_server_helpers.h @@ -35,26 +35,17 @@ namespace mongo { -namespace optionenvironment { -class OptionSection; -class Environment; -} // namespace optionenvironment - -namespace moe = mongo::optionenvironment; - /** * General server options for most standalone applications. Includes addBaseServerOptions. */ -Status addGeneralServerOptions(moe::OptionSection* options); - -Status addWindowsServerOptions(moe::OptionSection* options); +Status addGeneralServerOptions(optionenvironment::OptionSection* options); /** * Handle custom validation of server options that can not currently be done by using * Constraints in the Environment. See the "validate" function in the Environment class for * more details. */ -Status validateServerOptions(const moe::Environment& params); +Status validateServerOptions(const optionenvironment::Environment& params); /** * Canonicalize server options for the given environment. @@ -62,7 +53,7 @@ Status validateServerOptions(const moe::Environment& params); * For example, the options "objcheck", "noobjcheck", and "net.wireObjectCheck" should all be * merged into "net.wireObjectCheck". */ -Status canonicalizeServerOptions(moe::Environment* params); +Status canonicalizeServerOptions(optionenvironment::Environment* params); /** * Sets up the global server state necessary to be able to store the server options, based on how @@ -78,7 +69,7 @@ Status setupServerOptions(const std::vector<std::string>& args); * * For example, sets the serverGlobalParams.port variable based on the net.port config parameter. */ -Status storeServerOptions(const moe::Environment& params); +Status storeServerOptions(const optionenvironment::Environment& params); void printCommandLineOpts(); diff --git a/src/mongo/db/windows_options.idl b/src/mongo/db/windows_options.idl new file mode 100644 index 00000000000..ebdc78042d1 --- /dev/null +++ b/src/mongo/db/windows_options.idl @@ -0,0 +1,76 @@ + +# Copyright (C) 2019-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. +# + +global: + cpp_namespace: "mongo" + configs: + section: 'Windows Service Control Manager options' + source: [ yaml, cli, ini ] + +configs: + install: + description: 'Install Windows service' + arg_vartype: Switch + source: [ cli, ini ] + remove: + description: 'Remove Windows service' + arg_vartype: Switch + source: [ cli, ini ] + reinstall: + description: 'Reinstall Windows service (equivalent to --remove followed by --install)' + arg_vartype: Switch + source: [ cli, ini ] + service: + description: 'Start mongodb service' + arg_vartype: Switch + source: [ cli, ini ] + hidden: true + + 'processManagement.windowsService.serviceName': + description: 'Windows service name' + short_name: serviceName + arg_vartype: String + 'processManagement.windowsService.displayName': + description: 'Windows service display name' + short_name: serviceDisplayName + arg_vartype: String + 'processManagement.windowsService.description': + description: 'Windows service description' + short_name: serviceDescription + arg_vartype: String + 'processManagement.windowsService.serviceUser': + description: 'Account for service execution' + short_name: serviceUser + arg_vartype: String + 'processManagement.windowsService.servicePassword': + description: 'Password used to authenticate serviceUser' + short_name: servicePassword + arg_vartype: String + redact: true + diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index 3318c5fc42b..354d8f82bac 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -63,22 +63,7 @@ Status addMongosOptions(moe::OptionSection* options) { return ret; } -#if defined(_WIN32) - moe::OptionSection windows_scm_options("Windows Service Control Manager options"); - - ret = addWindowsServerOptions(&windows_scm_options); - if (!ret.isOK()) { - return ret; - } -#endif - - options->addSection(general_options).transitional_ignore(); - -#if defined(_WIN32) - options->addSection(windows_scm_options).transitional_ignore(); -#endif - - return Status::OK(); + return options->addSection(general_options); } void printMongosHelp(const moe::OptionSection& options) { diff --git a/src/mongo/util/cmdline_utils/SConscript b/src/mongo/util/cmdline_utils/SConscript index 53ecab4b9aa..1fbe0abb7e7 100644 --- a/src/mongo/util/cmdline_utils/SConscript +++ b/src/mongo/util/cmdline_utils/SConscript @@ -14,6 +14,3 @@ env.Library( '$BUILD_DIR/mongo/util/options_parser/options_parser', ]) -env.CppUnitTest('censor_cmdline_test', - 'censor_cmdline_test.cpp', - LIBDEPS=['cmdline_utils', '$BUILD_DIR/mongo/unittest/unittest']) diff --git a/src/mongo/util/cmdline_utils/censor_cmdline.cpp b/src/mongo/util/cmdline_utils/censor_cmdline.cpp index 63220bebcdf..50c17bcae18 100644 --- a/src/mongo/util/cmdline_utils/censor_cmdline.cpp +++ b/src/mongo/util/cmdline_utils/censor_cmdline.cpp @@ -46,13 +46,8 @@ struct InsensitiveCompare { } }; -std::set<std::string, InsensitiveCompare> gRedactedDottedNames = { - // Legacy redacted names pending conversion. - "processManagement.windowsService.servicePassword", -}; -std::set<std::string, InsensitiveCompare> gRedactedSingleNames = { - "servicePassword", -}; +std::set<std::string, InsensitiveCompare> gRedactedDottedNames; +std::set<std::string, InsensitiveCompare> gRedactedSingleNames; std::set<char> gRedactedCharacterNames; bool gGatherOptionsDone = false; diff --git a/src/mongo/util/cmdline_utils/censor_cmdline_test.cpp b/src/mongo/util/cmdline_utils/censor_cmdline_test.cpp deleted file mode 100644 index 76d3e5317fe..00000000000 --- a/src/mongo/util/cmdline_utils/censor_cmdline_test.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include <string> -#include <vector> - -#include "mongo/db/jsobj.h" -#include "mongo/unittest/unittest.h" -#include "mongo/util/cmdline_utils/censor_cmdline.h" -#include "mongo/util/cmdline_utils/censor_cmdline_test.h" -#include "mongo/util/options_parser/environment.h" - -namespace moe = mongo::optionenvironment; - -namespace mongo { -namespace { - -TEST(ArgvVectorCensorTests, NothingCensored) { - const std::vector<std::string> argv({"first", - "second", - "servicePassword=KEEP", - "--servicePassword-", - "KEEP", - "--servicePasswordFake=KEEP"}); - test::censoringArgv(argv, argv); - test::censoringVector(argv, argv); -} - -TEST(ArgvCensorTests, SomeStuffCensoredDoubleHyphen) { - const std::vector<std::string> argv({"first", - "second", - "--servicePassword=bad news", - "--servicePassword-", - "KEEP", - "--servicePassword", - "get out of dodge"}); - - const std::vector<std::string> expected({"first", - "second", - "--servicePassword=xxxxxxxx", - "--servicePassword-", - "KEEP", - "--servicePassword", - "xxxxxxxxxxxxxxxx"}); - - ASSERT_EQ(expected.size(), argv.size()); - test::censoringArgv(expected, argv); -} - -TEST(ArgvCensorTests, SomeStuffCensoredSingleHyphen) { - const std::vector<std::string> argv({"first", - "second", - "-servicePassword=bad news", - "-servicePassword-", - "KEEP", - "-servicePassword", - "get out of dodge"}); - - const std::vector<std::string> expected({"first", - "second", - "-servicePassword=xxxxxxxx", - "-servicePassword-", - "KEEP", - "-servicePassword", - "xxxxxxxxxxxxxxxx"}); - - ASSERT_EQ(expected.size(), argv.size()); - test::censoringArgv(expected, argv); -} - -TEST(VectorCensorTests, SomeStuffCensoredDoubleHyphen) { - const std::vector<std::string> argv({"first", - "second", - "--servicePassword=bad news", - "--servicePassword-", - "KEEP", - "--servicePassword", - "get out of dodge"}); - - const std::vector<std::string> expected({"first", - "second", - "--servicePassword=<password>", - "--servicePassword-", - "KEEP", - "--servicePassword", - "<password>"}); - - ASSERT_EQ(expected.size(), argv.size()); - test::censoringVector(expected, argv); -} - -TEST(VectorCensorTests, SomeStuffCensoredSingleHyphen) { - const std::vector<std::string> argv({"first", - "second", - "-servicePassword=bad news", - "-servicePassword-", - "KEEP", - "-servicePassword", - "get out of dodge"}); - - const std::vector<std::string> expected({"first", - "second", - "-servicePassword=<password>", - "-servicePassword-", - "KEEP", - "-servicePassword", - "<password>"}); - - ASSERT_EQ(expected.size(), argv.size()); - test::censoringVector(expected, argv); -} - -TEST(BSONObjCensorTests, Strings) { - BSONObj obj = BSON("firstarg" - << "not a password" - << "middlearg" - << "also not a password" - << "processManagement.windowsService.servicePassword" - << "this password should also be censored" - << "lastarg" - << false); - - BSONObj res = BSON("firstarg" - << "not a password" - << "middlearg" - << "also not a password" - << "processManagement.windowsService.servicePassword" - << "<password>" - << "lastarg" - << false); - - cmdline_utils::censorBSONObj(&obj); - ASSERT_BSONOBJ_EQ(res, obj); -} - -TEST(BSONObjCensorTests, Arrays) { - BSONObj obj = BSON("firstarg" - << "not a password" - << "middlearg" - << "also not a password" - << "processManagement.windowsService.servicePassword" - << BSON_ARRAY("first censored password" - << "next censored password") - << "lastarg" - << false); - - BSONObj res = BSON("firstarg" - << "not a password" - << "middlearg" - << "also not a password" - << "processManagement.windowsService.servicePassword" - << BSON_ARRAY("<password>" - << "<password>") - << "lastarg" - << false); - - cmdline_utils::censorBSONObj(&obj); - ASSERT_BSONOBJ_EQ(res, obj); -} - -} // namespace -} // namespace mongo |