1
0
Fork 0
This repository has been archived on 2024-01-05. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
command_gateway/src/client/main.rs

41 lines
No EOL
1.2 KiB
Rust

#![cfg_attr(not(unix), allow(unused_imports))]
pub mod client;
use libcommand::internal::{AuthorizationStatus, AuthorizeRequest, AuthorizeResponse};
use tonic::Response;
#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = std::env::args()
.skip(1)
.last().unwrap();
let command_arg : libcommand::Command = serde_json::from_str::<libcommand::Command>(&arg)
.unwrap();
let mut client = client::connect().await?;
let request = tonic::Request::new(AuthorizeRequest {
identifier: command_arg.identifier.clone(),
token: command_arg.token.clone(),
command: command_arg.command.clone()
});
let response : Response<AuthorizeResponse> = client.authorize(request).await?;
if AuthorizationStatus::from_i32(response.get_ref().status) == Some(AuthorizationStatus::Authorized) {
let mut command : std::process::Command = command_arg.into();
let mut child = command.spawn().unwrap();
child.wait().unwrap();
} else {
eprintln!("Permission denied");
}
Ok(())
}
#[cfg(not(unix))]
fn main() {
panic!("The `uds` example only works on unix systems!");
}