-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Use of this source code is governed by an MIT-style license that can be found | ||
// in the LICENSE file or at https://opensource.org/licenses/MIT. | ||
|
||
use std::process::ExitStatus; | ||
|
||
use protobuf::Message; | ||
|
||
/// Arguments of the `execute_signed_command` action. | ||
pub struct Args { | ||
raw_command: Vec<u8>, | ||
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 12 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
|
||
command: rrg_proto::execute_signed_command::SignedCommand, | ||
stdin: Stdin, | ||
ed25519_signature: ed25519_dalek::Signature, | ||
timeout: std::time::Duration, | ||
} | ||
|
||
/// Result of the `execute_signed_command` action. | ||
pub struct Item { | ||
/// Exit status of the command subprocess. | ||
exit_status: ExitStatus, | ||
/// Standard output of the command executiom. | ||
stdout: Vec<u8>, | ||
/// Wheather standard output is truncated. | ||
truncated_stdout: bool, | ||
/// Standard error of the command executiom. | ||
stderr: Vec<u8>, | ||
/// Wheather stderr is truncated. | ||
truncated_stderr: bool, | ||
} | ||
|
||
enum Stdin { | ||
NONE, | ||
UNSIGNED(Vec<u8>), | ||
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 35 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
|
||
SIGNED(Vec<u8>), | ||
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 36 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
|
||
} | ||
|
||
|
||
/// Handles invocations of the `execute_signed_command` action. | ||
pub fn handle<S>(session: &mut S, mut args: Args) -> crate::session::Result<()> | ||
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (macos-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (ubuntu-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, nightly)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
Check warning on line 41 in crates/rrg/src/action/execute_signed_command.rs GitHub Actions / CI (windows-latest, stable)
|
||
where | ||
S: crate::session::Session, | ||
{ | ||
// TODO(s-westphal): Add implementation. | ||
Ok(()) | ||
} | ||
|
||
impl crate::request::Args for Args { | ||
|
||
type Proto = rrg_proto::execute_signed_command::Args; | ||
|
||
fn from_proto(mut proto: Self::Proto) -> Result<Args, crate::request::ParseArgsError> { | ||
use crate::request::ParseArgsError; | ||
|
||
let raw_signature= proto.take_command_ed25519_signature(); | ||
|
||
let ed25519_signature = ed25519_dalek::Signature::try_from(&raw_signature[..]) | ||
.map_err(|error| ParseArgsError::invalid_field("command_ed25519_signature", error))?; | ||
|
||
let raw_command = proto.take_command(); | ||
let mut command = rrg_proto::execute_signed_command::SignedCommand::parse_from_bytes(&raw_command) | ||
.map_err(|error| ParseArgsError::invalid_field("command", error))?; | ||
|
||
|
||
let stdin: Stdin; | ||
if command.has_signed_stdin() { | ||
stdin = Stdin::SIGNED(command.take_signed_stdin()); | ||
} else if command.unsigned_stdin() && !proto.unsigned_stdin.is_empty() { | ||
stdin = Stdin::UNSIGNED(proto.take_unsigned_stdin()); | ||
} else { | ||
stdin = Stdin::NONE | ||
} | ||
|
||
let timeout = std::time::Duration::try_from(proto.take_timeout()) | ||
.map_err(|error| ParseArgsError::invalid_field("command", error))?; | ||
|
||
Ok(Args { | ||
raw_command, | ||
command, | ||
ed25519_signature, | ||
stdin, | ||
timeout, | ||
}) | ||
} | ||
} | ||
|
||
impl crate::response::Item for Item { | ||
|
||
type Proto = rrg_proto::execute_signed_command::Result; | ||
|
||
fn into_proto(self) -> Self::Proto { | ||
|
||
let mut proto = rrg_proto::execute_signed_command::Result::new(); | ||
|
||
if let Some(exit_code) = self.exit_status.code() { | ||
proto.set_exit_code(exit_code); | ||
} | ||
|
||
#[cfg(target_family = "unix")] | ||
{ | ||
use std::os::unix::process::ExitStatusExt; | ||
|
||
if let Some(exit_signal) = self.exit_status.signal() { | ||
proto.set_exit_signal(exit_signal); | ||
} | ||
} | ||
|
||
proto.set_stdout(self.stdout); | ||
proto.set_stdout_truncated(self.truncated_stdout); | ||
|
||
proto.set_stderr(self.stderr); | ||
proto.set_stderr_truncated(self.truncated_stderr); | ||
|
||
proto | ||
} | ||
} |