From 6ce955a143aa5c5396addde91ec6295d2d1d3a79 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 20 Nov 2024 14:37:48 -0800 Subject: [PATCH] fix: actor logs base64 --- Cargo.lock | 7 +++++++ packages/cli/Cargo.toml | 1 + packages/cli/src/commands/actor/logs.rs | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 61eb66df..de08711b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "1.3.2" @@ -1736,6 +1742,7 @@ name = "rivet-cli" version = "2.0.0-rc.4" dependencies = [ "anyhow", + "base64 0.22.1", "clap", "envy", "rivet-toolchain", diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index cb24fc2e..6c0afc2a 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -20,6 +20,7 @@ anyhow = "1.0" uuid = { version = "1.11.0", features = ["v4"] } envy = "0.4.2" url = { version = "2.5.3", features = ["serde"] } +base64 = "0.22.1" [build-dependencies] anyhow = "1.0" diff --git a/packages/cli/src/commands/actor/logs.rs b/packages/cli/src/commands/actor/logs.rs index 44399fba..682ced2a 100644 --- a/packages/cli/src/commands/actor/logs.rs +++ b/packages/cli/src/commands/actor/logs.rs @@ -1,4 +1,5 @@ use anyhow::*; +use base64::{engine::general_purpose::STANDARD, Engine}; use clap::{Parser, ValueEnum}; use std::process::ExitCode; use toolchain::rivet_api::{apis, models}; @@ -23,6 +24,9 @@ pub struct Opts { #[clap(long)] id: String, + #[clap(long)] + no_timestamps: bool, + #[clap(long)] no_follow: bool, } @@ -66,7 +70,19 @@ impl Opts { } for (ts, line) in res.timestamps.iter().zip(res.lines.iter()) { - println!("{ts} {line}"); + let decoded_line = match STANDARD.decode(line) { + Result::Ok(bytes) => String::from_utf8_lossy(&bytes).to_string(), + Err(_) => { + eprintln!("Failed to decode base64: {line}"); + continue; + } + }; + + if self.no_timestamps { + println!("{decoded_line}"); + } else { + println!("{ts} {decoded_line}"); + } } }