File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -168,11 +168,21 @@ where
168
168
S : Clone + clap:: Args + StorageOpt ,
169
169
{
170
170
/// The location of TLS Cert file
171
- #[ arg( long, env = "P_TLS_CERT_PATH" , value_name = "path" ) ]
171
+ #[ arg(
172
+ long,
173
+ env = "P_TLS_CERT_PATH" ,
174
+ value_name = "path" ,
175
+ value_parser = validation:: file_path
176
+ ) ]
172
177
pub tls_cert_path : Option < PathBuf > ,
173
178
174
179
/// The location of TLS Private Key file
175
- #[ arg( long, env = "P_TLS_KEY_PATH" , value_name = "path" ) ]
180
+ #[ arg(
181
+ long,
182
+ env = "P_TLS_KEY_PATH" ,
183
+ value_name = "path" ,
184
+ value_parser = validation:: file_path
185
+ ) ]
176
186
pub tls_key_path : Option < PathBuf > ,
177
187
178
188
/// The address on which the http server will listen.
@@ -251,3 +261,21 @@ where
251
261
"http" . to_string ( )
252
262
}
253
263
}
264
+
265
+ pub ( self ) mod validation {
266
+ use std:: path:: PathBuf ;
267
+
268
+ pub fn file_path ( s : & str ) -> Result < PathBuf , String > {
269
+ if s. is_empty ( ) {
270
+ return Err ( "empty path" . to_owned ( ) ) ;
271
+ }
272
+
273
+ let path = PathBuf :: from ( s) ;
274
+
275
+ if !path. is_file ( ) {
276
+ return Err ( "path specified does not point to an accessible file" . to_string ( ) ) ;
277
+ }
278
+
279
+ Ok ( path)
280
+ }
281
+ }
You can’t perform that action at this time.
0 commit comments