Add token and identifier
This commit is contained in:
parent
115855ac75
commit
f8a03bc18a
5 changed files with 27 additions and 23 deletions
|
@ -8,4 +8,4 @@
|
|||
|
||||
- `docker build . -t gateway`
|
||||
- `docker run -p 22:22 gateway`
|
||||
- `ssh test@localhost "{\"command\": \"/bin/bash\", \"envs\": {}, \"args\": []}"`
|
||||
- `ssh test@localhost "{\"identifier\": \"project_env\", \"token\": \"token\", \"command\": \"/bin/bash\", \"envs\": {}, \"args\": []}"`
|
|
@ -13,8 +13,9 @@ message AuthorizeRequest {
|
|||
// identifier of the project
|
||||
string identifier = 1;
|
||||
// ssh_keys from ssh agent
|
||||
string public_ssh_keys = 2;
|
||||
// command?
|
||||
string token = 2;
|
||||
// command like /bin/bash
|
||||
string command = 3;
|
||||
}
|
||||
|
||||
enum AuthorizationStatus {
|
||||
|
@ -26,7 +27,6 @@ message AuthorizeResponse {
|
|||
AuthorizationStatus status = 1;
|
||||
string error_message = 2;
|
||||
string session_uuid = 3;
|
||||
string log_file = 4;
|
||||
}
|
||||
|
||||
message TerminateRequest {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
pub mod client;
|
||||
|
||||
use libcommand::internal::{AuthorizeRequest, AuthorizeResponse};
|
||||
use libcommand::internal::{AuthorizationStatus, AuthorizeRequest, AuthorizeResponse};
|
||||
use tonic::Response;
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -11,23 +11,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let arg = std::env::args()
|
||||
.skip(1)
|
||||
.last().unwrap();
|
||||
let mut command : std::process::Command = serde_json::from_str::<libcommand::Command>(&arg)
|
||||
.unwrap()
|
||||
.into();
|
||||
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: "Tonic".into(),
|
||||
public_ssh_keys: "Tonic".into(),
|
||||
identifier: command_arg.identifier.clone(),
|
||||
token: command_arg.token.clone(),
|
||||
command: command_arg.command.clone()
|
||||
});
|
||||
|
||||
let response : Response<AuthorizeResponse> = client.authorize(request).await?;
|
||||
|
||||
println!("RESPONSE={:?}", response);
|
||||
|
||||
let mut child = command.spawn().unwrap();
|
||||
child.wait().unwrap();
|
||||
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(())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use tonic::{Request, Response, Status};
|
|||
|
||||
use libcommand::internal::{
|
||||
unix_server::Unix,
|
||||
AuthorizeRequest, AuthorizeResponse, TerminateRequest, TerminateResponse
|
||||
AuthorizeRequest, AuthorizeResponse, AuthorizationStatus, TerminateRequest, TerminateResponse, TerminateStatus
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -24,10 +24,9 @@ impl Unix for DaemonServer {
|
|||
println!("Got a request {:?} with info {:?}", request, conn_info);
|
||||
}
|
||||
|
||||
let reply = libcommand::internal::AuthorizeResponse {
|
||||
status: libcommand::internal::AuthorizationStatus::Authorized.into(),
|
||||
let reply = AuthorizeResponse {
|
||||
status: AuthorizationStatus::Authorized.into(),
|
||||
error_message: "".into(),
|
||||
log_file: "".into(),
|
||||
session_uuid: "".into()
|
||||
};
|
||||
Ok(Response::new(reply))
|
||||
|
@ -43,8 +42,8 @@ impl Unix for DaemonServer {
|
|||
println!("Got a request {:?} with info {:?}", request, conn_info);
|
||||
}
|
||||
|
||||
let reply = libcommand::internal::TerminateResponse {
|
||||
status: libcommand::internal::TerminateStatus::Ok.into(),
|
||||
let reply = TerminateResponse {
|
||||
status: TerminateStatus::Ok.into(),
|
||||
error_message: "".into(),
|
||||
};
|
||||
Ok(Response::new(reply))
|
||||
|
|
|
@ -9,9 +9,11 @@ pub mod internal {
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Command {
|
||||
command: String,
|
||||
envs: HashMap<String, String>,
|
||||
args: Vec<String>
|
||||
pub identifier: String,
|
||||
pub token: String,
|
||||
pub command: String,
|
||||
pub envs: HashMap<String, String>,
|
||||
pub args: Vec<String>
|
||||
}
|
||||
|
||||
impl Into<std::process::Command> for Command {
|
||||
|
|
Reference in a new issue