1 // Copyright 2023 gRPC authors.
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 // Automatically generated by tools/codegen/core/gen_config_vars.py
17 //
18 
19 #include <grpc/support/port_platform.h>
20 
21 #include "src/core/lib/config/config_vars.h"
22 
23 #include <algorithm>
24 #include <vector>
25 
26 #include "absl/flags/flag.h"
27 #include "absl/strings/escaping.h"
28 #include "absl/strings/str_cat.h"
29 
30 #include "src/core/lib/config/load_config.h"
31 
32 #ifndef GPR_DEFAULT_LOG_VERBOSITY_STRING
33 #define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR"
34 #endif  // !GPR_DEFAULT_LOG_VERBOSITY_STRING
35 
36 #ifdef GRPC_ENABLE_FORK_SUPPORT
37 #define GRPC_ENABLE_FORK_SUPPORT_DEFAULT true
38 #else
39 #define GRPC_ENABLE_FORK_SUPPORT_DEFAULT false
40 #endif  // GRPC_ENABLE_FORK_SUPPORT
41 
42 ABSL_FLAG(std::vector<std::string>, grpc_experiments, {},
43           "A comma separated list of currently active experiments. Experiments "
44           "may be prefixed with a '-' to disable them.");
45 ABSL_FLAG(absl::optional<int32_t>, grpc_client_channel_backup_poll_interval_ms,
46           {},
47           "Declares the interval in ms between two backup polls on client "
48           "channels. These polls are run in the timer thread so that gRPC can "
49           "process connection failures while there is no active polling "
50           "thread. They help reconnect disconnected client channels (mostly "
51           "due to idleness), so that the next RPC on this channel won't fail. "
52           "Set to 0 to turn off the backup polls.");
53 ABSL_FLAG(absl::optional<std::string>, grpc_dns_resolver, {},
54           "Declares which DNS resolver to use. The default is ares if gRPC is "
55           "built with c-ares support. Otherwise, the value of this environment "
56           "variable is ignored.");
57 ABSL_FLAG(std::vector<std::string>, grpc_trace, {},
58           "A comma separated list of tracers that provide additional insight "
59           "into how gRPC C core is processing requests via debug logs.");
60 ABSL_FLAG(absl::optional<std::string>, grpc_verbosity, {},
61           "Default gRPC logging verbosity");
62 ABSL_FLAG(absl::optional<std::string>, grpc_stacktrace_minloglevel, {},
63           "Messages logged at the same or higher level than this will print "
64           "stacktrace");
65 ABSL_FLAG(absl::optional<bool>, grpc_enable_fork_support, {},
66           "Enable fork support");
67 ABSL_FLAG(absl::optional<std::string>, grpc_poll_strategy, {},
68           "Declares which polling engines to try when starting gRPC. This is a "
69           "comma-separated list of engines, which are tried in priority order "
70           "first -> last.");
71 ABSL_FLAG(absl::optional<bool>, grpc_abort_on_leaks, {},
72           "A debugging aid to cause a call to abort() when gRPC objects are "
73           "leaked past grpc_shutdown()");
74 ABSL_FLAG(absl::optional<std::string>, grpc_system_ssl_roots_dir, {},
75           "Custom directory to SSL Roots");
76 ABSL_FLAG(absl::optional<std::string>, grpc_default_ssl_roots_file_path, {},
77           "Path to the default SSL roots file.");
78 ABSL_FLAG(absl::optional<bool>, grpc_not_use_system_ssl_roots, {},
79           "Disable loading system root certificates.");
80 ABSL_FLAG(absl::optional<std::string>, grpc_ssl_cipher_suites, {},
81           "A colon separated list of cipher suites to use with OpenSSL");
82 
83 namespace grpc_core {
84 
ConfigVars(const Overrides & overrides)85 ConfigVars::ConfigVars(const Overrides& overrides)
86     : client_channel_backup_poll_interval_ms_(
87           LoadConfig(FLAGS_grpc_client_channel_backup_poll_interval_ms,
88                      "GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS",
89                      overrides.client_channel_backup_poll_interval_ms, 5000)),
90       enable_fork_support_(LoadConfig(
91           FLAGS_grpc_enable_fork_support, "GRPC_ENABLE_FORK_SUPPORT",
92           overrides.enable_fork_support, GRPC_ENABLE_FORK_SUPPORT_DEFAULT)),
93       abort_on_leaks_(LoadConfig(FLAGS_grpc_abort_on_leaks,
94                                  "GRPC_ABORT_ON_LEAKS",
95                                  overrides.abort_on_leaks, false)),
96       not_use_system_ssl_roots_(LoadConfig(
97           FLAGS_grpc_not_use_system_ssl_roots, "GRPC_NOT_USE_SYSTEM_SSL_ROOTS",
98           overrides.not_use_system_ssl_roots, false)),
99       dns_resolver_(LoadConfig(FLAGS_grpc_dns_resolver, "GRPC_DNS_RESOLVER",
100                                overrides.dns_resolver, "")),
101       verbosity_(LoadConfig(FLAGS_grpc_verbosity, "GRPC_VERBOSITY",
102                             overrides.verbosity,
103                             GPR_DEFAULT_LOG_VERBOSITY_STRING)),
104       stacktrace_minloglevel_(LoadConfig(FLAGS_grpc_stacktrace_minloglevel,
105                                          "GRPC_STACKTRACE_MINLOGLEVEL",
106                                          overrides.stacktrace_minloglevel, "")),
107       poll_strategy_(LoadConfig(FLAGS_grpc_poll_strategy, "GRPC_POLL_STRATEGY",
108                                 overrides.poll_strategy, "all")),
109       ssl_cipher_suites_(LoadConfig(
110           FLAGS_grpc_ssl_cipher_suites, "GRPC_SSL_CIPHER_SUITES",
111           overrides.ssl_cipher_suites,
112           "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_"
113           "SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
114           "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384")),
115       experiments_(LoadConfig(FLAGS_grpc_experiments, "GRPC_EXPERIMENTS",
116                               overrides.experiments, "")),
117       trace_(LoadConfig(FLAGS_grpc_trace, "GRPC_TRACE", overrides.trace, "")),
118       override_system_ssl_roots_dir_(overrides.system_ssl_roots_dir),
119       override_default_ssl_roots_file_path_(
120           overrides.default_ssl_roots_file_path) {}
121 
SystemSslRootsDir() const122 std::string ConfigVars::SystemSslRootsDir() const {
123   return LoadConfig(FLAGS_grpc_system_ssl_roots_dir,
124                     "GRPC_SYSTEM_SSL_ROOTS_DIR", override_system_ssl_roots_dir_,
125                     "");
126 }
127 
DefaultSslRootsFilePath() const128 std::string ConfigVars::DefaultSslRootsFilePath() const {
129   return LoadConfig(FLAGS_grpc_default_ssl_roots_file_path,
130                     "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH",
131                     override_default_ssl_roots_file_path_, "");
132 }
133 
ToString() const134 std::string ConfigVars::ToString() const {
135   return absl::StrCat(
136       "experiments: ", "\"", absl::CEscape(Experiments()), "\"",
137       ", client_channel_backup_poll_interval_ms: ",
138       ClientChannelBackupPollIntervalMs(), ", dns_resolver: ", "\"",
139       absl::CEscape(DnsResolver()), "\"", ", trace: ", "\"",
140       absl::CEscape(Trace()), "\"", ", verbosity: ", "\"",
141       absl::CEscape(Verbosity()), "\"", ", stacktrace_minloglevel: ", "\"",
142       absl::CEscape(StacktraceMinloglevel()), "\"",
143       ", enable_fork_support: ", EnableForkSupport() ? "true" : "false",
144       ", poll_strategy: ", "\"", absl::CEscape(PollStrategy()), "\"",
145       ", abort_on_leaks: ", AbortOnLeaks() ? "true" : "false",
146       ", system_ssl_roots_dir: ", "\"", absl::CEscape(SystemSslRootsDir()),
147       "\"", ", default_ssl_roots_file_path: ", "\"",
148       absl::CEscape(DefaultSslRootsFilePath()), "\"",
149       ", not_use_system_ssl_roots: ", NotUseSystemSslRoots() ? "true" : "false",
150       ", ssl_cipher_suites: ", "\"", absl::CEscape(SslCipherSuites()), "\"");
151 }
152 
153 }  // namespace grpc_core
154