Merge pull request #45 from MindFlavor/issue/27/sudo_wg_optional
Added optional sudo to wg command
This commit is contained in:
		
						commit
						38b55fca32
					
				
							
								
								
									
										1032
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1032
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,6 +1,6 @@ | |||||||
| [package] | [package] | ||||||
| name                     = "prometheus_wireguard_exporter" | name                     = "prometheus_wireguard_exporter" | ||||||
| version                  = "3.4.0" | version                  = "3.4.1" | ||||||
| authors                  = ["Francesco Cogno <francesco.cogno@outlook.com>"] | authors                  = ["Francesco Cogno <francesco.cogno@outlook.com>"] | ||||||
| description              = "Prometheus WireGuard Exporter" | description              = "Prometheus WireGuard Exporter" | ||||||
| edition                  = "2018" | edition                  = "2018" | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -47,11 +47,21 @@ async fn perform_request( | |||||||
|     let mut wg_accumulator: Option<WireGuard> = None; |     let mut wg_accumulator: Option<WireGuard> = None; | ||||||
| 
 | 
 | ||||||
|     for interface_to_handle in interfaces_to_handle { |     for interface_to_handle in interfaces_to_handle { | ||||||
|         let output = Command::new("wg") |         let output = if options.prepend_sudo { | ||||||
|  |             Command::new("sudo") | ||||||
|  |                 .arg("wg") | ||||||
|                 .arg("show") |                 .arg("show") | ||||||
|                 .arg(&interface_to_handle) |                 .arg(&interface_to_handle) | ||||||
|                 .arg("dump") |                 .arg("dump") | ||||||
|             .output()?; |                 .output()? | ||||||
|  |         } else { | ||||||
|  |             Command::new("wg") | ||||||
|  |                 .arg("show") | ||||||
|  |                 .arg(&interface_to_handle) | ||||||
|  |                 .arg("dump") | ||||||
|  |                 .output()? | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|         let output_stdout_str = String::from_utf8(output.stdout)?; |         let output_stdout_str = String::from_utf8(output.stdout)?; | ||||||
|         trace!( |         trace!( | ||||||
|             "wg show {} dump stdout == {}", |             "wg show {} dump stdout == {}", | ||||||
| @ -125,6 +135,12 @@ async fn main() { | |||||||
|                 .help("verbose logging") |                 .help("verbose logging") | ||||||
|                 .takes_value(false), |                 .takes_value(false), | ||||||
|         ) |         ) | ||||||
|  |         .arg( | ||||||
|  |             Arg::with_name("prepend_sudo") | ||||||
|  |                 .short("a") | ||||||
|  |                 .help("Prepend sudo to the wg show commands") | ||||||
|  |                 .takes_value(false), | ||||||
|  |         ) | ||||||
|         .arg( |         .arg( | ||||||
|             Arg::with_name("separate_allowed_ips") |             Arg::with_name("separate_allowed_ips") | ||||||
|                 .short("s") |                 .short("s") | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
| pub(crate) struct Options { | pub(crate) struct Options { | ||||||
|     pub verbose: bool, |     pub verbose: bool, | ||||||
|  |     pub prepend_sudo: bool, | ||||||
|     pub separate_allowed_ips: bool, |     pub separate_allowed_ips: bool, | ||||||
|     pub extract_names_config_file: Option<String>, |     pub extract_names_config_file: Option<String>, | ||||||
|     pub interfaces: Option<Vec<String>>, |     pub interfaces: Option<Vec<String>>, | ||||||
| @ -11,6 +12,7 @@ impl Options { | |||||||
|     pub fn from_claps(matches: &clap::ArgMatches<'_>) -> Options { |     pub fn from_claps(matches: &clap::ArgMatches<'_>) -> Options { | ||||||
|         let options = Options { |         let options = Options { | ||||||
|             verbose: matches.is_present("verbose"), |             verbose: matches.is_present("verbose"), | ||||||
|  |             prepend_sudo: matches.is_present("prepend_sudo"), | ||||||
|             separate_allowed_ips: matches.is_present("separate_allowed_ips"), |             separate_allowed_ips: matches.is_present("separate_allowed_ips"), | ||||||
|             extract_names_config_file: matches |             extract_names_config_file: matches | ||||||
|                 .value_of("extract_names_config_files") |                 .value_of("extract_names_config_files") | ||||||
| @ -29,8 +31,3 @@ impl Options { | |||||||
|         options |         options | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 |  | ||||||
| #[cfg(test)] |  | ||||||
| mod tests { |  | ||||||
|     use super::*; |  | ||||||
| } |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user