@@ -24,6 +24,12 @@ const DEFAULT_IDLE_LINGER_TIME: Duration = Duration::from_secs(60);
24
24
25
25
const ENV_SIDECAR_SELF_TELEMETRY : & str = "_DD_SIDECAR_SELF_TELEMETRY" ;
26
26
27
+ const ENV_SIDECAR_APPSEC_SHARED_LIB_PATH : & str = "_DD_SIDECAR_APPSEC_SHARED_LIB_PATH" ;
28
+ const ENV_SIDECAR_APPSEC_SOCKET_FILE_PATH : & str = "_DD_SIDECAR_APPSEC_SOCKET_FILE_PATH" ;
29
+ const ENV_SIDECAR_APPSEC_LOCK_FILE_PATH : & str = "_DD_SIDECAR_APPSEC_LOCK_FILE_PATH" ;
30
+ const ENV_SIDECAR_APPSEC_LOG_FILE_PATH : & str = "_DD_SIDECAR_APPSEC_LOG_FILE_PATH" ;
31
+ const ENV_SIDECAR_APPSEC_LOG_LEVEL : & str = "_DD_SIDECAR_APPSEC_LOG_LEVEL" ;
32
+
27
33
#[ derive( Debug , Copy , Clone ) ]
28
34
pub enum IpcMode {
29
35
Shared ,
@@ -78,22 +84,66 @@ pub struct Config {
78
84
pub self_telemetry : bool ,
79
85
pub library_dependencies : Vec < LibDependency > ,
80
86
pub child_env : HashMap < std:: ffi:: OsString , std:: ffi:: OsString > ,
87
+ pub appsec_config : Option < AppSecConfig > ,
88
+ }
89
+
90
+ #[ derive( Debug , Clone ) ]
91
+ pub struct AppSecConfig {
92
+ pub shared_lib_path : std:: ffi:: OsString ,
93
+ pub socket_file_path : std:: ffi:: OsString ,
94
+ pub lock_file_path : std:: ffi:: OsString ,
95
+ pub log_file_path : std:: ffi:: OsString ,
96
+ pub log_level : String ,
81
97
}
82
98
83
99
impl Config {
84
100
pub fn get ( ) -> Self {
85
101
FromEnv :: config ( )
86
102
}
87
103
88
- pub fn to_env ( & self ) -> HashMap < & ' static str , String > {
89
- HashMap :: from ( [
90
- ( ENV_SIDECAR_IPC_MODE , self . ipc_mode . to_string ( ) ) ,
91
- ( ENV_SIDECAR_LOG_METHOD , self . log_method . to_string ( ) ) ,
104
+ pub fn to_env ( & self ) -> HashMap < & ' static str , std :: ffi :: OsString > {
105
+ let mut res = HashMap :: from ( [
106
+ ( ENV_SIDECAR_IPC_MODE , self . ipc_mode . to_string ( ) . into ( ) ) ,
107
+ ( ENV_SIDECAR_LOG_METHOD , self . log_method . to_string ( ) . into ( ) ) ,
92
108
(
93
109
ENV_IDLE_LINGER_TIME_SECS ,
94
- self . idle_linger_time . as_secs ( ) . to_string ( ) ,
110
+ self . idle_linger_time . as_secs ( ) . to_string ( ) . into ( ) ,
111
+ ) ,
112
+ (
113
+ ENV_SIDECAR_SELF_TELEMETRY ,
114
+ self . self_telemetry . to_string ( ) . into ( ) ,
115
+ ) ,
116
+ ] ) ;
117
+ if self . appsec_config . is_some ( ) {
118
+ res. extend ( self . appsec_config . as_ref ( ) . unwrap ( ) . to_env ( ) ) ;
119
+ }
120
+ res
121
+ }
122
+ }
123
+
124
+ impl AppSecConfig {
125
+ pub fn to_env ( & self ) -> HashMap < & ' static str , std:: ffi:: OsString > {
126
+ HashMap :: from ( [
127
+ (
128
+ ENV_SIDECAR_APPSEC_SHARED_LIB_PATH ,
129
+ self . shared_lib_path . to_owned ( ) ,
130
+ ) ,
131
+ (
132
+ ENV_SIDECAR_APPSEC_SOCKET_FILE_PATH ,
133
+ self . socket_file_path . to_owned ( ) ,
134
+ ) ,
135
+ (
136
+ ENV_SIDECAR_APPSEC_LOCK_FILE_PATH ,
137
+ self . lock_file_path . to_owned ( ) ,
138
+ ) ,
139
+ (
140
+ ENV_SIDECAR_APPSEC_LOG_FILE_PATH ,
141
+ self . log_file_path . to_owned ( ) ,
142
+ ) ,
143
+ (
144
+ ENV_SIDECAR_APPSEC_LOG_LEVEL ,
145
+ self . log_level . to_owned ( ) . into ( ) ,
95
146
) ,
96
- ( ENV_SIDECAR_SELF_TELEMETRY , self . self_telemetry . to_string ( ) ) ,
97
147
] )
98
148
}
99
149
}
@@ -159,8 +209,25 @@ impl FromEnv {
159
209
self_telemetry : Self :: self_telemetry ( ) ,
160
210
library_dependencies : vec ! [ ] ,
161
211
child_env : std:: env:: vars_os ( ) . collect ( ) ,
212
+ appsec_config : Self :: appsec_config ( ) ,
162
213
}
163
214
}
215
+
216
+ pub fn appsec_config ( ) -> Option < AppSecConfig > {
217
+ let shared_lib_path = std:: env:: var_os ( ENV_SIDECAR_APPSEC_SHARED_LIB_PATH ) ?;
218
+ let socket_file_path = std:: env:: var_os ( ENV_SIDECAR_APPSEC_SOCKET_FILE_PATH ) ?;
219
+ let lock_file_path = std:: env:: var_os ( ENV_SIDECAR_APPSEC_LOCK_FILE_PATH ) ?;
220
+ let log_file_path = std:: env:: var_os ( ENV_SIDECAR_APPSEC_LOG_FILE_PATH ) ?;
221
+ let log_level = std:: env:: var ( ENV_SIDECAR_APPSEC_LOG_LEVEL ) . ok ( ) ?;
222
+
223
+ Some ( AppSecConfig {
224
+ shared_lib_path,
225
+ socket_file_path,
226
+ lock_file_path,
227
+ log_file_path,
228
+ log_level,
229
+ } )
230
+ }
164
231
}
165
232
166
233
pub fn get_product_endpoint ( subdomain : & str , endpoint : & Endpoint ) -> Endpoint {
0 commit comments