MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
options.h
1/* Copyright 2014 10gen Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#pragma once
17
18#include <string>
19
20#include "mongo/client/export_macros.h"
21#include "mongo/logger/log_domain.h"
22#include "mongo/logger/message_log_domain.h"
23#include "mongo/stdx/functional.h"
24
25namespace mongo {
26namespace client {
27
32class MONGO_CLIENT_API Options {
33public:
34 // Defaults for non-boolean or std::string parameters that are not defaulted to the
35 // empty string. These are useful in case you which to set a parameter to a scale
36 // factor or mutation of the default.
37 static const unsigned int kDefaultAutoShutdownGracePeriodMillis = 0;
38 static const int kDefaultDefaultLocalThresholdMillis = 15;
39
40 // Helpful typedefs for logging-related options
41 typedef std::auto_ptr<logger::MessageLogDomain::EventAppender> LogAppenderPtr;
42 typedef stdx::function<LogAppenderPtr()> LogAppenderFactory;
43
47 static const Options& current();
48
53
55 enum DefaultPorts { kDbServer = 27017, kShardServer = 27018, kConfigServer = 27019 };
56
58 enum SSLModes {
59
62
68 // kSSLPreferred,
69
71 kSSLRequired
72 };
73
75 enum TLSProtocol { kTLS1_0, kTLS1_1, kTLS1_2 };
76
77 //
78 // Startup and shutdown
79 //
80
91 Options& setCallShutdownAtExit(bool value = true);
92 bool callShutdownAtExit() const;
93
100 unsigned int autoShutdownGracePeriodMillis() const;
101
102
103 //
104 // Replication
105 //
106
112 int defaultLocalThresholdMillis() const;
113
114
115 //
116 // SSL
117 //
118 // NOTE: None of the below settings have any effect unless the driver
119 // was compiled with SSL support.
120 //
121 // Glossary:
122 // - CA File: certificate authority certificate file
123 // - PEM Key File: SSL certificate file in PEM format
124 // - CRL: certificate revocation list
125 // - FIPS Mode: OpenSSL crypto library FIPS 140-2 mode processing
126 //
127
132 Options& setSSLMode(SSLModes sslMode = kSSLRequired);
133 SSLModes SSLMode() const;
134
136 inline bool SSLEnabled() const {
137 return SSLMode() != kSSLDisabled;
138 }
139
144 Options& setFIPSMode(bool value = true);
145 const bool FIPSMode() const;
146
152 Options& setSSLDisabledTLSProtocols(const std::vector<TLSProtocol>& protocols);
153 const std::vector<TLSProtocol>& SSLDisabledTLSProtocols() const;
154
159 Options& setSSLCAFile(const std::string& fileName);
160 const std::string& SSLCAFile() const;
161
166 Options& setSSLPEMKeyFile(const std::string& fileName);
167 const std::string& SSLPEMKeyFile() const;
168
173 Options& setSSLPEMKeyPassword(const std::string& password);
174 const std::string& SSLPEMKeyPassword() const;
175
180 Options& setSSLCRLFile(const std::string& fileName);
181 const std::string& SSLCRLFile() const;
182
188 const bool SSLAllowInvalidCertificates() const;
189
195 const bool SSLAllowInvalidHostnames() const;
196
201 Options& setSSLCipherConfig(const std::string& config);
202 const std::string& SSLCipherConfig() const;
203
204 //
205 // Logging
206 //
207
212 Options& setLogAppenderFactory(const LogAppenderFactory& factory);
213 const LogAppenderFactory& logAppenderFactory() const;
214
221 logger::LogSeverity minLoggedSeverity() const;
222
223 //
224 // Networking
225 //
226
232 bool IPv6Enabled() const;
233
234 //
235 // Misc
236 //
237
242 Options& setValidateObjects(bool value = true);
243 bool validateObjects() const;
244
245private:
246 bool _callShutdownAtExit;
247 unsigned int _autoShutdownGracePeriodMillis;
248 SSLModes _sslMode;
249 bool _useFIPSMode;
250 std::vector<TLSProtocol> _sslDisabledTLSProtocols;
251 std::string _sslCAFile;
252 std::string _sslPEMKeyFile;
253 std::string _sslPEMKeyPassword;
254 std::string _sslCRLFile;
255 bool _sslAllowInvalidCertificates;
256 bool _sslAllowInvalidHostnames;
257 std::string _sslCipherConfig;
258 int _defaultLocalThresholdMillis;
259 LogAppenderFactory _appenderFactory;
260 logger::LogSeverity _minLoggedSeverity;
261 bool _IPv6Enabled;
262 bool _validateObjects;
263};
264
265} // namespace client
266} // namespace mongo
The Options structure is passed to mongo::client::initialize to configure various properties and conf...
Definition options.h:32
Options & setSSLAllowInvalidCertificates(bool value=true)
When set true, SSL certificate validation is disabled.
Options & setSSLMode(SSLModes sslMode=kSSLRequired)
If set to kSSLRequired, the driver will use SSL when connecting.
Options & setValidateObjects(bool value=true)
Configure whether BSON objects returned from the server should be validated.
Options & setSSLDisabledTLSProtocols(const std::vector< TLSProtocol > &protocols)
Allow disabling particular TLS protocols.
static const Options & current()
Obtains the currently configured options for the driver.
Options & setDefaultLocalThresholdMillis(int millis)
Set the default threshold to consider a node local.
SSLModes
The possible modes for SSL support in an SSL enabled build of the driver.
Definition options.h:58
@ kSSLDisabled
Don't attempt to make SSL connections, or require SSL support of the server.
Definition options.h:61
Options & setSSLCipherConfig(const std::string &config)
Override the default OpenSSL cipher configuration.
DefaultPorts
The default ports where different mongodb servers tend to run.
Definition options.h:55
Options & setCallShutdownAtExit(bool value=true)
If true, the driver will automatically schedule a client::shutdown via 'std::atexit'.
TLSProtocol
The TLS protocols.
Definition options.h:75
Options & setSSLCRLFile(const std::string &fileName)
Configure the SSL CRL file to use.
Options & setSSLPEMKeyPassword(const std::string &password)
Configure the SSL PEM key password.
Options & setSSLPEMKeyFile(const std::string &fileName)
Configure the SSL PEM key file to use.
Options & setAutoShutdownGracePeriodMillis(unsigned int millis)
The grace period used when calling client::shutdown from atexit.
Options & setLogAppenderFactory(const LogAppenderFactory &factory)
Provide a factory for a log appender to configure logging.
Options()
Constructs a default options object with default values for all options.
Options & setSSLCAFile(const std::string &fileName)
Configure the SSL CA file to use.
Options & setIPv6Enabled(bool state)
Enable support for the IPv6 protocol family.
Options & setFIPSMode(bool value=true)
Sets whether to operate in FIPS mode.
Options & setMinLoggedSeverity(logger::LogSeverity level)
Specify the minimum severity of messages that will be logged, if logging is enabled.
bool SSLEnabled() const
A convenience: returns true if SSL is not disabled (preferred or required).
Definition options.h:136
Options & setSSLAllowInvalidHostnames(bool value=true)
When set true, SSL hostname validation is disabled.
Representation of the severity / priority of a log message.
Definition log_severity.h:33
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20