/Users/deen/code/yugabyte-db/src/yb/server/webserver_options.cc
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #include "yb/server/webserver_options.h" |
33 | | |
34 | | #include <string.h> |
35 | | |
36 | | #include <string> |
37 | | |
38 | | #include <gflags/gflags.h> |
39 | | |
40 | | #include "yb/util/env.h" |
41 | | #include "yb/util/env_util.h" |
42 | | #include "yb/util/flag_tags.h" |
43 | | #include "yb/util/path_util.h" |
44 | | |
45 | | using std::string; |
46 | | |
47 | | namespace yb { |
48 | | |
49 | | static std::string GetDefaultDocumentRoot(); |
50 | | |
51 | | } // namespace yb |
52 | | |
53 | | // Flags defining web server behavior. The class implementation should |
54 | | // not use these directly, but rather access them via WebserverOptions. |
55 | | // This makes it easier to instantiate web servers with different options |
56 | | // within a single unit test. |
57 | | DEFINE_string( |
58 | | webserver_interface, "", |
59 | | "Interface to start debug webserver on. If blank, webserver binds to first host IP" |
60 | | "present in the list of comma separated rpc_bind_addresses"); |
61 | | TAG_FLAG(webserver_interface, advanced); |
62 | | |
63 | | // We use an empty default value here because we can't call GetDefaultDocumentRoot from flag |
64 | | // initilization. Instead, we call GetDefaultDocumentRoot if we find that the flag is empty. |
65 | | DEFINE_string(webserver_doc_root, "", |
66 | | "Files under <webserver_doc_root> are accessible via the debug webserver. " |
67 | | "Defaults to $YB_HOME/www, or if $YB_HOME is not set, disables the document " |
68 | | "root"); |
69 | | TAG_FLAG(webserver_doc_root, advanced); |
70 | | |
71 | | DEFINE_bool(webserver_enable_doc_root, true, |
72 | | "If true, webserver may serve static files from the webserver_doc_root"); |
73 | | TAG_FLAG(webserver_enable_doc_root, advanced); |
74 | | |
75 | | DEFINE_string(webserver_certificate_file, "", |
76 | | "The location of the debug webserver's SSL certificate file, in .pem format. If " |
77 | | "empty, webserver SSL support is not enabled"); |
78 | | DEFINE_string(webserver_authentication_domain, "", |
79 | | "Domain used for debug webserver authentication"); |
80 | | DEFINE_string(webserver_password_file, "", |
81 | | "(Optional) Location of .htpasswd file containing user names and hashed passwords for" |
82 | | " debug webserver authentication"); |
83 | | |
84 | | DEFINE_int32(webserver_num_worker_threads, 50, |
85 | | "Maximum number of threads to start for handling web server requests"); |
86 | | TAG_FLAG(webserver_num_worker_threads, advanced); |
87 | | |
88 | | DEFINE_int32(webserver_port, 0, |
89 | | "Port to bind to for the web server"); |
90 | | TAG_FLAG(webserver_port, stable); |
91 | | |
92 | | namespace yb { |
93 | | |
94 | | // Returns $YB_HOME/www if set, else ROOT_DIR/www, where ROOT_DIR is computed based on executable |
95 | | // path. |
96 | 3.80k | static string GetDefaultDocumentRoot() { |
97 | 3.80k | return JoinPathSegments(yb::env_util::GetRootDir("www"), "www"); |
98 | 3.80k | } |
99 | | |
100 | | WebserverOptions::WebserverOptions() |
101 | | : bind_interface(FLAGS_webserver_interface), |
102 | | port(FLAGS_webserver_port), |
103 | | enable_doc_root(FLAGS_webserver_enable_doc_root), |
104 | | certificate_file(FLAGS_webserver_certificate_file), |
105 | | authentication_domain(FLAGS_webserver_authentication_domain), |
106 | | password_file(FLAGS_webserver_password_file), |
107 | 20.0k | num_worker_threads(FLAGS_webserver_num_worker_threads) { |
108 | 20.0k | doc_root = FLAGS_webserver_doc_root.empty() ? |
109 | 16.2k | GetDefaultDocumentRoot() : FLAGS_webserver_doc_root; |
110 | 20.0k | } |
111 | | |
112 | | } // namespace yb |