FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/server/ServerEnvVars.cpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
server
/
ServerEnvVars.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
120 lines (100 loc) · 3.52 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
server
/
ServerEnvVars.cpp
Copy path
File metadata and controls
120 lines (100 loc) · 3.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* ServerEnvVars.cpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
"
ServerEnvVars.hpp
"
#
include
<
boost/algorithm/string.hpp
>
#
include
<
core/system/Environment.hpp
>
#
include
<
core/system/Xdg.hpp
>
#
include
<
core/FileSerializer.hpp
>
#
include
<
core/Log.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
server
{
namespace
env_vars
{
Error
readEnvConfigFile
(
bool
emitInfoLog)
{
//
Look up config file location (log search path if enabled)
FilePath envConfPath = emitInfoLog ?
core::system::xdg::findSystemConfigFile
(
"
environment variables
"
,
"
env-vars
"
) :
core::system::xdg::systemConfigFile
(
"
env-vars
"
);
//
No work to do if we don't have a file specifying server environment variables
if
(!envConfPath.
exists
())
{
return
Success
();
}
//
Read all environment variable assignments from the file
core::system::Options env;
Error error = readCollectionFromFile<core::system::Options>(envConfPath, &env,
[=](
const
std::string& line, core::system::Option* pPair)
{
//
Ignore commented lines
if
(
boost::starts_with
(line,
"
#
"
))
return
ReadCollectionIgnoreLine;
//
Ignore lines that don't contain an environment variable assignment
size_t
pos = line.
find
(
'
=
'
);
if
(pos == std::string::npos)
return
ReadCollectionIgnoreLine;
pPair->
first
= line.
substr
(
0
, pos);
pPair->
second
= line.
substr
(pos+
1
);
return
ReadCollectionAddLine;
});
if
(error)
{
return
error;
}
//
Indicate where we read the logs from (for diagnostic purposes)
if
(emitInfoLog)
{
LOG_INFO_MESSAGE
(
"
Read server environment variables from
"
+
envConfPath.
getAbsolutePath
() +
"
(
"
+
safe_convert::numberToString
(env.
size
()) +
"
variables found)
"
);
}
//
Set each environment variable
for
(core::system::Option var: env)
{
if
(emitInfoLog)
{
LOG_INFO_MESSAGE
(
"
Setting server environment variable '
"
+
var.
first
+
"
' = '
"
+ var.
second
+
"
'
"
);
}
core::system::setenv
(var.
first
, var.
second
);
}
return
Success
();
}
//
Forwards any HTTP proxy variables from the current process into the given environment.
void
forwardHttpProxyVars
(core::system::Options *pEnvironment)
{
for
(
auto
&& proxyVar: {
"
HTTP_PROXY
"
,
"
HTTPS_PROXY
"
,
"
NO_PROXY
"
})
{
std::string val =
core::system::getenv
(proxyVar);
if
(!val.
empty
())
{
std::string oldVal =
core::system::getenv
(*pEnvironment, proxyVar);
if
(!oldVal.
empty
() && oldVal != val)
{
LOG_WARNING_MESSAGE
(
"
Overriding HTTP proxy setting
"
+
std::string
(proxyVar) +
"
: '
"
+ oldVal +
"
' => '
"
+ val +
"
'
"
);
}
core::system::setenv
(pEnvironment, proxyVar, val);
}
}
}
Error
initialize
()
{
return
readEnvConfigFile
(
true
/*
emit info log
*/
);
}
}
//
namespace env_vars
}
//
namespace server
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL