// SPDX-FileCopyrightText: OpenTalk GmbH // SPDX-License-Identifier: MIT OR Apache-2.0 use std::io::{self, Read, Write}; use snafu::{ResultExt, Whatever}; use terdoc_types::TerdocClient as _; fn read_from_stdin() -> Result, Whatever> { // read task from stdin let mut buffer = Vec::new(); let mut stdin = io::stdin(); stdin .read_to_end(&mut buffer) .whatever_context("Failed to read stdin")?; Ok(buffer) } #[tokio::main] #[snafu::report] async fn main() -> Result<(), Whatever> { env_logger::init(); let url = std::env::var("SERVICE").unwrap_or_else(|_| "http://127.0.0.1:8090".into()); let mut client = terdoc_client::TerdocClient::new(&url).expect("a valid URL must be provided"); // Custom headers etc. can be set using a "middleware" client.set_middleware(|req| req.basic_auth("admin", Some("good password"))); let render_request = read_from_stdin()?; let response = client .request_render(&serde_json::from_slice(&render_request).whatever_context("Invalid Task")?) .await .whatever_context("Request failed")?; let mut stdout = io::stdout().lock(); stdout .write_all(&response) .whatever_context("failed to write result")?; log::info!("All done"); Ok(()) }